static int parent_fd = 0;
-static int log_debug = 0;
+#define DEBUG_LEVEL_PRINT_FUNCTION 2
+#define DEBUG_LEVEL_PRINT_DEBUG 2
+static int debug_level = 0;
static time_t last_limited = 0;
time_t t;
struct tm stm;
- /* Don't write debug messages if not enabled */
- if (!log_debug && severity == LOGS_DEBUG)
+ /* Don't write debug messages if debug level is too low */
+ if (debug_level < DEBUG_LEVEL_PRINT_DEBUG && severity == LOGS_DEBUG)
return;
#ifdef WINNT
#else
if (!system_log) {
- /* Don't clutter up syslog with internal debugging info */
+ /* Don't clutter up syslog with timestamps and internal debugging info */
time(&t);
stm = *gmtime(&t);
strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%SZ", &stm);
- fprintf(stderr, "%s %s:%d:(%s) ", buf, filename, line_number, function_name);
+ fprintf(stderr, "%s ", buf);
+ if (debug_level >= DEBUG_LEVEL_PRINT_FUNCTION)
+ fprintf(stderr, "%s:%d:(%s) ", filename, line_number, function_name);
}
#endif
/* ================================================== */
-void LOG_EnableDebug(void)
+void LOG_SetDebugLevel(int level)
{
- log_debug = 1;
+ debug_level = level;
}
/* ================================================== */
int line_number, const char *filename,
const char *function_name, const char *format, ...);
-/* Enable logging of debug messages */
-extern void LOG_EnableDebug(void);
+/* Set debug level:
+ 0, 1 - only non-debug messages are logged
+ 2 - debug messages are logged too, all messages are prefixed with
+ filename, line, and function name
+ */
+extern void LOG_SetDebugLevel(int level);
/* Log messages to syslog instead of stderr */
extern void LOG_OpenSystemLog(void);
int do_init_rtc = 0, restarted = 0;
int other_pid;
int lock_memory = 0, sched_priority = 0;
+ int system_log = 1;
LOG_Initialise();
} else if (!strcmp("-d", *argv)) {
debug++;
nofork = 1;
+ system_log = 0;
} else if (!strcmp("-4", *argv)) {
address_family = IPADDR_INET4;
} else if (!strcmp("-6", *argv)) {
go_daemon();
}
- if (!debug) {
+ if (system_log) {
LOG_OpenSystemLog();
}
- if (debug > 1) {
- LOG_EnableDebug();
- }
+ LOG_SetDebugLevel(debug);
LOG(LOGS_INFO, LOGF_Main, "chronyd version %s starting", CHRONY_VERSION);