Tor  0.4.7.0-alpha-dev
Data Structures | Macros | Typedefs | Functions | Variables
log.h File Reference

Headers for log.c. More...

#include <stdarg.h>
#include "lib/cc/torint.h"
#include "lib/cc/compat_compiler.h"
#include "lib/defs/logging_types.h"
#include "lib/testsupport/testsupport.h"

Go to the source code of this file.

Data Structures

struct  log_severity_list_t
 

Macros

#define LOG_DEBUG   7
 
#define LOG_INFO   6
 
#define LOG_NOTICE   5
 
#define LOG_WARN   4
 
#define LOG_ERR   3
 
#define LD_GENERAL   (UINT64_C(1)<<0)
 
#define LD_CRYPTO   (UINT64_C(1)<<1)
 
#define LD_NET   (UINT64_C(1)<<2)
 
#define LD_CONFIG   (UINT64_C(1)<<3)
 
#define LD_FS   (UINT64_C(1)<<4)
 
#define LD_PROTOCOL   (UINT64_C(1)<<5)
 
#define LD_MM   (UINT64_C(1)<<6)
 
#define LD_HTTP   (UINT64_C(1)<<7)
 
#define LD_APP   (UINT64_C(1)<<8)
 
#define LD_CONTROL   (UINT64_C(1)<<9)
 
#define LD_CIRC   (UINT64_C(1)<<10)
 
#define LD_REND   (UINT64_C(1)<<11)
 
#define LD_BUG   (UINT64_C(1)<<12)
 
#define LD_DIR   (UINT64_C(1)<<13)
 
#define LD_DIRSERV   (UINT64_C(1)<<14)
 
#define LD_OR   (UINT64_C(1)<<15)
 
#define LD_EDGE   (UINT64_C(1)<<16)
 
#define LD_EXIT   LD_EDGE
 
#define LD_ACCT   (UINT64_C(1)<<17)
 
#define LD_HIST   (UINT64_C(1)<<18)
 
#define LD_HANDSHAKE   (UINT64_C(1)<<19)
 
#define LD_HEARTBEAT   (UINT64_C(1)<<20)
 
#define LD_CHANNEL   (UINT64_C(1)<<21)
 
#define LD_SCHED   (UINT64_C(1)<<22)
 
#define LD_GUARD   (UINT64_C(1)<<23)
 
#define LD_CONSDIFF   (UINT64_C(1)<<24)
 
#define LD_DOS   (UINT64_C(1)<<25)
 
#define LD_PROCESS   (UINT64_C(1)<<26)
 
#define LD_PT   (UINT64_C(1)<<27)
 
#define LD_BTRACK   (UINT64_C(1)<<28)
 
#define LD_MESG   (UINT64_C(1)<<29)
 
#define N_LOGGING_DOMAINS   30
 
#define HIGHEST_RESERVED_LD_DOMAIN_   (UINT64_C(1)<<(N_LOGGING_DOMAINS - 1))
 
#define LD_ALL_DOMAINS   ((~(UINT64_C(0)))>>(64 - N_LOGGING_DOMAINS))
 
#define N_LOGGING_FLAGS   3
 
#define LOWEST_RESERVED_LD_FLAG_   (UINT64_C(1)<<(64 - N_LOGGING_FLAGS))
 
#define LD_ALL_FLAGS   ((~(UINT64_C(0)))<<(64 - N_LOGGING_FLAGS))
 
#define LD_NOCB   (UINT64_C(1)<<62)
 
#define LD_NOFUNCNAME   (UINT64_C(1)<<63)
 
#define log_debug(domain, args, ...)
 
#define log_info(domain, args, ...)    log_fn_(LOG_INFO, domain, __FUNCTION__, args, ##__VA_ARGS__)
 
#define log_notice(domain, args, ...)    log_fn_(LOG_NOTICE, domain, __FUNCTION__, args, ##__VA_ARGS__)
 
#define log_warn(domain, args, ...)    log_fn_(LOG_WARN, domain, __FUNCTION__, args, ##__VA_ARGS__)
 
#define log_err(domain, args, ...)    log_fn_(LOG_ERR, domain, __FUNCTION__, args, ##__VA_ARGS__)
 
#define log_fn(severity, domain, args, ...)    log_fn_(severity, domain, __FUNCTION__, args, ##__VA_ARGS__)
 
#define log_fn_ratelim(ratelim, severity, domain, args, ...)
 

Typedefs

typedef void(* log_callback) (int severity, log_domain_mask_t domain, const char *msg)
 
typedef void(* pending_callback_callback) (void)
 

Functions

void init_logging (int disable_startup_queue)
 
int parse_log_level (const char *level)
 
const char * log_level_to_string (int level)
 
int parse_log_severity_config (const char **cfg, log_severity_list_t *severity_out)
 
void set_log_severity_config (int minSeverity, int maxSeverity, log_severity_list_t *severity_out)
 
void add_stream_log (const log_severity_list_t *severity, const char *name, int fd)
 
int add_file_log (const log_severity_list_t *severity, const char *filename, int fd)
 
int add_callback_log (const log_severity_list_t *severity, log_callback cb)
 
void logs_set_pending_callback_callback (pending_callback_callback cb)
 
void logs_set_domain_logging (int enabled)
 
int get_min_log_level (void)
 
void switch_logs_debug (void)
 
void logs_free_all (void)
 
void logs_flush_sigsafe (void)
 
void add_default_log (int min_severity)
 
void close_temp_logs (void)
 
void rollback_log_changes (void)
 
void mark_logs_temp (void)
 
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 log_set_application_name (const char *name)
 
void set_log_time_granularity (int granularity_msec)
 
void truncate_logs (void)
 
void tor_log (int severity, log_domain_mask_t domain, const char *format,...)
 
void tor_log_update_sigsafe_err_fds (void)
 
void tor_log_get_logfile_names (struct smartlist_t *out)
 
static bool debug_logging_enabled (void)
 
void log_fn_ (int severity, log_domain_mask_t domain, const char *funcname, const char *format,...)
 
void log_fn_ratelim_ (struct ratelim_t *ratelim, int severity, log_domain_mask_t domain, const char *funcname, const char *format,...)
 
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)
 

Variables

int log_global_min_severity_
 
const int LOG_WARN_
 
const int LOG_NOTICE_
 
const log_domain_mask_t LD_NET_
 
const log_domain_mask_t LD_GENERAL_
 

Detailed Description

Headers for log.c.

Definition in file log.h.

Macro Definition Documentation

◆ HIGHEST_RESERVED_LD_DOMAIN_

#define HIGHEST_RESERVED_LD_DOMAIN_   (UINT64_C(1)<<(N_LOGGING_DOMAINS - 1))

The highest log domain

Definition at line 126 of file log.h.

◆ LD_ACCT

#define LD_ACCT   (UINT64_C(1)<<17)

Bandwidth accounting.

Definition at line 97 of file log.h.

◆ LD_ALL_DOMAINS

#define LD_ALL_DOMAINS   ((~(UINT64_C(0)))>>(64 - N_LOGGING_DOMAINS))

All log domains.

Definition at line 128 of file log.h.

◆ LD_ALL_FLAGS

#define LD_ALL_FLAGS   ((~(UINT64_C(0)))<<(64 - N_LOGGING_FLAGS))

All log flags.

Definition at line 135 of file log.h.

◆ LD_APP

#define LD_APP   (UINT64_C(1)<<8)

Application (socks) requests.

Definition at line 78 of file log.h.

◆ LD_BTRACK

#define LD_BTRACK   (UINT64_C(1)<<28)

Bootstrap tracker.

Definition at line 119 of file log.h.

◆ LD_BUG

#define LD_BUG   (UINT64_C(1)<<12)

Internal errors in this Tor process.

Definition at line 86 of file log.h.

◆ LD_CHANNEL

#define LD_CHANNEL   (UINT64_C(1)<<21)

Abstract channel_t code

Definition at line 105 of file log.h.

◆ LD_CIRC

#define LD_CIRC   (UINT64_C(1)<<10)

Building, using, and managing circuits.

Definition at line 82 of file log.h.

◆ LD_CONFIG

#define LD_CONFIG   (UINT64_C(1)<<3)

Parsing and acting on our configuration.

Definition at line 68 of file log.h.

◆ LD_CONSDIFF

#define LD_CONSDIFF   (UINT64_C(1)<<24)

Generation and application of consensus diffs.

Definition at line 111 of file log.h.

◆ LD_CONTROL

#define LD_CONTROL   (UINT64_C(1)<<9)

Communication via the controller protocol.

Definition at line 80 of file log.h.

◆ LD_CRYPTO

#define LD_CRYPTO   (UINT64_C(1)<<1)

The cryptography subsystem.

Definition at line 64 of file log.h.

◆ LD_DIR

#define LD_DIR   (UINT64_C(1)<<13)

Learning and using information about Tor servers.

Definition at line 88 of file log.h.

◆ LD_DIRSERV

#define LD_DIRSERV   (UINT64_C(1)<<14)

Learning and using information about Tor servers.

Definition at line 90 of file log.h.

◆ LD_DOS

#define LD_DOS   (UINT64_C(1)<<25)

Denial of Service mitigation.

Definition at line 113 of file log.h.

◆ LD_EDGE

#define LD_EDGE   (UINT64_C(1)<<16)

Generic edge-connection functionality.

Definition at line 94 of file log.h.

◆ LD_FS

#define LD_FS   (UINT64_C(1)<<4)

Reading and writing from the filesystem.

Definition at line 70 of file log.h.

◆ LD_GENERAL

#define LD_GENERAL   (UINT64_C(1)<<0)

Catch-all for miscellaneous events and fatal errors.

Definition at line 62 of file log.h.

◆ LD_GUARD

#define LD_GUARD   (UINT64_C(1)<<23)

Guard nodes

Definition at line 109 of file log.h.

◆ LD_HANDSHAKE

#define LD_HANDSHAKE   (UINT64_C(1)<<19)

OR handshaking

Definition at line 101 of file log.h.

◆ LD_HEARTBEAT

#define LD_HEARTBEAT   (UINT64_C(1)<<20)

Heartbeat messages

Definition at line 103 of file log.h.

◆ LD_HIST

#define LD_HIST   (UINT64_C(1)<<18)

Router history

Definition at line 99 of file log.h.

◆ LD_HTTP

#define LD_HTTP   (UINT64_C(1)<<7)

HTTP implementation.

Definition at line 76 of file log.h.

◆ LD_MESG

#define LD_MESG   (UINT64_C(1)<<29)

Message-passing backend.

Definition at line 121 of file log.h.

◆ LD_MM

#define LD_MM   (UINT64_C(1)<<6)

Memory management.

Definition at line 74 of file log.h.

◆ LD_NET

#define LD_NET   (UINT64_C(1)<<2)

Networking.

Definition at line 66 of file log.h.

◆ LD_NOCB

#define LD_NOCB   (UINT64_C(1)<<62)

This log message is not safe to send to a callback-based logger immediately. Used as a flag, not a log domain.

Definition at line 144 of file log.h.

◆ LD_NOFUNCNAME

#define LD_NOFUNCNAME   (UINT64_C(1)<<63)

This log message should not include a function name, even if it otherwise would. Used as a flag, not a log domain.

Definition at line 147 of file log.h.

◆ LD_OR

#define LD_OR   (UINT64_C(1)<<15)

Onion routing protocol.

Definition at line 92 of file log.h.

◆ LD_PROCESS

#define LD_PROCESS   (UINT64_C(1)<<26)

Processes

Definition at line 115 of file log.h.

◆ LD_PROTOCOL

#define LD_PROTOCOL   (UINT64_C(1)<<5)

Other servers' (non)compliance with the Tor protocol.

Definition at line 72 of file log.h.

◆ LD_PT

#define LD_PT   (UINT64_C(1)<<27)

Pluggable Transports.

Definition at line 117 of file log.h.

◆ LD_REND

#define LD_REND   (UINT64_C(1)<<11)

Hidden services.

Definition at line 84 of file log.h.

◆ LD_SCHED

#define LD_SCHED   (UINT64_C(1)<<22)

Scheduler

Definition at line 107 of file log.h.

◆ LOG_DEBUG

#define LOG_DEBUG   7

Debug-level severity: for hyper-verbose messages of no interest to anybody but developers.

Definition at line 42 of file log.h.

◆ log_debug

#define log_debug (   domain,
  args,
  ... 
)
Value:
STMT_BEGIN \
log_fn_(LOG_DEBUG, domain, __FUNCTION__, args, ##__VA_ARGS__); \
STMT_END
#define LOG_DEBUG
Definition: log.h:42
static bool debug_logging_enabled(void)
Definition: log.h:217

Definition at line 268 of file log.h.

◆ LOG_ERR

#define LOG_ERR   3

Error-level severity: for messages that only appear when something has gone very wrong, and the Tor process can no longer proceed.

Definition at line 56 of file log.h.

◆ log_fn

#define log_fn (   severity,
  domain,
  args,
  ... 
)     log_fn_(severity, domain, __FUNCTION__, args, ##__VA_ARGS__)

Log a message at level severity, using a pretty-printed version of the current function name.

Definition at line 283 of file log.h.

◆ log_fn_ratelim

#define log_fn_ratelim (   ratelim,
  severity,
  domain,
  args,
  ... 
)
Value:
log_fn_ratelim_(ratelim, severity, domain, __FUNCTION__, \
args, ##__VA_ARGS__)

As log_fn, but use ratelim (an instance of ratelim_t) to control the frequency at which messages can appear.

Definition at line 288 of file log.h.

◆ LOG_INFO

#define LOG_INFO   6

Info-level severity: for messages that appear frequently during normal operation.

Definition at line 45 of file log.h.

◆ LOG_NOTICE

#define LOG_NOTICE   5

Notice-level severity: for messages that appear infrequently during normal operation; that the user will probably care about; and that are not errors.

Definition at line 50 of file log.h.

◆ LOG_WARN

#define LOG_WARN   4

Warn-level severity: for messages that only appear when something has gone wrong.

Definition at line 53 of file log.h.

◆ LOWEST_RESERVED_LD_FLAG_

#define LOWEST_RESERVED_LD_FLAG_   (UINT64_C(1)<<(64 - N_LOGGING_FLAGS))

First bit that is reserved in log_domain_mask_t for non-domain flags.

Definition at line 133 of file log.h.

◆ N_LOGGING_DOMAINS

#define N_LOGGING_DOMAINS   30

The number of log domains.

Definition at line 124 of file log.h.

◆ N_LOGGING_FLAGS

#define N_LOGGING_FLAGS   3

The number of log flags.

Definition at line 131 of file log.h.

Typedef Documentation

◆ log_callback

typedef void(* log_callback) (int severity, log_domain_mask_t domain, const char *msg)

Callback type used for add_callback_log.

Definition at line 158 of file log.h.

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 977 of file log.c.

◆ add_default_log()

void add_default_log ( int  min_severity)

Add a log handler to accept messages when no other log is configured.

Definition at line 944 of file log.c.

Referenced by add_default_log_for_quiet_level().

◆ 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 1148 of file log.c.

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 902 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 997 of file log.c.

Referenced by control_adjust_event_log_severity().

◆ close_temp_logs()

void close_temp_logs ( void  )

Close any log handlers marked by mark_logs_temp().

Definition at line 1095 of file log.c.

Referenced by rollback_log_changes().

◆ debug_logging_enabled()

static bool debug_logging_enabled ( void  )
inlinestatic

Return true iff debug logging is enabled for at least one domain.

Definition at line 217 of file log.h.

Referenced by dispatch_send_msg_unchecked(), and dispatcher_run_msg_cbs().

◆ 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 1058 of file log.c.

◆ 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 1016 of file log.c.

Referenced by queued_events_flush_all().

◆ 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 1426 of file log.c.

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

◆ init_logging()

void init_logging ( int  disable_startup_queue)

Initialize the global logging facility

Definition at line 911 of file log.c.

◆ 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 function.

Definition at line 705 of file log.c.

Referenced by tor_log_string().

◆ log_level_to_string()

const char* log_level_to_string ( int  level)

Return the string equivalent of a given log level.

Definition at line 1231 of file log.c.

◆ 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 222 of file log.c.

◆ 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 211 of file log.c.

Referenced by tor_init().

◆ logs_flush_sigsafe()

void logs_flush_sigsafe ( void  )

Flush the signal-safe log files.

This function is safe to call from a signal handler. It is currently called by the BUG() macros, when terminating the process on an abnormal condition.

Definition at line 791 of file log.c.

Referenced by tor_abort_().

◆ logs_free_all()

void logs_free_all ( void  )

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

Definition at line 745 of file log.c.

◆ 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 934 of file log.c.

◆ 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 967 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 1131 of file log.c.

◆ 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 1214 of file log.c.

◆ 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 1322 of file log.c.

◆ 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 1119 of file log.c.

Referenced by options_rollback_log_transaction().

◆ 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 868 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 247 of file log.c.

◆ switch_logs_debug()

void switch_logs_debug ( void  )

Switch all logs to output at most verbose level.

Definition at line 1441 of file log.c.

◆ tor_log()

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

◆ 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 683 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 235 of file log.c.

◆ 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 625 of file log.c.

◆ truncate_logs()

void truncate_logs ( void  )

Truncate all the log files.

Definition at line 1456 of file log.c.

Variable Documentation

◆ log_global_min_severity_

int log_global_min_severity_
extern

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 187 of file log.c.

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

◆ LOG_WARN_

const int LOG_WARN_
extern

This defines log levels that are linked in the Rust log module, rather than re-defining these in both Rust and C.

C_RUST_COUPLED src/rust/tor_log LogSeverity, LogDomain

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

Definition at line 63 of file log.c.