error handling API More...
Go to the source code of this file.
Data Structures | |
struct | CustomLogger |
Linked list of active loggers. More... | |
struct | LogDef |
Represents a single logging definition. More... | |
Macros | |
#define | BULK_DELAY_THRESHOLD (12 * 60 * 60 * 1000LL * 1000LL) |
After how many milliseconds do we always print that "message X was repeated N times"? Use 12h. More... | |
#define | BULK_REPEAT_THRESHOLD 1000 |
After how many repetitions do we always print that "message X was repeated N times"? (even if we have not yet reached the delay threshold) More... | |
#define | BULK_TRACK_SIZE 256 |
How many characters do we use for matching of bulk messages? More... | |
#define | COMP_TRACK_SIZE 32 |
How many characters do we use for matching of bulk components? More... | |
#define | DATE_STR_SIZE 64 |
How many characters can a date/time string be at most? More... | |
#define | ROTATION_KEEP 3 |
How many log files to keep? More... | |
#define | PATH_MAX 4096 |
Assumed maximum path length (for the log file name). More... | |
#define | LEN |
Functions | |
static enum GNUNET_ErrorType | get_type (const char *log) |
Convert a textual description of a loglevel to the respective enumeration type. More... | |
void | GNUNET_abort_ () |
Abort the process, generate a core dump if possible. More... | |
static void | resize_logdefs (void) |
Utility function - reallocates logdefs array to be twice as large. More... | |
static void | log_rotate (const char *new_name) |
Rotate logs, deleting the oldest log. More... | |
const char * | GNUNET_b2s (const void *buf, size_t buf_size) |
Convert a buffer to an 8-character string representative of the contents. More... | |
static enum GNUNET_GenericReturnValue | setup_log_file (const struct tm *tm) |
Setup the log file. More... | |
static int | add_definition (const char *lcomponent, const char *file, const char *function, int from_line, int to_line, int level, int force) |
Utility function - adds a parsed definition to logdefs array. More... | |
int | GNUNET_get_log_call_status (int caller_level, const char *comp, const char *file, const char *function, int line) |
Decides whether a particular logging call should or should not be allowed to be made. More... | |
static int | parse_definitions (const char *constname, int force) |
Utility function - parses a definition. More... | |
static void | parse_all_definitions () |
Utility function - parses GNUNET_LOG and GNUNET_FORCE_LOG. More... | |
enum GNUNET_GenericReturnValue | GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile) |
Setup logging. More... | |
void | GNUNET_logger_add (GNUNET_Logger logger, void *logger_cls) |
Add a custom logger. More... | |
void | GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls) |
Remove a custom logger. More... | |
static void | output_message (enum GNUNET_ErrorType kind, const char *comp, const char *datestr, const char *msg) |
Actually output the log message. More... | |
static void | flush_bulk (const char *datestr) |
Flush an existing bulk report to the output. More... | |
void | GNUNET_log_skip (int n, int check_reset) |
Ignore the next n calls to the log function. More... | |
int | GNUNET_get_log_skip () |
Get the number of log calls that are going to be skipped. More... | |
static void | mylog (enum GNUNET_ErrorType kind, const char *comp, const char *message, va_list va) |
Output a log message using the default mechanism. More... | |
void | GNUNET_log_nocheck (enum GNUNET_ErrorType kind, const char *message,...) |
Main log function. More... | |
void | GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind, const char *comp, const char *message,...) |
Log function that specifies an alternative component. More... | |
const char * | GNUNET_error_type_to_string (enum GNUNET_ErrorType kind) |
Convert error type to string. More... | |
const char * | GNUNET_h2s (const struct GNUNET_HashCode *hc) |
Convert a hash to a string (for printing debug messages). More... | |
const char * | GNUNET_h2s2 (const struct GNUNET_HashCode *hc) |
Convert a hash to a string (for printing debug messages). More... | |
const char * | GNUNET_p2s (const struct GNUNET_CRYPTO_EddsaPublicKey *p) |
Convert a public key value to a string (for printing debug messages). More... | |
const char * | GNUNET_p2s2 (const struct GNUNET_CRYPTO_EddsaPublicKey *p) |
Convert a public key value to a string (for printing debug messages). More... | |
const char * | GNUNET_e2s (const struct GNUNET_CRYPTO_EcdhePublicKey *p) |
Convert a public key value to a string (for printing debug messages). More... | |
const char * | GNUNET_e2s2 (const struct GNUNET_CRYPTO_EcdhePublicKey *p) |
Convert a public key value to a string (for printing debug messages). More... | |
const char * | GNUNET_sh2s (const struct GNUNET_ShortHashCode *shc) |
Convert a short hash value to a string (for printing debug messages). More... | |
const char * | GNUNET_uuid2s (const struct GNUNET_Uuid *uuid) |
Convert a UUID to a string (for printing debug messages). More... | |
const char * | GNUNET_h2s_full (const struct GNUNET_HashCode *hc) |
Convert a hash to a string (for printing debug messages). More... | |
const char * | GNUNET_i2s (const struct GNUNET_PeerIdentity *pid) |
Convert a peer identity to a string (for printing debug messages). More... | |
const char * | GNUNET_i2s2 (const struct GNUNET_PeerIdentity *pid) |
Convert a peer identity to a string (for printing debug messages). More... | |
const char * | GNUNET_i2s_full (const struct GNUNET_PeerIdentity *pid) |
Convert a peer identity to a string (for printing debug messages). More... | |
const char * | GNUNET_a2s (const struct sockaddr *addr, socklen_t addrlen) |
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages). More... | |
void | GNUNET_log_config_missing (enum GNUNET_ErrorType kind, const char *section, const char *option) |
Log error message about missing configuration option. More... | |
void | GNUNET_log_config_invalid (enum GNUNET_ErrorType kind, const char *section, const char *option, const char *required) |
Log error message about invalid configuration option value. More... | |
void | GNUNET_async_scope_enter (const struct GNUNET_AsyncScopeId *aid, struct GNUNET_AsyncScopeSave *old_scope) |
Set the async scope for the current thread. More... | |
void | GNUNET_async_scope_restore (struct GNUNET_AsyncScopeSave *old_scope) |
Clear the current thread's async scope. More... | |
void | GNUNET_async_scope_fresh (struct GNUNET_AsyncScopeId *aid_ret) |
Generate a fresh async scope identifier. More... | |
void | GNUNET_async_scope_get (struct GNUNET_AsyncScopeSave *scope_ret) |
Get the current async scope. More... | |
size_t | GNUNET_hex2b (const char *src, void *dst, size_t dstlen, int invert) |
Parse an ascii-encoded hexadecimal string into the buffer. More... | |
void | GNUNET_print_bytes (const void *buf, size_t buf_len, int fold, int in_be) |
Print a byte string in hexadecimal ascii notation. More... | |
void | GNUNET_util_cl_init (void) |
void | __attribute__ ((constructor)) |
Initializer. More... | |
void | GNUNET_util_cl_fini (void) |
void | __attribute__ ((destructor)) |
Destructor. More... | |
Variables | |
static GNUNET_THREAD_LOCAL struct GNUNET_AsyncScopeSave | current_async_scope |
Asynchronous scope of the current thread, or NULL if we have not entered an async scope yet. More... | |
static GNUNET_THREAD_LOCAL char last_bulk[256] | __nonstring |
The last "bulk" error message that we have been logging. More... | |
static GNUNET_THREAD_LOCAL enum GNUNET_ErrorType | last_bulk_kind |
Type of the last bulk message. More... | |
static GNUNET_THREAD_LOCAL struct GNUNET_TIME_Absolute | last_bulk_time |
Time of the last bulk error message (0 for none) More... | |
static GNUNET_THREAD_LOCAL unsigned int | last_bulk_repeat |
Number of times that bulk message has been repeated since. More... | |
static GNUNET_THREAD_LOCAL char | last_bulk_comp [32+1] |
Component when the last bulk was logged. More... | |
static char * | component |
Running component. More... | |
static char * | component_nopid |
Running component (without pid). More... | |
static char * | log_file_name |
Format string describing the name of the log file. More... | |
static enum GNUNET_ErrorType | min_level |
Minimum log level. More... | |
static struct CustomLogger * | loggers |
Linked list of our custom loggres. More... | |
static GNUNET_THREAD_LOCAL int | skip_log = 0 |
Number of log calls to ignore. More... | |
static FILE * | GNUNET_stderr |
File descriptor to use for "stderr", or NULL for none. More... | |
static struct LogDef * | logdefs |
Dynamic array of logging definitions. More... | |
static int | logdefs_size |
Allocated size of logdefs array (in units) More... | |
static int | logdefs_len |
The number of units used in logdefs array. More... | |
static int | gnunet_log_parsed |
GNUNET_YES if GNUNET_LOG environment variable is already parsed. More... | |
static int | gnunet_force_log_parsed |
GNUNET_YES if GNUNET_FORCE_LOG environment variable is already parsed. More... | |
static int | gnunet_force_log_present |
GNUNET_YES if at least one definition with forced == 1 is available. More... | |
error handling API
Definition in file common_logging.c.
#define BULK_DELAY_THRESHOLD (12 * 60 * 60 * 1000LL * 1000LL) |
After how many milliseconds do we always print that "message X was repeated N times"? Use 12h.
Definition at line 36 of file common_logging.c.
#define BULK_REPEAT_THRESHOLD 1000 |
After how many repetitions do we always print that "message X was repeated N times"? (even if we have not yet reached the delay threshold)
Definition at line 43 of file common_logging.c.
#define BULK_TRACK_SIZE 256 |
How many characters do we use for matching of bulk messages?
Definition at line 49 of file common_logging.c.
#define COMP_TRACK_SIZE 32 |
How many characters do we use for matching of bulk components?
Definition at line 55 of file common_logging.c.
#define DATE_STR_SIZE 64 |
How many characters can a date/time string be at most?
Definition at line 61 of file common_logging.c.
#define ROTATION_KEEP 3 |
How many log files to keep?
Definition at line 66 of file common_logging.c.
#define PATH_MAX 4096 |
Assumed maximum path length (for the log file name).
Definition at line 72 of file common_logging.c.
#define LEN |
|
static |
Convert a textual description of a loglevel to the respective enumeration type.
log | loglevel to parse |
Definition at line 254 of file common_logging.c.
References GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_INVALID, GNUNET_ERROR_TYPE_MESSAGE, GNUNET_ERROR_TYPE_NONE, GNUNET_ERROR_TYPE_UNSPECIFIED, and GNUNET_ERROR_TYPE_WARNING.
Referenced by GNUNET_log_setup(), and parse_definitions().
|
static |
Utility function - reallocates logdefs array to be twice as large.
Definition at line 289 of file common_logging.c.
References GNUNET_realloc, logdefs, and logdefs_size.
Referenced by add_definition().
|
static |
Rotate logs, deleting the oldest log.
new_name | new name to add to the rotation |
Definition at line 302 of file common_logging.c.
References GNUNET_free, GNUNET_strdup, and ROTATION_KEEP.
Referenced by setup_log_file().
|
static |
Setup the log file.
tm | timestamp for which we should setup logging |
Definition at line 352 of file common_logging.c.
References GNUNET_DISK_directory_create_for_file(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log_strerror_file, GNUNET_OK, GNUNET_stderr, GNUNET_strdup, GNUNET_SYSERR, log_file_name, log_rotate(), and PATH_MAX.
Referenced by GNUNET_log_setup(), and mylog().
|
static |
Utility function - adds a parsed definition to logdefs array.
component | see struct LogDef, can't be NULL |
file | see struct LogDef, can't be NULL |
function | see struct LogDef, can't be NULL |
from_line | see struct LogDef |
to_line | see struct LogDef |
level | see struct LogDef, must be >= 0 |
force | see struct LogDef |
Definition at line 439 of file common_logging.c.
References LogDef::component_regex, LogDef::file_regex, LogDef::force, LogDef::from_line, LogDef::function_regex, LogDef::level, logdefs, logdefs_len, logdefs_size, resize_logdefs(), and LogDef::to_line.
Referenced by parse_definitions().
|
static |
Utility function - parses a definition.
Definition format: component;file;function;from_line-to_line;level[/component...] All entries are mandatory, but may be empty. Empty entries for component, file and function are treated as "matches anything". Empty line entry is treated as "from 0 to INT_MAX" Line entry with only one line is treated as "this line only" Entry for level MUST NOT be empty. Entries for component, file and function that consist of a single character "*" are treated (at the moment) the same way empty entries are treated (wildcard matching is not implemented (yet?)). file entry is matched to the end of FILE. That is, it might be a base name, or a base name with leading directory names (some compilers define FILE to absolute file path).
constname | name of the environment variable from which to get the string to be parsed |
force | 1 if definitions found in constname are to be forced |
Definition at line 570 of file common_logging.c.
References _, add_definition(), LogDef::force, LogDef::from_line, get_type(), getenv(), GNUNET_ERROR_TYPE_INVALID, GNUNET_ERROR_TYPE_UNSPECIFIED, GNUNET_free, GNUNET_strdup, INT_MAX, LogDef::level, p, start, state, t, and LogDef::to_line.
Referenced by parse_all_definitions().
|
static |
Utility function - parses GNUNET_LOG and GNUNET_FORCE_LOG.
Definition at line 704 of file common_logging.c.
References gnunet_force_log_parsed, gnunet_force_log_present, gnunet_log_parsed, GNUNET_NO, GNUNET_YES, and parse_definitions().
Referenced by GNUNET_log_setup().
|
static |
Actually output the log message.
kind | how severe was the issue |
comp | component responsible |
datestr | current date/time |
msg | the actual message |
Definition at line 820 of file common_logging.c.
References current_async_scope, end, getenv(), GNUNET_assert, GNUNET_ERROR_TYPE_MESSAGE, GNUNET_error_type_to_string(), GNUNET_stderr, GNUNET_STRINGS_data_to_string(), GNUNET_THREAD_LOCAL, GNUNET_YES, GNUNET_AsyncScopeSave::have_scope, CustomLogger::logger, CustomLogger::logger_cls, loggers, msg, CustomLogger::next, GNUNET_AsyncScopeSave::scope_id, and skip_log.
Referenced by flush_bulk(), and mylog().
|
static |
Flush an existing bulk report to the output.
datestr | our current timestamp |
Definition at line 916 of file common_logging.c.
References _, GNUNET_TIME_Absolute::abs_value_us, BULK_TRACK_SIZE, DATE_STR_SIZE, GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_get_duration(), GNUNET_YES, last_bulk_comp, last_bulk_kind, last_bulk_repeat, last_bulk_time, msg, and output_message().
Referenced by mylog().
|
static |
Output a log message using the default mechanism.
kind | how severe was the issue |
comp | component responsible |
message | the actual message |
va | arguments to the format string "message" |
Definition at line 995 of file common_logging.c.
References GNUNET_TIME_Absolute::abs_value_us, BULK_DELAY_THRESHOLD, BULK_REPEAT_THRESHOLD, DATE_STR_SIZE, flush_bulk(), GNUNET_assert, GNUNET_ERROR_TYPE_BULK, GNUNET_strlcpy(), GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_get_duration(), GNUNET_TIME_get_offset(), last_bulk_comp, last_bulk_kind, last_bulk_repeat, last_bulk_time, output_message(), GNUNET_TIME_Relative::rel_value_us, setup_log_file(), and size.
Referenced by GNUNET_log_from_nocheck(), and GNUNET_log_nocheck().
void GNUNET_log_nocheck | ( | enum GNUNET_ErrorType | kind, |
const char * | message, | ||
... | |||
) |
Main log function.
kind | how serious is the error? |
message | what is the message (format string) |
... | arguments for format string |
Definition at line 1093 of file common_logging.c.
References component, and mylog().
void GNUNET_log_from_nocheck | ( | enum GNUNET_ErrorType | kind, |
const char * | comp, | ||
const char * | message, | ||
... | |||
) |
Log function that specifies an alternative component.
This function should be used by plugins.
kind | how serious is the error? |
comp | component responsible for generating the message |
message | what is the message (format string) |
... | arguments for format string |
Definition at line 1113 of file common_logging.c.
References component_nopid, GNUNET_snprintf(), and mylog().
void GNUNET_util_cl_init | ( | void | ) |
void __attribute__ | ( | (constructor) | ) |
void GNUNET_util_cl_fini | ( | void | ) |
void __attribute__ | ( | (destructor) | ) |
|
static |
Asynchronous scope of the current thread, or NULL if we have not entered an async scope yet.
Definition at line 102 of file common_logging.c.
Referenced by GNUNET_async_scope_enter(), GNUNET_async_scope_get(), GNUNET_async_scope_restore(), and output_message().
|
static |
The last "bulk" error message that we have been logging.
Note that this message maybe truncated to the first BULK_TRACK_SIZE characters, in which case it is NOT 0-terminated!
Definition at line 109 of file common_logging.c.
|
static |
Type of the last bulk message.
Definition at line 114 of file common_logging.c.
Referenced by flush_bulk(), and mylog().
|
static |
Time of the last bulk error message (0 for none)
Definition at line 119 of file common_logging.c.
Referenced by flush_bulk(), and mylog().
|
static |
Number of times that bulk message has been repeated since.
Definition at line 124 of file common_logging.c.
Referenced by flush_bulk(), and mylog().
|
static |
Component when the last bulk was logged.
Will be 0-terminated.
Definition at line 129 of file common_logging.c.
Referenced by flush_bulk(), and mylog().
|
static |
Running component.
Definition at line 134 of file common_logging.c.
Referenced by GNUNET_log_nocheck(), and GNUNET_log_setup().
|
static |
Running component (without pid).
Definition at line 139 of file common_logging.c.
Referenced by GNUNET_get_log_call_status(), GNUNET_log_from_nocheck(), and GNUNET_log_setup().
|
static |
Format string describing the name of the log file.
Definition at line 144 of file common_logging.c.
Referenced by GNUNET_log_setup(), and setup_log_file().
|
static |
Minimum log level.
Definition at line 149 of file common_logging.c.
Referenced by GNUNET_get_log_call_status(), and GNUNET_log_setup().
|
static |
Linked list of our custom loggres.
Definition at line 154 of file common_logging.c.
Referenced by GNUNET_logger_add(), GNUNET_logger_remove(), and output_message().
|
static |
Number of log calls to ignore.
Definition at line 159 of file common_logging.c.
Referenced by GNUNET_get_log_skip(), GNUNET_log_skip(), and output_message().
|
static |
File descriptor to use for "stderr", or NULL for none.
Definition at line 164 of file common_logging.c.
Referenced by __attribute__(), output_message(), and setup_log_file().
|
static |
Dynamic array of logging definitions.
Definition at line 217 of file common_logging.c.
Referenced by add_definition(), GNUNET_get_log_call_status(), and resize_logdefs().
|
static |
Allocated size of logdefs array (in units)
Definition at line 222 of file common_logging.c.
Referenced by add_definition(), and resize_logdefs().
|
static |
The number of units used in logdefs array.
Definition at line 227 of file common_logging.c.
Referenced by add_definition(), and GNUNET_get_log_call_status().
|
static |
GNUNET_YES if GNUNET_LOG environment variable is already parsed.
Definition at line 232 of file common_logging.c.
Referenced by parse_all_definitions().
|
static |
GNUNET_YES if GNUNET_FORCE_LOG environment variable is already parsed.
Definition at line 237 of file common_logging.c.
Referenced by parse_all_definitions().
|
static |
GNUNET_YES if at least one definition with forced == 1 is available.
Definition at line 242 of file common_logging.c.
Referenced by GNUNET_get_log_call_status(), and parse_all_definitions().