mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Use our own logging facility to log toxcore's logs
This commit is contained in:
parent
deb82006e5
commit
2e4cae692e
|
@ -97,7 +97,7 @@ static void manage_keys(DHT *dht)
|
|||
static void print_log(void *context, Logger_Level level, const char *file, int line,
|
||||
const char *func, const char *message, void *userdata)
|
||||
{
|
||||
char *strlevel;
|
||||
const char *strlevel;
|
||||
|
||||
switch (level) {
|
||||
case LOGGER_LEVEL_TRACE:
|
||||
|
|
|
@ -178,42 +178,40 @@ static void daemonize(LOG_BACKEND log_backend, char *pid_file_path)
|
|||
}
|
||||
}
|
||||
|
||||
void print_log(void *context, LOGGER_LEVEL level, const char *file, int line,
|
||||
// Logs toxcore logger message using our logger facility
|
||||
|
||||
static void toxcore_logger_callback(void *context, Logger_Level level, const char *file, int line,
|
||||
const char *func, const char *message, void *userdata)
|
||||
{
|
||||
if (MIN_LOGGER_LEVEL != LOG_TRACE && MIN_LOGGER_LEVEL != LOG_DEBUG) {
|
||||
return;
|
||||
}
|
||||
|
||||
char *strlevel;
|
||||
LOG_LEVEL log_level;
|
||||
|
||||
switch (level) {
|
||||
case LOG_TRACE:
|
||||
strlevel = "TRACE";
|
||||
case LOGGER_LEVEL_TRACE:
|
||||
log_level = LOG_LEVEL_INFO;
|
||||
break;
|
||||
|
||||
case LOG_DEBUG:
|
||||
strlevel = "DEBUG";
|
||||
case LOGGER_LEVEL_DEBUG:
|
||||
log_level = LOG_LEVEL_INFO;
|
||||
break;
|
||||
|
||||
case LOG_INFO:
|
||||
strlevel = "INFO";
|
||||
case LOGGER_LEVEL_INFO:
|
||||
log_level = LOG_LEVEL_INFO;
|
||||
break;
|
||||
|
||||
case LOG_WARNING:
|
||||
strlevel = "WARNING";
|
||||
case LOGGER_LEVEL_WARNING:
|
||||
log_level = LOG_LEVEL_WARNING;
|
||||
break;
|
||||
|
||||
case LOG_ERROR:
|
||||
strlevel = "ERROR";
|
||||
case LOGGER_LEVEL_ERROR:
|
||||
log_level = LOG_LEVEL_ERROR;
|
||||
break;
|
||||
|
||||
default:
|
||||
strlevel = "<unknown>";
|
||||
log_level = LOG_LEVEL_INFO;
|
||||
break;
|
||||
}
|
||||
|
||||
fprintf(stderr, "[%s] %s:%d(%s) %s\n", strlevel, file, line, func, message);
|
||||
log_write(log_level, "%s:%d(%s) %s\n", file, line, func, message);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
@ -269,7 +267,10 @@ int main(int argc, char *argv[])
|
|||
ip_init(&ip, enable_ipv6);
|
||||
|
||||
Logger *logger = logger_new();
|
||||
logger_callback_log(logger, print_log, nullptr, nullptr);
|
||||
|
||||
if (MIN_LOGGER_LEVEL == LOGGER_LEVEL_TRACE || MIN_LOGGER_LEVEL == LOGGER_LEVEL_DEBUG) {
|
||||
logger_callback_log(logger, toxcore_logger_callback, nullptr, nullptr);
|
||||
}
|
||||
|
||||
Networking_Core *net = new_networking(logger, ip, port);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user