1 /* Copyright (c) 2001, Matej Pfajfar.
2 * Copyright (c) 2001-2004, Roger Dingledine.
3 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4 * Copyright (c) 2007-2011, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
9 * \brief Functions to send messages to log files or the console.
18 #ifdef HAVE_SYS_TIME_H
27 #ifdef HAVE_SYS_TYPES_H
28 #include <sys/types.h>
37 #include "container.h"
39 #define TRUNCATED_STR "[...truncated]"
40 #define TRUNCATED_STR_LEN 14
42 /** Information for a single logfile; only used in log.c */
43 typedef struct logfile_t
{
44 struct logfile_t
*next
; /**< Next logfile_t in the linked list. */
45 char *filename
; /**< Filename to open. */
46 int fd
; /**< fd to receive log messages, or -1 for none. */
47 int seems_dead
; /**< Boolean: true if the stream seems to be kaput. */
48 int needs_close
; /**< Boolean: true if the stream gets closed on shutdown. */
49 int is_temporary
; /**< Boolean: close after initializing logging subsystem.*/
50 int is_syslog
; /**< Boolean: send messages to syslog. */
51 log_callback callback
; /**< If not NULL, send messages to this function. */
52 log_severity_list_t
*severities
; /**< Which severity of messages should we
53 * log for each log domain? */
56 static void log_free(logfile_t
*victim
);
58 /** Helper: map a log severity to descriptive string. */
59 static INLINE
const char *
60 sev_to_string(int severity
)
63 case LOG_DEBUG
: return "debug";
64 case LOG_INFO
: return "info";
65 case LOG_NOTICE
: return "notice";
66 case LOG_WARN
: return "warn";
67 case LOG_ERR
: return "err";
68 default: /* Call assert, not tor_assert, since tor_assert
69 * calls log on failure. */
70 assert(0); return "UNKNOWN";
74 /** Helper: decide whether to include the function name in the log message. */
76 should_log_function_name(log_domain_mask_t domain
, int severity
)
81 /* All debugging messages occur in interesting places. */
86 /* We care about places where bugs occur. */
87 return (domain
== LD_BUG
);
89 /* Call assert, not tor_assert, since tor_assert calls log on failure. */
94 /** A mutex to guard changes to logfiles and logging. */
95 static tor_mutex_t log_mutex
;
96 static int log_mutex_initialized
= 0;
98 /** Linked list of logfile_t. */
99 static logfile_t
*logfiles
= NULL
;
100 /** Boolean: do we report logging domains? */
101 static int log_domains_are_logged
= 0;
104 /** The number of open syslog log handlers that we have. When this reaches 0,
105 * we can close our connection to the syslog facility. */
106 static int syslog_count
= 0;
109 /** Represents a log message that we are going to send to callback-driven
110 * loggers once we can do so in a non-reentrant way. */
111 typedef struct pending_cb_message_t
{
113 log_domain_mask_t domain
;
115 } pending_cb_message_t
;
117 /** Log messages waiting to be replayed onto callback-based logs */
118 static smartlist_t
*pending_cb_messages
= NULL
;
120 #define LOCK_LOGS() STMT_BEGIN \
121 tor_mutex_acquire(&log_mutex); \
123 #define UNLOCK_LOGS() STMT_BEGIN tor_mutex_release(&log_mutex); STMT_END
125 /** What's the lowest log level anybody cares about? Checking this lets us
126 * bail out early from log_debug if we aren't debugging. */
127 int _log_global_min_severity
= LOG_NOTICE
;
129 static void delete_log(logfile_t
*victim
);
130 static void close_log(logfile_t
*victim
);
132 static char *domain_to_string(log_domain_mask_t domain
,
133 char *buf
, size_t buflen
);
135 /** Name of the application: used to generate the message we write at the
136 * start of each new log. */
137 static char *appname
= NULL
;
139 /** Set the "application name" for the logs to <b>name</b>: we'll use this
140 * name in the message we write when starting up, and at the start of each new
143 * Tor uses this string to write the version number to the log file. */
145 log_set_application_name(const char *name
)
148 appname
= name
? tor_strdup(name
) : NULL
;
151 /** Helper: Write the standard prefix for log lines to a
152 * <b>buf_len</b> character buffer in <b>buf</b>.
155 _log_prefix(char *buf
, size_t buf_len
, int severity
)
163 tor_gettimeofday(&now
);
164 t
= (time_t)now
.tv_sec
;
166 n
= strftime(buf
, buf_len
, "%b %d %H:%M:%S", tor_localtime_r(&t
, &tm
));
167 r
= tor_snprintf(buf
+n
, buf_len
-n
, ".%.3i [%s] ",
168 (int)now
.tv_usec
/ 1000, sev_to_string(severity
));
175 /** If lf refers to an actual file that we have just opened, and the file
176 * contains no data, log an "opening new logfile" message at the top.
178 * Return -1 if the log is broken and needs to be deleted, else return 0.
181 log_tor_version(logfile_t
*lf
, int reset
)
187 if (!lf
->needs_close
)
188 /* If it doesn't get closed, it isn't really a file. */
190 if (lf
->is_temporary
)
191 /* If it's temporary, it isn't really a file. */
194 is_new
= lf
->fd
>= 0 && tor_fd_getpos(lf
->fd
) == 0;
196 if (reset
&& !is_new
)
197 /* We are resetting, but we aren't at the start of the file; no
198 * need to log again. */
200 n
= _log_prefix(buf
, sizeof(buf
), LOG_NOTICE
);
202 tor_snprintf(buf
+n
, sizeof(buf
)-n
,
203 "%s opening %slog file.\n", appname
, is_new
?"new ":"");
205 tor_snprintf(buf
+n
, sizeof(buf
)-n
,
206 "Tor %s opening %slog file.\n", VERSION
, is_new
?"new ":"");
208 if (write_all(lf
->fd
, buf
, strlen(buf
), 0) < 0) /* error */
209 return -1; /* failed */
213 /** Helper: Format a log message into a fixed-sized buffer. (This is
214 * factored out of <b>logv</b> so that we never format a message more
215 * than once.) Return a pointer to the first character of the message
216 * portion of the formatted string.
219 format_msg(char *buf
, size_t buf_len
,
220 log_domain_mask_t domain
, int severity
, const char *funcname
,
221 const char *format
, va_list ap
, size_t *msg_len_out
)
228 assert(buf_len
>= 16); /* prevent integer underflow and general stupidity */
229 buf_len
-= 2; /* subtract 2 characters so we have room for \n\0 */
230 buf_end
= buf
+buf_len
; /* point *after* the last char we can write to */
232 n
= _log_prefix(buf
, buf_len
, severity
);
233 end_of_prefix
= buf
+n
;
235 if (log_domains_are_logged
) {
237 if (cp
== buf_end
) goto format_msg_no_room_for_domains
;
239 if (cp
== buf_end
) goto format_msg_no_room_for_domains
;
240 cp
= domain_to_string(domain
, cp
, (buf
+buf_len
-cp
));
241 if (cp
== buf_end
) goto format_msg_no_room_for_domains
;
243 if (cp
== buf_end
) goto format_msg_no_room_for_domains
;
245 if (cp
== buf_end
) goto format_msg_no_room_for_domains
;
248 format_msg_no_room_for_domains
:
249 /* This will leave end_of_prefix and n unchanged, and thus cause
250 * whatever log domain string we had written to be clobbered. */
253 if (funcname
&& should_log_function_name(domain
, severity
)) {
254 r
= tor_snprintf(buf
+n
, buf_len
-n
, "%s(): ", funcname
);
261 if (domain
== LD_BUG
&& buf_len
-n
> 6) {
262 memcpy(buf
+n
, "Bug: ", 6);
266 r
= tor_vsnprintf(buf
+n
,buf_len
-n
,format
,ap
);
268 /* The message was too long; overwrite the end of the buffer with
269 * "[...truncated]" */
270 if (buf_len
>= TRUNCATED_STR_LEN
) {
271 size_t offset
= buf_len
-TRUNCATED_STR_LEN
;
272 /* We have an extra 2 characters after buf_len to hold the \n\0,
273 * so it's safe to add 1 to the size here. */
274 strlcpy(buf
+offset
, TRUNCATED_STR
, buf_len
-offset
+1);
276 /* Set 'n' to the end of the buffer, where we'll be writing \n\0.
277 * Since we already subtracted 2 from buf_len, this is safe.*/
285 return end_of_prefix
;
288 /** Helper: sends a message to the appropriate logfiles, at loglevel
289 * <b>severity</b>. If provided, <b>funcname</b> is prepended to the
290 * message. The actual message is derived as from tor_snprintf(format,ap).
293 logv(int severity
, log_domain_mask_t domain
, const char *funcname
,
294 const char *format
, va_list ap
)
300 char *end_of_prefix
=NULL
;
301 int callbacks_deferred
= 0;
303 /* Call assert, not tor_assert, since tor_assert calls log on failure. */
305 /* check that severity is sane. Overrunning the masks array leads to
306 * interesting and hard to diagnose effects */
307 assert(severity
>= LOG_ERR
&& severity
<= LOG_DEBUG
);
310 if ((! (domain
& LD_NOCB
)) && smartlist_len(pending_cb_messages
))
311 flush_pending_log_callbacks();
315 if (! (lf
->severities
->masks
[SEVERITY_MASK_IDX(severity
)] & domain
)) {
319 if (! (lf
->fd
>= 0 || lf
->is_syslog
|| lf
->callback
)) {
323 if (lf
->seems_dead
) {
330 format_msg(buf
, sizeof(buf
), domain
, severity
, funcname
, format
, ap
,
337 char *m
= end_of_prefix
;
339 /* Some syslog implementations have limits on the length of what you can
340 * pass them, and some very old ones do not detect overflow so well.
341 * Regrettably, they call their maximum line length MAXLINE. */
343 #warn "MAXLINE is a very low number; it might not be from syslog.h after all"
345 if (msg_len
>= MAXLINE
)
346 m
= tor_strndup(end_of_prefix
, MAXLINE
-1);
348 syslog(severity
, "%s", m
);
350 if (m
!= end_of_prefix
) {
357 } else if (lf
->callback
) {
358 if (domain
& LD_NOCB
) {
359 if (!callbacks_deferred
) {
360 pending_cb_message_t
*msg
= tor_malloc(sizeof(pending_cb_message_t
));
361 msg
->severity
= severity
;
362 msg
->domain
= domain
;
363 msg
->msg
= tor_strdup(end_of_prefix
);
364 smartlist_add(pending_cb_messages
, msg
);
366 callbacks_deferred
= 1;
369 lf
->callback(severity
, domain
, end_of_prefix
);
374 if (write_all(lf
->fd
, buf
, msg_len
, 0) < 0) { /* error */
375 /* don't log the error! mark this log entry to be blown away, and
384 /** Output a message to the log. */
386 tor_log(int severity
, log_domain_mask_t domain
, const char *format
, ...)
389 if (severity
> _log_global_min_severity
)
392 logv(severity
, domain
, NULL
, format
, ap
);
396 /** Output a message to the log, prefixed with a function name <b>fn</b>. */
399 _log_fn(int severity
, log_domain_mask_t domain
, const char *fn
,
400 const char *format
, ...)
403 if (severity
> _log_global_min_severity
)
406 logv(severity
, domain
, fn
, format
, ap
);
410 const char *_log_fn_function_name
=NULL
;
412 _log_fn(int severity
, log_domain_mask_t domain
, const char *format
, ...)
415 if (severity
> _log_global_min_severity
)
418 logv(severity
, domain
, _log_fn_function_name
, format
, ap
);
420 _log_fn_function_name
= NULL
;
423 _log_debug(log_domain_mask_t domain
, const char *format
, ...)
426 /* For GCC we do this check in the macro. */
427 if (PREDICT_LIKELY(LOG_DEBUG
> _log_global_min_severity
))
430 logv(LOG_DEBUG
, domain
, _log_fn_function_name
, format
, ap
);
432 _log_fn_function_name
= NULL
;
435 _log_info(log_domain_mask_t domain
, const char *format
, ...)
438 if (LOG_INFO
> _log_global_min_severity
)
441 logv(LOG_INFO
, domain
, _log_fn_function_name
, format
, ap
);
443 _log_fn_function_name
= NULL
;
446 _log_notice(log_domain_mask_t domain
, const char *format
, ...)
449 if (LOG_NOTICE
> _log_global_min_severity
)
452 logv(LOG_NOTICE
, domain
, _log_fn_function_name
, format
, ap
);
454 _log_fn_function_name
= NULL
;
457 _log_warn(log_domain_mask_t domain
, const char *format
, ...)
460 if (LOG_WARN
> _log_global_min_severity
)
463 logv(LOG_WARN
, domain
, _log_fn_function_name
, format
, ap
);
465 _log_fn_function_name
= NULL
;
468 _log_err(log_domain_mask_t domain
, const char *format
, ...)
471 if (LOG_ERR
> _log_global_min_severity
)
474 logv(LOG_ERR
, domain
, _log_fn_function_name
, format
, ap
);
476 _log_fn_function_name
= NULL
;
480 /** Free all storage held by <b>victim</b>. */
482 log_free(logfile_t
*victim
)
486 tor_free(victim
->severities
);
487 tor_free(victim
->filename
);
491 /** Close all open log files, and free other static memory. */
495 logfile_t
*victim
, *next
;
508 /* We _could_ destroy the log mutex here, but that would screw up any logs
509 * that happened between here and the end of execution. */
512 /** Remove and free the log entry <b>victim</b> from the linked-list
513 * logfiles (it is probably present, but it might not be due to thread
514 * racing issues). After this function is called, the caller shouldn't
515 * refer to <b>victim</b> anymore.
517 * Long-term, we need to do something about races in the log subsystem
518 * in general. See bug 222 for more details.
521 delete_log(logfile_t
*victim
)
524 if (victim
== logfiles
)
525 logfiles
= victim
->next
;
527 for (tmpl
= logfiles
; tmpl
&& tmpl
->next
!= victim
; tmpl
=tmpl
->next
) ;
529 // tor_assert(tmpl->next == victim);
532 tmpl
->next
= victim
->next
;
537 /** Helper: release system resources (but not memory) held by a single
540 close_log(logfile_t
*victim
)
542 if (victim
->needs_close
&& victim
->fd
>= 0) {
545 } else if (victim
->is_syslog
) {
547 if (--syslog_count
== 0) {
548 /* There are no other syslogs; close the logging facility. */
555 /** Adjust a log severity configuration in <b>severity_out</b> to contain
556 * every domain between <b>loglevelMin</b> and <b>loglevelMax</b>, inclusive.
559 set_log_severity_config(int loglevelMin
, int loglevelMax
,
560 log_severity_list_t
*severity_out
)
563 tor_assert(loglevelMin
>= loglevelMax
);
564 tor_assert(loglevelMin
>= LOG_ERR
&& loglevelMin
<= LOG_DEBUG
);
565 tor_assert(loglevelMax
>= LOG_ERR
&& loglevelMax
<= LOG_DEBUG
);
566 memset(severity_out
, 0, sizeof(log_severity_list_t
));
567 for (i
= loglevelMin
; i
>= loglevelMax
; --i
) {
568 severity_out
->masks
[SEVERITY_MASK_IDX(i
)] = ~0u;
572 /** Add a log handler named <b>name</b> to send all messages in <b>severity</b>
573 * to <b>fd</b>. Copies <b>severity</b>. Helper: does no locking. */
575 add_stream_log_impl(const log_severity_list_t
*severity
,
576 const char *name
, int fd
)
579 lf
= tor_malloc_zero(sizeof(logfile_t
));
581 lf
->filename
= tor_strdup(name
);
582 lf
->severities
= tor_memdup(severity
, sizeof(log_severity_list_t
));
586 _log_global_min_severity
= get_min_log_level();
589 /** Add a log handler named <b>name</b> to send all messages in <b>severity</b>
590 * to <b>fd</b>. Steals a reference to <b>severity</b>; the caller must
591 * not use it after calling this function. */
593 add_stream_log(const log_severity_list_t
*severity
, const char *name
, int fd
)
596 add_stream_log_impl(severity
, name
, fd
);
600 /** Initialize the global logging facility */
604 if (!log_mutex_initialized
) {
605 tor_mutex_init(&log_mutex
);
606 log_mutex_initialized
= 1;
608 if (pending_cb_messages
== NULL
)
609 pending_cb_messages
= smartlist_create();
612 /** Set whether we report logging domains as a part of our log messages.
615 logs_set_domain_logging(int enabled
)
618 log_domains_are_logged
= enabled
;
622 /** Add a log handler to receive messages during startup (before the real
623 * logs are initialized).
626 add_temp_log(int min_severity
)
628 log_severity_list_t
*s
= tor_malloc_zero(sizeof(log_severity_list_t
));
629 set_log_severity_config(min_severity
, LOG_ERR
, s
);
631 add_stream_log_impl(s
, "<temp>", fileno(stdout
));
633 logfiles
->is_temporary
= 1;
638 * Add a log handler to send messages in <b>severity</b>
639 * to the function <b>cb</b>.
642 add_callback_log(const log_severity_list_t
*severity
, log_callback cb
)
645 lf
= tor_malloc_zero(sizeof(logfile_t
));
647 lf
->severities
= tor_memdup(severity
, sizeof(log_severity_list_t
));
648 lf
->filename
= tor_strdup("<callback>");
654 _log_global_min_severity
= get_min_log_level();
659 /** Adjust the configured severity of any logs whose callback function is
662 change_callback_log_severity(int loglevelMin
, int loglevelMax
,
666 log_severity_list_t severities
;
667 set_log_severity_config(loglevelMin
, loglevelMax
, &severities
);
669 for (lf
= logfiles
; lf
; lf
= lf
->next
) {
670 if (lf
->callback
== cb
) {
671 memcpy(lf
->severities
, &severities
, sizeof(severities
));
674 _log_global_min_severity
= get_min_log_level();
678 /** If there are any log messages that were genered with LD_NOCB waiting to
679 * be sent to callback-based loggers, send them now. */
681 flush_pending_log_callbacks(void)
684 smartlist_t
*messages
, *messages_tmp
;
687 if (0 == smartlist_len(pending_cb_messages
)) {
692 messages
= pending_cb_messages
;
693 pending_cb_messages
= smartlist_create();
695 SMARTLIST_FOREACH_BEGIN(messages
, pending_cb_message_t
*, msg
) {
696 const int severity
= msg
->severity
;
697 const int domain
= msg
->domain
;
698 for (lf
= logfiles
; lf
; lf
= lf
->next
) {
699 if (! lf
->callback
|| lf
->seems_dead
||
700 ! (lf
->severities
->masks
[SEVERITY_MASK_IDX(severity
)] & domain
)) {
703 lf
->callback(severity
, domain
, msg
->msg
);
707 } SMARTLIST_FOREACH_END(msg
);
708 smartlist_clear(messages
);
710 messages_tmp
= pending_cb_messages
;
711 pending_cb_messages
= messages
;
712 messages
= messages_tmp
;
713 } while (smartlist_len(messages
));
715 smartlist_free(messages
);
720 /** Close any log handlers added by add_temp_log() or marked by
721 * mark_logs_temp(). */
723 close_temp_logs(void)
728 for (p
= &logfiles
; *p
; ) {
729 if ((*p
)->is_temporary
) {
731 /* we use *p here to handle the edge case of the head of the list */
740 _log_global_min_severity
= get_min_log_level();
744 /** Make all currently temporary logs (set to be closed by close_temp_logs)
745 * live again, and close all non-temporary logs. */
747 rollback_log_changes(void)
751 for (lf
= logfiles
; lf
; lf
= lf
->next
)
752 lf
->is_temporary
= ! lf
->is_temporary
;
757 /** Configure all log handles to be closed by close_temp_logs(). */
763 for (lf
= logfiles
; lf
; lf
= lf
->next
)
764 lf
->is_temporary
= 1;
769 * Add a log handler to send messages to <b>filename</b>. If opening the
770 * logfile fails, -1 is returned and errno is set appropriately (by open(2)).
773 add_file_log(const log_severity_list_t
*severity
, const char *filename
)
778 fd
= open(filename
, O_WRONLY
|O_CREAT
|O_APPEND
, 0644);
781 if (tor_fd_seekend(fd
)<0)
785 add_stream_log_impl(severity
, filename
, fd
);
786 logfiles
->needs_close
= 1;
788 _log_global_min_severity
= get_min_log_level();
790 if (log_tor_version(lf
, 0) < 0) {
800 * Add a log handler to send messages to they system log facility.
803 add_syslog_log(const log_severity_list_t
*severity
)
806 if (syslog_count
++ == 0)
807 /* This is the first syslog. */
808 openlog("Tor", LOG_PID
| LOG_NDELAY
, LOGFACILITY
);
810 lf
= tor_malloc_zero(sizeof(logfile_t
));
812 lf
->severities
= tor_memdup(severity
, sizeof(log_severity_list_t
));
813 lf
->filename
= tor_strdup("<syslog>");
819 _log_global_min_severity
= get_min_log_level();
825 /** If <b>level</b> is a valid log severity, return the corresponding
826 * numeric value. Otherwise, return -1. */
828 parse_log_level(const char *level
)
830 if (!strcasecmp(level
, "err"))
832 if (!strcasecmp(level
, "warn"))
834 if (!strcasecmp(level
, "notice"))
836 if (!strcasecmp(level
, "info"))
838 if (!strcasecmp(level
, "debug"))
843 /** Return the string equivalent of a given log level. */
845 log_level_to_string(int level
)
847 return sev_to_string(level
);
850 /** NULL-terminated array of names for log domains such that domain_list[dom]
851 * is a description of <b>dom</b>. */
852 static const char *domain_list
[] = {
853 "GENERAL", "CRYPTO", "NET", "CONFIG", "FS", "PROTOCOL", "MM",
854 "HTTP", "APP", "CONTROL", "CIRC", "REND", "BUG", "DIR", "DIRSERV",
855 "OR", "EDGE", "ACCT", "HIST", "HANDSHAKE", NULL
858 /** Return a bitmask for the log domain for which <b>domain</b> is the name,
859 * or 0 if there is no such name. */
860 static log_domain_mask_t
861 parse_log_domain(const char *domain
)
864 for (i
=0; domain_list
[i
]; ++i
) {
865 if (!strcasecmp(domain
, domain_list
[i
]))
871 /** Translate a bitmask of log domains to a string. */
873 domain_to_string(log_domain_mask_t domain
, char *buf
, size_t buflen
)
876 char *eos
= buf
+buflen
;
883 int bit
= tor_log2(domain
);
885 if (bit
>= N_LOGGING_DOMAINS
) {
886 tor_snprintf(buf
, buflen
, "<BUG:Unknown domain %lx>", (long)domain
);
887 return buf
+strlen(buf
);
889 d
= domain_list
[bit
];
890 n
= strlcpy(cp
, d
, eos
-cp
);
892 tor_snprintf(buf
, buflen
, "<BUG:Truncating domain %lx>", (long)domain
);
893 return buf
+strlen(buf
);
898 if (domain
== 0 || (eos
-cp
) < 2)
901 memcpy(cp
, ",", 2); /*Nul-terminated ,"*/
906 /** Parse a log severity pattern in *<b>cfg_ptr</b>. Advance cfg_ptr after
907 * the end of the severityPattern. Set the value of <b>severity_out</b> to
908 * the parsed pattern. Return 0 on success, -1 on failure.
910 * The syntax for a SeverityPattern is:
912 * SeverityPattern = *(DomainSeverity SP)* DomainSeverity
913 * DomainSeverity = (DomainList SP)? SeverityRange
914 * SeverityRange = MinSeverity ("-" MaxSeverity )?
915 * DomainList = "[" (SP? DomainSpec SP? ",") SP? DomainSpec "]"
916 * DomainSpec = "*" | Domain | "~" Domain
918 * A missing MaxSeverity defaults to ERR. Severities and domains are
919 * case-insensitive. "~" indicates negation for a domain; negation happens
920 * last inside a DomainList. Only one SeverityRange without a DomainList is
924 parse_log_severity_config(const char **cfg_ptr
,
925 log_severity_list_t
*severity_out
)
927 const char *cfg
= *cfg_ptr
;
928 int got_anything
= 0;
929 int got_an_unqualified_range
= 0;
930 memset(severity_out
, 0, sizeof(*severity_out
));
932 cfg
= eat_whitespace(cfg
);
934 const char *dash
, *space
;
935 char *sev_lo
, *sev_hi
;
937 log_domain_mask_t domains
= ~0u;
942 smartlist_t
*domains_list
;
943 log_domain_mask_t neg_domains
= 0;
944 const char *closebracket
= strchr(cfg
, ']');
948 domains_str
= tor_strndup(cfg
+1, closebracket
-cfg
-1);
949 domains_list
= smartlist_create();
950 smartlist_split_string(domains_list
, domains_str
, ",", SPLIT_SKIP_SPACE
,
952 tor_free(domains_str
);
953 SMARTLIST_FOREACH(domains_list
, const char *, domain
,
955 if (!strcmp(domain
, "*")) {
960 if (*domain
== '~') {
964 d
= parse_log_domain(domain
);
966 log_warn(LD_CONFIG
, "No such logging domain as %s", domain
);
976 SMARTLIST_FOREACH(domains_list
, char *, d
, tor_free(d
));
977 smartlist_free(domains_list
);
980 if (domains
== 0 && neg_domains
)
981 domains
= ~neg_domains
;
983 domains
&= ~neg_domains
;
984 cfg
= eat_whitespace(closebracket
+1);
986 ++got_an_unqualified_range
;
988 if (!strcasecmpstart(cfg
, "file") ||
989 !strcasecmpstart(cfg
, "stderr") ||
990 !strcasecmpstart(cfg
, "stdout") ||
991 !strcasecmpstart(cfg
, "syslog")) {
994 if (got_an_unqualified_range
> 1)
997 space
= strchr(cfg
, ' ');
998 dash
= strchr(cfg
, '-');
1000 space
= strchr(cfg
, '\0');
1001 if (dash
&& dash
< space
) {
1002 sev_lo
= tor_strndup(cfg
, dash
-cfg
);
1003 sev_hi
= tor_strndup(dash
+1, space
-(dash
+1));
1005 sev_lo
= tor_strndup(cfg
, space
-cfg
);
1006 sev_hi
= tor_strdup("ERR");
1008 low
= parse_log_level(sev_lo
);
1009 high
= parse_log_level(sev_hi
);
1018 for (i
=low
; i
>= high
; --i
)
1019 severity_out
->masks
[SEVERITY_MASK_IDX(i
)] |= domains
;
1021 cfg
= eat_whitespace(space
);
1026 return got_anything
? 0 : -1;
1029 /** Return the least severe log level that any current log is interested in. */
1031 get_min_log_level(void)
1036 for (lf
= logfiles
; lf
; lf
= lf
->next
) {
1037 for (i
= LOG_DEBUG
; i
> min
; --i
)
1038 if (lf
->severities
->masks
[SEVERITY_MASK_IDX(i
)])
1044 /** Switch all logs to output at most verbose level. */
1046 switch_logs_debug(void)
1051 for (lf
= logfiles
; lf
; lf
=lf
->next
) {
1052 for (i
= LOG_DEBUG
; i
>= LOG_ERR
; --i
)
1053 lf
->severities
->masks
[SEVERITY_MASK_IDX(i
)] = ~0u;
1055 _log_global_min_severity
= get_min_log_level();
1061 dump_log_info(logfile_t
*lf
)
1066 printf("=== log into \"%s\" (%s-%s) (%stemporary)\n", lf
->filename
,
1067 sev_to_string(lf
->min_loglevel
),
1068 sev_to_string(lf
->max_loglevel
),
1069 lf
->is_temporary
?"":"not ");
1070 } else if (lf
->is_syslog
) {
1071 printf("=== syslog (%s-%s) (%stemporary)\n",
1072 sev_to_string(lf
->min_loglevel
),
1073 sev_to_string(lf
->max_loglevel
),
1074 lf
->is_temporary
?"":"not ");
1076 printf("=== log (%s-%s) (%stemporary)\n",
1077 sev_to_string(lf
->min_loglevel
),
1078 sev_to_string(lf
->max_loglevel
),
1079 lf
->is_temporary
?"":"not ");
1087 printf("==== BEGIN LOGS ====\n");
1088 for (lf
= logfiles
; lf
; lf
= lf
->next
)
1090 printf("==== END LOGS ====\n");