Tor 0.4.9.0-alpha-dev
|
#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_ |
#define HIGHEST_RESERVED_LD_DOMAIN_ (UINT64_C(1)<<(N_LOGGING_DOMAINS - 1)) |
#define LD_ALL_DOMAINS ((~(UINT64_C(0)))>>(64 - N_LOGGING_DOMAINS)) |
#define LD_ALL_FLAGS ((~(UINT64_C(0)))<<(64 - N_LOGGING_FLAGS)) |
#define LD_BUG (UINT64_C(1)<<12) |
#define LD_CIRC (UINT64_C(1)<<10) |
#define LD_CONFIG (UINT64_C(1)<<3) |
#define LD_CONSDIFF (UINT64_C(1)<<24) |
#define LD_CONTROL (UINT64_C(1)<<9) |
#define LD_DIR (UINT64_C(1)<<13) |
#define LD_DIRSERV (UINT64_C(1)<<14) |
#define LD_DOS (UINT64_C(1)<<25) |
#define LD_EDGE (UINT64_C(1)<<16) |
#define LD_FS (UINT64_C(1)<<4) |
#define LD_GENERAL (UINT64_C(1)<<0) |
#define LD_NOCB (UINT64_C(1)<<62) |
#define LD_NOFUNCNAME (UINT64_C(1)<<63) |
#define LD_PROTOCOL (UINT64_C(1)<<5) |
#define LOG_DEBUG 7 |
#define log_debug | ( | domain, | |
args, | |||
... | |||
) |
#define LOG_ERR 3 |
#define log_fn | ( | severity, | |
domain, | |||
args, | |||
... | |||
) | log_fn_(severity, domain, __FUNCTION__, args, ##__VA_ARGS__) |
#define log_fn_ratelim | ( | ratelim, | |
severity, | |||
domain, | |||
args, | |||
... | |||
) |
#define LOG_INFO 6 |
#define LOG_NOTICE 5 |
#define log_notice | ( | domain, | |
args, | |||
... | |||
) | log_fn_(LOG_NOTICE, domain, __FUNCTION__, args, ##__VA_ARGS__) |
#define LOG_WARN 4 |
#define LOWEST_RESERVED_LD_FLAG_ (UINT64_C(1)<<(64 - N_LOGGING_FLAGS)) |
typedef void(* log_callback) (int severity, log_domain_mask_t domain, const char *msg) |
int add_callback_log | ( | const log_severity_list_t * | severity, |
log_callback | cb | ||
) |
void add_default_log | ( | int | min_severity | ) |
Add a log handler to accept messages when no other log is configured.
Definition at line 950 of file log.c.
Referenced by add_default_log_for_quiet_level().
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 1154 of file log.c.
Referenced by open_and_add_file_log().
void add_stream_log | ( | const log_severity_list_t * | severity, |
const char * | name, | ||
int | fd | ||
) |
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 1003 of file log.c.
Referenced by control_adjust_event_log_severity().
void close_temp_logs | ( | void | ) |
Close any log handlers marked by mark_logs_temp().
Definition at line 1101 of file log.c.
Referenced by rollback_log_changes().
|
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().
void flush_log_messages_from_startup | ( | void | ) |
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 1022 of file log.c.
Referenced by queued_events_flush_all().
int get_min_log_level | ( | void | ) |
Return the least severe log level that any current log is interested in.
Definition at line 1432 of file log.c.
Referenced by add_file_log(), change_callback_log_severity(), and switch_logs_debug().
void init_logging | ( | int | disable_startup_queue | ) |
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 706 of file log.c.
Referenced by tor_log_string().
void log_fn_ratelim_ | ( | struct ratelim_t * | ratelim, |
int | severity, | ||
log_domain_mask_t | domain, | ||
const char * | funcname, | ||
const char * | format, | ||
... | |||
) |
const char * log_level_to_string | ( | int | level | ) |
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.
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 212 of file log.c.
Referenced by tor_init().
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 796 of file log.c.
Referenced by tor_abort_().
void logs_free_all | ( | void | ) |
void logs_set_domain_logging | ( | int | enabled | ) |
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".
void mark_logs_temp | ( | void | ) |
Configure all log handles to be closed by close_temp_logs().
int parse_log_level | ( | const char * | level | ) |
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.
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 1125 of file log.c.
Referenced by options_rollback_log_transaction().
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 873 of file log.c.
Referenced by change_callback_log_severity().
void set_log_time_granularity | ( | int | granularity_msec | ) |
void switch_logs_debug | ( | void | ) |
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 591 of file log.c.
Referenced by channel_dump_statistics(), 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(), handle_response_fetch_consensus(), hs_service_dump_stats(), init_key_from_file(), keypin_load_journal_impl(), log_cert_lifetime(), log_new_relay_greeting(), managed_proxy_set_state(), pubsub_cfg_dump(), rep_hist_dump_stats(), and string_is_key_value().
void tor_log_get_logfile_names | ( | smartlist_t * | out | ) |
void tor_log_string | ( | int | severity, |
log_domain_mask_t | domain, | ||
const char * | function, | ||
const char * | string | ||
) |
void tor_log_update_sigsafe_err_fds | ( | void | ) |
|
extern |
|
extern |
|
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 188 of file log.c.
Referenced by add_file_log(), change_callback_log_severity(), log_fn_(), log_message_is_interesting(), and switch_logs_debug().
|
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)