Skip to content

Commit ed15555

Browse files
authored
Refactored logger internals (#3428)
1 parent d51cf7c commit ed15555

File tree

9 files changed

+143
-216
lines changed

9 files changed

+143
-216
lines changed

src/janus-cfgconv.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ int lock_debug = 0;
4040
/* Main Code */
4141
int main(int argc, char *argv[])
4242
{
43-
janus_log_init(FALSE, TRUE, NULL);
43+
janus_log_init(FALSE, TRUE, NULL, NULL);
4444
atexit(janus_log_destroy);
4545

4646
JANUS_LOG(LOG_INFO, "Janus version: %d (%s)\n", janus_version, janus_version_string);

src/janus.c

+22-21
Original file line numberDiff line numberDiff line change
@@ -4405,11 +4405,12 @@ gint main(int argc, char *argv[]) {
44054405
core_limits.rlim_cur = core_limits.rlim_max = RLIM_INFINITY;
44064406
setrlimit(RLIMIT_CORE, &core_limits);
44074407

4408-
g_print("Janus version: %d (%s)\n", janus_version, janus_version_string);
4409-
g_print("Janus commit: %s\n", janus_build_git_sha);
4410-
g_print("Compiled on: %s\n\n", janus_build_git_time);
44114408
janus_mark_started();
44124409

4410+
JANUS_PRINT("Janus version: %d (%s)\n", janus_version, janus_version_string);
4411+
JANUS_PRINT("Janus commit: %s\n", janus_build_git_sha);
4412+
JANUS_PRINT("Compiled on: %s\n\n", janus_build_git_time);
4413+
44134414
/* Initialize some command line options defaults */
44144415
options.debug_level = -1;
44154416
options.session_timeout = -1;
@@ -4443,19 +4444,19 @@ gint main(int argc, char *argv[]) {
44434444
}
44444445
if((config = janus_config_parse(config_file)) == NULL) {
44454446
/* We failed to load the libconfig configuration file, let's try the INI */
4446-
g_print("Failed to load %s, trying the INI instead...\n", config_file);
4447+
JANUS_PRINT("Failed to load %s, trying the INI instead...\n", config_file);
44474448
g_free(config_file);
44484449
char file[255];
44494450
g_snprintf(file, 255, "%s/janus.cfg", configs_folder);
44504451
config_file = g_strdup(file);
44514452
if((config = janus_config_parse(config_file)) == NULL) {
44524453
if(options.config_file) {
44534454
/* We only give up if the configuration file was explicitly provided */
4454-
g_print("Error reading configuration from %s\n", config_file);
4455+
JANUS_PRINT("Error reading configuration from %s\n", config_file);
44554456
janus_options_destroy();
44564457
exit(1);
44574458
}
4458-
g_print("Error reading/parsing the configuration file in %s, going on with the defaults and the command line arguments\n",
4459+
JANUS_PRINT("Error reading/parsing the configuration file in %s, going on with the defaults and the command line arguments\n",
44594460
configs_folder);
44604461
config = janus_config_create("janus.cfg");
44614462
if(config == NULL) {
@@ -4530,18 +4531,18 @@ gint main(int argc, char *argv[]) {
45304531
}
45314532
/* Daemonize now, if we need to */
45324533
if(daemonize) {
4533-
g_print("Running Janus as a daemon\n");
4534+
JANUS_PRINT("Running Janus as a daemon\n");
45344535

45354536
/* Create a pipe for parent<->child communication during the startup phase */
45364537
if(pipe(pipefd) == -1) {
4537-
g_print("pipe error!\n");
4538+
JANUS_PRINT("pipe error!\n");
45384539
exit(1);
45394540
}
45404541

45414542
/* Fork off the parent process */
45424543
pid_t pid = fork();
45434544
if(pid < 0) {
4544-
g_print("Fork error!\n");
4545+
JANUS_PRINT("Fork error!\n");
45454546
exit(1);
45464547
}
45474548
if(pid > 0) {
@@ -4570,7 +4571,7 @@ gint main(int argc, char *argv[]) {
45704571

45714572
/* Leave the parent and return the exit code we received from the child */
45724573
if(code)
4573-
g_print("Error launching Janus (error code %d), check the logs for more details\n", code);
4574+
JANUS_PRINT("Error launching Janus (error code %d), check the logs for more details\n", code);
45744575
exit(code);
45754576
}
45764577
/* Child here */
@@ -4582,13 +4583,13 @@ gint main(int argc, char *argv[]) {
45824583
/* Create a new SID for the child process */
45834584
pid_t sid = setsid();
45844585
if(sid < 0) {
4585-
g_print("Error setting SID!\n");
4586+
JANUS_PRINT("Error setting SID!\n");
45864587
exit(1);
45874588
}
45884589
/* Change the current working directory */
45894590
const char *cwd = options.cwd_path ? options.cwd_path : "/";
45904591
if((chdir(cwd)) < 0) {
4591-
g_print("Error changing the current working directory!\n");
4592+
JANUS_PRINT("Error changing the current working directory!\n");
45924593
exit(1);
45934594
}
45944595
/* We close stdin/stdout/stderr when initializing the logger */
@@ -4606,10 +4607,7 @@ gint main(int argc, char *argv[]) {
46064607
if(item && item->value && janus_is_true(item->value))
46074608
exit_on_dl_error = TRUE;
46084609

4609-
/* Initialize logger */
4610-
if(janus_log_init(daemonize, use_stdout, logfile) < 0)
4611-
exit(1);
4612-
/* Check if there are external loggers we need to load as well */
4610+
/* Check if there are external loggers we need to load */
46134611
const char *path = NULL;
46144612
DIR *dir = NULL;
46154613
/* External loggers are usually disabled by default: they need to be enabled in the configuration */
@@ -4664,16 +4662,16 @@ gint main(int argc, char *argv[]) {
46644662
memset(eventpath, 0, 1024);
46654663
g_snprintf(eventpath, 1024, "%s/%s", path, eventent->d_name);
46664664
void *event = dlopen(eventpath, RTLD_NOW | RTLD_GLOBAL);
4667-
if (!event) {
4665+
if(!event) {
46684666
JANUS_LOG(exit_on_dl_error ? LOG_FATAL : LOG_ERR, "\tCouldn't load logger plugin '%s': %s\n", eventent->d_name, dlerror());
4669-
if (exit_on_dl_error)
4667+
if(exit_on_dl_error)
46704668
exit(1);
46714669
} else {
46724670
create_l *create = (create_l*) dlsym(event, "create");
46734671
const char *dlsym_error = dlerror();
4674-
if (dlsym_error) {
4672+
if(dlsym_error) {
46754673
JANUS_LOG(exit_on_dl_error ? LOG_FATAL : LOG_ERR, "\tCouldn't load symbol 'create': %s\n", dlsym_error);
4676-
if (exit_on_dl_error)
4674+
if(exit_on_dl_error)
46774675
exit(1);
46784676
continue;
46794677
}
@@ -4717,7 +4715,10 @@ gint main(int argc, char *argv[]) {
47174715
if(disabled_loggers != NULL)
47184716
g_strfreev(disabled_loggers);
47194717
disabled_loggers = NULL;
4720-
janus_log_set_loggers(loggers);
4718+
4719+
/* Initialize logger */
4720+
if(janus_log_init(daemonize, use_stdout, logfile, loggers) < 0)
4721+
exit(1);
47214722

47224723
JANUS_PRINT("---------------------------------------------------\n");
47234724
JANUS_PRINT(" Starting Meetecho Janus (WebRTC Server) v%s\n", janus_version_string);

0 commit comments

Comments
 (0)