… | |
… | |
41 | |
41 | |
42 | loglevel log_level = L_INFO; |
42 | loglevel log_level = L_INFO; |
43 | const char *log_identity = ""; |
43 | const char *log_identity = ""; |
44 | static int logto = LOGTO_STDERR; |
44 | static int logto = LOGTO_STDERR; |
45 | |
45 | |
|
|
46 | loglevel |
46 | loglevel string_to_loglevel (const char *s) |
47 | string_to_loglevel (const char *s) |
47 | { |
48 | { |
48 | if (!strcmp (s, "noise")) return L_NOISE; |
49 | if (!strcmp (s, "noise")) return L_NOISE; |
49 | if (!strcmp (s, "trace")) return L_TRACE; |
50 | if (!strcmp (s, "trace")) return L_TRACE; |
50 | if (!strcmp (s, "debug")) return L_DEBUG; |
51 | if (!strcmp (s, "debug")) return L_DEBUG; |
51 | if (!strcmp (s, "info")) return L_INFO; |
52 | if (!strcmp (s, "info")) return L_INFO; |
… | |
… | |
55 | if (!strcmp (s, "critical")) return L_CRIT; |
56 | if (!strcmp (s, "critical")) return L_CRIT; |
56 | |
57 | |
57 | return L_NONE; |
58 | return L_NONE; |
58 | } |
59 | } |
59 | |
60 | |
|
|
61 | void |
60 | void log_to (int mask) |
62 | log_to (int mask) |
61 | { |
63 | { |
62 | if (logto & LOGTO_SYSLOG) |
64 | if (logto & LOGTO_SYSLOG) |
63 | closelog (); |
65 | closelog (); |
64 | |
66 | |
65 | logto = mask; |
67 | logto = mask; |
66 | |
68 | |
67 | if (logto & LOGTO_SYSLOG) |
69 | if (logto & LOGTO_SYSLOG) |
68 | openlog (log_identity, LOG_CONS | LOG_PID, LOG_DAEMON); |
70 | openlog (log_identity, LOG_CONS | LOG_PID, LOG_DAEMON); |
69 | } |
71 | } |
70 | |
72 | |
|
|
73 | void |
71 | void slog_ (const loglevel l, const char *m, ...) |
74 | slog_ (const loglevel l, const char *m, ...) |
72 | { |
75 | { |
73 | if (l >= log_level) |
76 | if (l >= log_level) |
74 | { |
77 | { |
75 | va_list ap; |
78 | va_list ap; |
76 | va_start (ap, m); |
79 | va_start (ap, m); |
… | |
… | |
99 | |
102 | |
100 | delete msg; |
103 | delete msg; |
101 | } |
104 | } |
102 | } |
105 | } |
103 | |
106 | |
|
|
107 | void |
104 | void fatal (const char *m) |
108 | fatal (const char *m) |
105 | { |
109 | { |
106 | slog (L_CRIT, m); |
110 | slog (L_CRIT, m); |
107 | exit (EXIT_FAILURE); |
111 | exit (EXIT_FAILURE); |
108 | } |
112 | } |
109 | |
113 | |
|
|
114 | void |
110 | extern void require_failed (const char *file, int line, const char *info) |
115 | require_failed (const char *file, int line, const char *info) |
111 | { |
116 | { |
112 | slog (L_CRIT, "FATAL: This program encountered a SHOULD NOT HAPPEN condition and will exit:"); |
117 | slog (L_CRIT, "FATAL: This program encountered a SHOULD NOT HAPPEN condition and will exit:"); |
113 | slog (L_CRIT, "FATAL+ %s:%d '%s' is false", file, line, info); |
118 | slog (L_CRIT, "FATAL+ %s:%d '%s' is false", file, line, info); |
114 | slog (L_CRIT, "FATAL+ This might indicates a bug in this program, a bug in your libraries,"); |
119 | slog (L_CRIT, "FATAL+ This might indicates a bug in this program, a bug in your libraries,"); |
115 | slog (L_CRIT, "FATAL+ your system setup or operating system. Or it might indicate a very"); |
120 | slog (L_CRIT, "FATAL+ your system setup or operating system. Or it might indicate a very"); |