tor  0.4.1.0-alpha-dev
Data Structures | Macros | Typedefs | Functions | Variables
log.c File Reference
#include "orconfig.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lib/log/log.h"
#include "lib/log/log_sys.h"
#include "lib/version/git_revision.h"
#include "lib/log/ratelim.h"
#include "lib/lock/compat_mutex.h"
#include "lib/smartlist_core/smartlist_core.h"
#include "lib/smartlist_core/smartlist_foreach.h"
#include "lib/smartlist_core/smartlist_split.h"
#include "lib/err/torerr.h"
#include "lib/intmath/bits.h"
#include "lib/string/compat_string.h"
#include "lib/string/printf.h"
#include "lib/malloc/malloc.h"
#include "lib/string/util_string.h"
#include "lib/wallclock/tor_gettimeofday.h"
#include "lib/wallclock/approx_time.h"
#include "lib/wallclock/time_to_tm.h"
#include "lib/fdio/fdio.h"
#include "lib/cc/ctassert.h"

Go to the source code of this file.

Data Structures

struct  logfile_t
 
struct  pending_log_message_t
 

Macros

#define LOG_PRIVATE
 
#define SEVERITY_MASK_IDX(sev)   ((sev) - LOG_ERR)
 
#define log_free(lg)   FREE_AND_NULL(logfile_t, log_free_, (lg))
 
#define MAX_STARTUP_MSG_LEN   (1<<16)
 
#define LOCK_LOGS()
 
#define UNLOCK_LOGS()
 
#define pending_log_message_free(msg)   FREE_AND_NULL(pending_log_message_t, pending_log_message_free_, (msg))
 
#define TRUNCATED_STR   "[...truncated]"
 
#define TRUNCATED_STR_LEN   14
 

Typedefs

typedef struct logfile_t logfile_t
 
typedef struct pending_log_message_t pending_log_message_t
 

Functions

static void log_free_ (logfile_t *victim)
 
static const char * sev_to_string (int severity)
 
static int should_log_function_name (log_domain_mask_t domain, int severity)
 
static void delete_log (logfile_t *victim)
 
static void close_log (logfile_t *victim)
 
static char * domain_to_string (log_domain_mask_t domain, char *buf, size_t buflen)
 
static char * format_msg (char *buf, size_t buf_len, log_domain_mask_t domain, int severity, const char *funcname, const char *suffix, const char *format, va_list ap, size_t *msg_len_out) CHECK_PRINTF(7
 
void log_set_application_name (const char *name)
 
int log_message_is_interesting (int severity, log_domain_mask_t domain)
 
void tor_log_string (int severity, log_domain_mask_t domain, const char *function, const char *string)
 
void set_log_time_granularity (int granularity_msec)
 
static size_t log_prefix_ (char *buf, size_t buf_len, int severity)
 
static int log_tor_version (logfile_t *lf, int reset)
 
static pending_log_message_tpending_log_message_new (int severity, log_domain_mask_t domain, const char *fullmsg, const char *shortmsg)
 
static void pending_log_message_free_ (pending_log_message_t *msg)
 
static int logfile_is_external (const logfile_t *lf)
 
static int logfile_wants_message (const logfile_t *lf, int severity, log_domain_mask_t domain)
 
static void logfile_deliver (logfile_t *lf, const char *buf, size_t msg_len, const char *msg_after_prefix, log_domain_mask_t domain, int severity, int *callbacks_deferred)
 
 MOCK_IMPL (STATIC void, logv,(int severity, log_domain_mask_t domain, const char *funcname, const char *suffix, const char *format, va_list ap))
 
void tor_log (int severity, log_domain_mask_t domain, const char *format,...)
 
static int int_array_contains (const int *array, int n, int item)
 
void tor_log_update_sigsafe_err_fds (void)
 
void tor_log_get_logfile_names (smartlist_t *out)
 
void log_fn_ (int severity, log_domain_mask_t domain, const char *fn, const char *format,...)
 
void log_fn_ratelim_ (ratelim_t *ratelim, int severity, log_domain_mask_t domain, const char *fn, const char *format,...)
 
void logs_free_all (void)
 
void set_log_severity_config (int loglevelMin, int loglevelMax, log_severity_list_t *severity_out)
 
static void add_stream_log_impl (const log_severity_list_t *severity, const char *name, int fd)
 
void add_stream_log (const log_severity_list_t *severity, const char *name, int fd)
 
void init_logging (int disable_startup_queue)
 
void logs_set_domain_logging (int enabled)
 
void add_temp_log (int min_severity)
 
void logs_set_pending_callback_callback (pending_callback_callback cb)
 
int add_callback_log (const log_severity_list_t *severity, log_callback cb)
 
void change_callback_log_severity (int loglevelMin, int loglevelMax, log_callback cb)
 
void flush_pending_log_callbacks (void)
 
void flush_log_messages_from_startup (void)
 
void close_temp_logs (void)
 
void rollback_log_changes (void)
 
void mark_logs_temp (void)
 
int add_file_log (const log_severity_list_t *severity, const char *filename, int fd)
 
int parse_log_level (const char *level)
 
const char * log_level_to_string (int level)
 
 CTASSERT (ARRAY_LENGTH(domain_list)==N_LOGGING_DOMAINS+1)
 
static log_domain_mask_t parse_log_domain (const char *domain)
 
int parse_log_severity_config (const char **cfg_ptr, log_severity_list_t *severity_out)
 
int get_min_log_level (void)
 
void switch_logs_debug (void)
 
void truncate_logs (void)
 

Variables

const int LOG_WARN_ = LOG_WARN
 
const int LOG_NOTICE_ = LOG_NOTICE
 
const log_domain_mask_t LD_GENERAL_ = LD_GENERAL
 
const log_domain_mask_t LD_NET_ = LD_NET
 
static tor_mutex_t log_mutex
 
static int log_mutex_initialized = 0
 
static logfile_tlogfiles = NULL
 
static int log_domains_are_logged = 0
 
static smartlist_tpending_cb_messages = NULL
 
static pending_callback_callback pending_cb_cb = NULL
 
static smartlist_tpending_startup_messages = NULL
 
static size_t pending_startup_messages_len
 
static int queue_startup_messages = 1
 
static int pretty_fn_has_parens = 0
 
int log_global_min_severity_ = LOG_NOTICE
 
static char static char * appname = NULL
 
static int log_time_granularity = 1
 
static const char * domain_list []
 

Detailed Description

Functions to send messages to log files or the console.

Definition in file log.c.

Macro Definition Documentation

◆ LOCK_LOGS

#define LOCK_LOGS ( )
Value:
STMT_BEGIN \
raw_assert(log_mutex_initialized); \
tor_mutex_acquire(&log_mutex); \
STMT_END
static tor_mutex_t log_mutex
Definition: log.c:161
static int log_mutex_initialized
Definition: log.c:163

Lock the log_mutex to prevent others from changing the logfile_t list

Definition at line 212 of file log.c.

◆ MAX_STARTUP_MSG_LEN

#define MAX_STARTUP_MSG_LEN   (1<<16)

Don't store more than this many bytes of messages while waiting for the logs to get configured.

Definition at line 209 of file log.c.

◆ SEVERITY_MASK_IDX

#define SEVERITY_MASK_IDX (   sev)    ((sev) - LOG_ERR)

Given a severity, yields an index into log_severity_list_t.masks to use for that severity.

Definition at line 60 of file log.c.

◆ TRUNCATED_STR

#define TRUNCATED_STR   "[...truncated]"

The string we stick at the end of a log message when it is too long, and its length.

Definition at line 65 of file log.c.

◆ UNLOCK_LOGS

#define UNLOCK_LOGS ( )
Value:
STMT_BEGIN \
raw_assert(log_mutex_initialized); \
tor_mutex_release(&log_mutex); \
STMT_END
static tor_mutex_t log_mutex
Definition: log.c:161
static int log_mutex_initialized
Definition: log.c:163

Unlock the log_mutex

Definition at line 217 of file log.c.

Typedef Documentation

◆ logfile_t

typedef struct logfile_t logfile_t

Information for a single logfile; only used in log.c

◆ pending_log_message_t

Represents a log message that we are going to send to callback-driven loggers once we can do so in a non-reentrant way.

Function Documentation

◆ add_callback_log()

int add_callback_log ( const log_severity_list_t severity,
log_callback  cb 
)

Add a log handler to send messages in severity to the function cb.

Definition at line 970 of file log.c.

◆ add_file_log()

int add_file_log ( const log_severity_list_t severity,
const char *  filename,
int  fd 
)

Add a log handler to send messages to filename via fd. If opening the logfile failed, -1 is returned and errno is set appropriately (by open(2)). Takes ownership of fd.

Definition at line 1140 of file log.c.

References add_stream_log_impl(), delete_log(), get_min_log_level(), LOCK_LOGS, log_global_min_severity_, log_tor_version(), logfiles, logfile_t::needs_close, tor_fd_seekend(), and UNLOCK_LOGS.

Referenced by open_and_add_file_log().

◆ add_stream_log()

void add_stream_log ( const log_severity_list_t severity,
const char *  name,
int  fd 
)

Add a log handler named name to send all messages in severity to fd. Steals a reference to severity; the caller must not use it after calling this function.

Definition at line 893 of file log.c.

◆ add_stream_log_impl()

static void add_stream_log_impl ( const log_severity_list_t severity,
const char *  name,
int  fd 
)
static

Add a log handler named name to send all messages in severity to fd. Copies severity. Helper: does no locking.

Definition at line 875 of file log.c.

Referenced by add_file_log().

◆ add_temp_log()

void add_temp_log ( int  min_severity)

Add a log handler to receive messages during startup (before the real logs are initialized).

Definition at line 936 of file log.c.

◆ change_callback_log_severity()

void change_callback_log_severity ( int  loglevelMin,
int  loglevelMax,
log_callback  cb 
)

Adjust the configured severity of any logs whose callback function is cb.

Definition at line 990 of file log.c.

References logfile_t::callback, get_min_log_level(), LOCK_LOGS, log_global_min_severity_, logfiles, logfile_t::next, set_log_severity_config(), logfile_t::severities, and UNLOCK_LOGS.

Referenced by control_adjust_event_log_severity().

◆ close_log()

static void close_log ( logfile_t victim)
static

Helper: release system resources (but not memory) held by a single logfile_t.

Definition at line 840 of file log.c.

References logfile_t::fd, logfile_t::is_syslog, and logfile_t::needs_close.

Referenced by close_temp_logs(), and logs_free_all().

◆ close_temp_logs()

void close_temp_logs ( void  )

Close any log handlers added by add_temp_log() or marked by mark_logs_temp().

Definition at line 1089 of file log.c.

References close_log(), LOCK_LOGS, logfiles, and logfile_t::next.

Referenced by rollback_log_changes().

◆ delete_log()

static void delete_log ( logfile_t victim)
static

Remove and free the log entry victim from the linked-list logfiles (it is probably present, but it might not be due to thread racing issues). After this function is called, the caller shouldn't refer to victim anymore.

Long-term, we need to do something about races in the log subsystem in general. See bug 222 for more details.

Definition at line 821 of file log.c.

References logfiles, and logfile_t::next.

Referenced by add_file_log().

◆ domain_to_string()

static char * domain_to_string ( log_domain_mask_t  domain,
char *  buf,
size_t  buflen 
)
static

Translate a bitmask of log domains to a string.

Definition at line 1293 of file log.c.

References ARRAY_LENGTH, domain_list, and tor_log2().

◆ flush_log_messages_from_startup()

void flush_log_messages_from_startup ( void  )

Flush all the messages we stored from startup while waiting for log initialization.

Definition at line 1051 of file log.c.

References logfile_t::fd, LOCK_LOGS, logfile_deliver(), logfile_wants_message(), logfiles, logfile_t::next, pending_startup_messages, pending_startup_messages_len, queue_startup_messages, and SMARTLIST_FOREACH_BEGIN.

◆ flush_pending_log_callbacks()

void flush_pending_log_callbacks ( void  )

If there are any log messages that were generated with LD_NOCB waiting to be sent to callback-based loggers, send them now.

Definition at line 1009 of file log.c.

References LOCK_LOGS, and pending_cb_messages.

Referenced by queued_events_flush_all().

◆ format_msg()

static char * format_msg ( char *  buf,
size_t  buf_len,
log_domain_mask_t  domain,
int  severity,
const char *  funcname,
const char *  suffix,
const char *  format,
va_list  ap,
size_t *  msg_len_out 
)
inlinestatic

Helper: Format a log message into a fixed-sized buffer. (This is factored out of logv so that we never format a message more than once.) Return a pointer to the first character of the message portion of the formatted string.

Definition at line 366 of file log.c.

◆ get_min_log_level()

int get_min_log_level ( void  )

Return the least severe log level that any current log is interested in.

Definition at line 1450 of file log.c.

References LOG_DEBUG, LOG_ERR, logfiles, log_severity_list_t::masks, logfile_t::next, logfile_t::severities, and SEVERITY_MASK_IDX.

Referenced by add_file_log(), change_callback_log_severity(), options_act_reversible(), and switch_logs_debug().

◆ init_logging()

void init_logging ( int  disable_startup_queue)

Initialize the global logging facility

Definition at line 902 of file log.c.

References log_mutex, log_mutex_initialized, pending_cb_messages, pending_startup_messages, pretty_fn_has_parens, queue_startup_messages, and tor_mutex_init().

◆ int_array_contains()

static int int_array_contains ( const int *  array,
int  n,
int  item 
)
static

Helper function; return true iff the n-element array array contains item.

Definition at line 650 of file log.c.

Referenced by tor_log_update_sigsafe_err_fds().

◆ log_fn_()

void log_fn_ ( int  severity,
log_domain_mask_t  domain,
const char *  fn,
const char *  format,
  ... 
)

Implementation of the log_fn backend, used when we have variadic macros. All arguments are as for log_fn, except for fn, which is the name of the calling functions.

Definition at line 734 of file log.c.

References log_global_min_severity_.

Referenced by tor_log_string().

◆ log_free_()

static void log_free_ ( logfile_t victim)
static

Free all storage held by victim.

Definition at line 763 of file log.c.

References logfile_t::android_tag, logfile_t::filename, logfile_t::severities, and tor_free.

◆ log_level_to_string()

const char* log_level_to_string ( int  level)

Return the string equivalent of a given log level.

Definition at line 1258 of file log.c.

References sev_to_string().

◆ log_message_is_interesting()

int log_message_is_interesting ( int  severity,
log_domain_mask_t  domain 
)

Return true if some of the running logs might be interested in a log message of the given severity in the given domains. If this function returns true, the log message might be ignored anyway, but if it returns false, it is definitely_ safe not to log the message.

Definition at line 258 of file log.c.

References log_global_min_severity_.

◆ log_prefix_()

static size_t log_prefix_ ( char *  buf,
size_t  buf_len,
int  severity 
)
inlinestatic

Helper: Write the standard prefix for log lines to a buf_len character buffer in buf.

Definition at line 293 of file log.c.

References log_time_granularity, sev_to_string(), tor_localtime_r_msg(), and tor_snprintf().

Referenced by log_tor_version().

◆ log_set_application_name()

void log_set_application_name ( const char *  name)

Set the "application name" for the logs to name: we'll use this name in the message we write when starting up, and at the start of each new log.

Tor uses this string to write the version number to the log file.

Definition at line 247 of file log.c.

Referenced by tor_init().

◆ log_tor_version()

static int log_tor_version ( logfile_t lf,
int  reset 
)
static

If lf refers to an actual file that we have just opened, and the file contains no data, log an "opening new logfile" message at the top.

Return -1 if the log is broken and needs to be deleted, else return 0.

Definition at line 328 of file log.c.

References appname, logfile_t::fd, logfile_t::is_temporary, LOG_NOTICE, log_prefix_(), logfile_t::needs_close, tor_fd_getpos(), tor_snprintf(), and write_all_to_fd_minimal().

Referenced by add_file_log().

◆ logfile_deliver()

static void logfile_deliver ( logfile_t lf,
const char *  buf,
size_t  msg_len,
const char *  msg_after_prefix,
log_domain_mask_t  domain,
int  severity,
int *  callbacks_deferred 
)
inlinestatic

Send a message to lf. The full message, with time prefix and severity, is in buf. The message itself is in msg_after_prefix. If callbacks_deferred points to true, then we already deferred this message for pending callbacks and don't need to do it again. Otherwise, if we need to do it, do it, and set callbacks_deferred to 1.

Definition at line 517 of file log.c.

References logfile_t::is_syslog.

Referenced by flush_log_messages_from_startup().

◆ logfile_is_external()

static int logfile_is_external ( const logfile_t lf)
inlinestatic

Helper function: returns true iff the log file, given in lf, is handled externally via the system log API, the Android logging API, or is an external callback function.

Definition at line 484 of file log.c.

Referenced by logfile_wants_message(), and tor_log_update_sigsafe_err_fds().

◆ logfile_wants_message()

static int logfile_wants_message ( const logfile_t lf,
int  severity,
log_domain_mask_t  domain 
)
inlinestatic

Return true iff lf would like to receive a message with the specified severity in the specified domain.

Definition at line 494 of file log.c.

References logfile_t::fd, logfile_is_external(), log_severity_list_t::masks, logfile_t::seems_dead, logfile_t::severities, and SEVERITY_MASK_IDX.

Referenced by flush_log_messages_from_startup().

◆ logs_free_all()

void logs_free_all ( void  )

Close all open log files, and free other static memory.

Definition at line 775 of file log.c.

References close_log(), LOCK_LOGS, logfiles, logfile_t::next, pending_cb_cb, pending_cb_messages, pending_startup_messages, and UNLOCK_LOGS.

◆ logs_set_domain_logging()

void logs_set_domain_logging ( int  enabled)

Set whether we report logging domains as a part of our log messages.

Definition at line 925 of file log.c.

References LOCK_LOGS, log_domains_are_logged, and UNLOCK_LOGS.

◆ logs_set_pending_callback_callback()

void logs_set_pending_callback_callback ( pending_callback_callback  cb)

Register "cb" as the callback to call when there are new pending log callbacks to be flushed with flush_pending_log_callbacks().

Note that this callback, if present, can be invoked from any thread.

This callback must not log.

It is intentional that this function contains the name "callback" twice: it sets a "callback" to be called on the condition that there is a "pending callback".

Definition at line 960 of file log.c.

◆ mark_logs_temp()

void mark_logs_temp ( void  )

Configure all log handles to be closed by close_temp_logs().

Definition at line 1125 of file log.c.

References logfile_t::is_temporary, LOCK_LOGS, logfiles, logfile_t::next, and UNLOCK_LOGS.

◆ MOCK_IMPL()

MOCK_IMPL ( STATIC  void,
logv  ,
(int severity, log_domain_mask_t domain, const char *funcname, const char *suffix, const char *format, va_list ap)   
)

Helper: sends a message to the appropriate logfiles, at loglevel severity. If provided, funcname is prepended to the message. The actual message is derived as from tor_snprintf(format,ap).

Definition at line 574 of file log.c.

◆ parse_log_domain()

static log_domain_mask_t parse_log_domain ( const char *  domain)
static

Return a bitmask for the log domain for which domain is the name, or 0 if there is no such name.

Definition at line 1281 of file log.c.

References domain_list.

◆ parse_log_level()

int parse_log_level ( const char *  level)

If level is a valid log severity, return the corresponding numeric value. Otherwise, return -1.

Definition at line 1241 of file log.c.

References LOG_DEBUG, LOG_ERR, LOG_INFO, LOG_NOTICE, and LOG_WARN.

◆ parse_log_severity_config()

int parse_log_severity_config ( const char **  cfg_ptr,
log_severity_list_t severity_out 
)

Parse a log severity pattern in *cfg_ptr. Advance cfg_ptr after the end of the severityPattern. Set the value of severity_out to the parsed pattern. Return 0 on success, -1 on failure.

The syntax for a SeverityPattern is:

  SeverityPattern = *(DomainSeverity SP)* DomainSeverity
  DomainSeverity = (DomainList SP)? SeverityRange
  SeverityRange = MinSeverity ("-" MaxSeverity )?
  DomainList = "[" (SP? DomainSpec SP? ",") SP? DomainSpec "]"
  DomainSpec = "*" | Domain | "~" Domain

A missing MaxSeverity defaults to ERR. Severities and domains are case-insensitive. "~" indicates negation for a domain; negation happens last inside a DomainList. Only one SeverityRange without a DomainList is allowed per line.

Definition at line 1345 of file log.c.

References eat_whitespace().

◆ pending_log_message_free_()

static void pending_log_message_free_ ( pending_log_message_t msg)
static

Release all storage held by msg.

Definition at line 471 of file log.c.

References pending_log_message_t::fullmsg, pending_log_message_t::msg, and tor_free.

◆ rollback_log_changes()

void rollback_log_changes ( void  )

Make all currently temporary logs (set to be closed by close_temp_logs) live again, and close all non-temporary logs.

Definition at line 1113 of file log.c.

References close_temp_logs(), logfile_t::is_temporary, LOCK_LOGS, logfiles, logfile_t::next, and UNLOCK_LOGS.

◆ set_log_severity_config()

void set_log_severity_config ( int  loglevelMin,
int  loglevelMax,
log_severity_list_t severity_out 
)

Adjust a log severity configuration in severity_out to contain every domain between loglevelMin and loglevelMax, inclusive.

Definition at line 859 of file log.c.

Referenced by change_callback_log_severity().

◆ set_log_time_granularity()

void set_log_time_granularity ( int  granularity_msec)

Define log time granularity for all logs to be granularity_msec milliseconds.

Definition at line 283 of file log.c.

References log_time_granularity, and tor_log_sigsafe_err_set_granularity().

◆ sev_to_string()

static const char* sev_to_string ( int  severity)
inlinestatic

Helper: map a log severity to descriptive string.

Definition at line 98 of file log.c.

References LOG_DEBUG, LOG_ERR, LOG_INFO, LOG_NOTICE, and LOG_WARN.

Referenced by log_level_to_string(), and log_prefix_().

◆ should_log_function_name()

static int should_log_function_name ( log_domain_mask_t  domain,
int  severity 
)
inlinestatic

Helper: decide whether to include the function name in the log message.

Definition at line 114 of file log.c.

References LD_BUG, LD_NOFUNCNAME, LOG_DEBUG, LOG_ERR, LOG_INFO, LOG_NOTICE, and LOG_WARN.

◆ switch_logs_debug()

void switch_logs_debug ( void  )

Switch all logs to output at most verbose level.

Definition at line 1465 of file log.c.

References get_min_log_level(), LOCK_LOGS, LOG_DEBUG, LOG_ERR, log_global_min_severity_, logfiles, log_severity_list_t::masks, logfile_t::next, logfile_t::severities, SEVERITY_MASK_IDX, and UNLOCK_LOGS.

◆ tor_log()

void tor_log ( int  severity,
log_domain_mask_t  domain,
const char *  format,
  ... 
)

Output a message to the log. It gets logged to all logfiles that care about messages with severity in domain. The content is formatted printf-style based on format and extra arguments.

Definition at line 632 of file log.c.

References log_global_min_severity_.

Referenced by channel_listener_dump_statistics(), circuit_log_path(), circuit_note_clock_jumped(), directory_info_has_arrived(), dump_routerlist_mem_usage(), dumpmemusage(), dumpstats(), handle_missing_protocol_warning_impl(), init_key_from_file(), keypin_load_journal_impl(), log_cert_lifetime(), log_new_relay_greeting(), MOCK_IMPL(), pubsub_cfg_dump(), rep_hist_dump_stats(), string_is_key_value(), and tor_log_mallinfo().

◆ tor_log_get_logfile_names()

void tor_log_get_logfile_names ( smartlist_t out)

Add to out a copy of every currently configured log file name. Used to enable access to these filenames with the sandbox code.

Definition at line 712 of file log.c.

◆ tor_log_string()

void tor_log_string ( int  severity,
log_domain_mask_t  domain,
const char *  function,
const char *  string 
)

As tor_log, but takes an optional function name, and does not treat its string as a printf format.

For use by Rust integration.

Definition at line 271 of file log.c.

References log_fn_().

◆ tor_log_update_sigsafe_err_fds()

void tor_log_update_sigsafe_err_fds ( void  )

Function to call whenever the list of logs changes to get ready to log from signal handlers.

Definition at line 663 of file log.c.

References logfile_t::fd, int_array_contains(), logfile_t::is_temporary, LD_BUG, LD_GENERAL, LOCK_LOGS, LOG_ERR, logfile_is_external(), logfiles, log_severity_list_t::masks, logfile_t::next, logfile_t::seems_dead, logfile_t::severities, SEVERITY_MASK_IDX, and TOR_SIGSAFE_LOG_MAX_FDS.

◆ truncate_logs()

void truncate_logs ( void  )

Truncate all the log files.

Definition at line 1480 of file log.c.

References logfile_t::fd, logfiles, logfile_t::next, and tor_ftruncate().

Variable Documentation

◆ appname

char static char* appname = NULL
static

Name of the application: used to generate the message we write at the start of each new log.

Definition at line 239 of file log.c.

Referenced by log_tor_version().

◆ domain_list

const char* domain_list[]
static
Initial value:
= {
"GENERAL", "CRYPTO", "NET", "CONFIG", "FS", "PROTOCOL", "MM",
"HTTP", "APP", "CONTROL", "CIRC", "REND", "BUG", "DIR", "DIRSERV",
"OR", "EDGE", "ACCT", "HIST", "HANDSHAKE", "HEARTBEAT", "CHANNEL",
"SCHED", "GUARD", "CONSDIFF", "DOS", "PROCESS", "PT", "BTRACK", "MESG",
NULL
}

NULL-terminated array of names for log domains such that domain_list[dom] is a description of dom.

Remember to update doc/tor.1.txt if you modify this list.

Definition at line 1268 of file log.c.

Referenced by domain_to_string(), and parse_log_domain().

◆ log_domains_are_logged

int log_domains_are_logged = 0
static

Boolean: do we report logging domains?

Definition at line 168 of file log.c.

Referenced by logs_set_domain_logging().

◆ log_global_min_severity_

int log_global_min_severity_ = LOG_NOTICE

What's the lowest log level anybody cares about? Checking this lets us bail out early from log_debug if we aren't debugging.

Definition at line 224 of file log.c.

Referenced by add_file_log(), change_callback_log_severity(), log_fn_(), log_message_is_interesting(), switch_logs_debug(), and tor_log().

◆ log_mutex

tor_mutex_t log_mutex
static

A mutex to guard changes to logfiles and logging.

Definition at line 161 of file log.c.

Referenced by init_logging().

◆ log_mutex_initialized

int log_mutex_initialized = 0
static

True iff we have initialized log_mutex

Definition at line 163 of file log.c.

Referenced by init_logging().

◆ log_time_granularity

int log_time_granularity = 1
static

Log time granularity in milliseconds.

Definition at line 278 of file log.c.

Referenced by log_prefix_(), and set_log_time_granularity().

◆ LOG_WARN_

const int LOG_WARN_ = LOG_WARN

Defining compile-time constants for Tor log levels (used by the Rust log wrapper at src/rust/tor_log)

Definition at line 71 of file log.c.

◆ logfiles

logfile_t* logfiles = NULL
static

◆ pending_cb_cb

pending_callback_callback pending_cb_cb = NULL
static

Callback to invoke when pending_cb_messages becomes nonempty.

Definition at line 189 of file log.c.

Referenced by logs_free_all().

◆ pending_cb_messages

smartlist_t* pending_cb_messages = NULL
static

Log messages waiting to be replayed onto callback-based logs

Definition at line 186 of file log.c.

Referenced by flush_pending_log_callbacks(), init_logging(), and logs_free_all().

◆ pending_startup_messages

smartlist_t* pending_startup_messages = NULL
static

Log messages waiting to be replayed once the logging system is initialized.

Definition at line 193 of file log.c.

Referenced by flush_log_messages_from_startup(), init_logging(), and logs_free_all().

◆ pending_startup_messages_len

size_t pending_startup_messages_len
static

Number of bytes of messages queued in pending_startup_messages. (This is the length of the messages, not the number of bytes used to store them.)

Definition at line 198 of file log.c.

Referenced by flush_log_messages_from_startup().

◆ pretty_fn_has_parens

int pretty_fn_has_parens = 0
static

True iff PRETTY_FUNCTION includes parenthesized arguments.

Definition at line 205 of file log.c.

Referenced by init_logging().

◆ queue_startup_messages

int queue_startup_messages = 1
static

True iff we should store messages while waiting for the logs to get configured.

Definition at line 202 of file log.c.

Referenced by flush_log_messages_from_startup(), and init_logging().