![]() |
GNUnet
0.11.x
|
error handling API More...
#include "platform.h"
#include "gnunet_crypto_lib.h"
#include "gnunet_disk_lib.h"
#include "gnunet_strings_lib.h"
#include <regex.h>
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 GNUNET_GE_KIND. 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... | |
static int | setup_log_file (const struct tm *tm) |
Setup the log file. More... | |
static int | add_definition (const char *component, 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... | |
int | 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... | |
void | __attribute__ ((constructor)) |
Initializer. More... | |
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 37 of file common_logging.c.
Referenced by mylog().
#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 44 of file common_logging.c.
Referenced by mylog().
#define BULK_TRACK_SIZE 256 |
How many characters do we use for matching of bulk messages?
Definition at line 50 of file common_logging.c.
Referenced by flush_bulk().
#define COMP_TRACK_SIZE 32 |
How many characters do we use for matching of bulk components?
Definition at line 56 of file common_logging.c.
#define DATE_STR_SIZE 64 |
How many characters can a date/time string be at most?
Definition at line 62 of file common_logging.c.
Referenced by flush_bulk(), and mylog().
#define ROTATION_KEEP 3 |
How many log files to keep?
Definition at line 67 of file common_logging.c.
Referenced by log_rotate().
#define PATH_MAX 4096 |
Assumed maximum path length (for the log file name).
Definition at line 73 of file common_logging.c.
Referenced by setup_log_file().
#define LEN |
Referenced by GNUNET_a2s().
|
static |
Convert a textual description of a loglevel to the respective GNUNET_GE_KIND.
log | loglevel to parse |
Definition at line 255 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 290 of file common_logging.c.
References GNUNET_realloc, 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 303 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 331 of file common_logging.c.
References fn, 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 418 of file common_logging.c.
References LogDef::component_regex, LogDef::file_regex, LogDef::force, LogDef::from_line, LogDef::function_regex, LogDef::level, logdefs_len, logdefs_size, resize_logdefs(), and LogDef::to_line.
Referenced by parse_definitions().
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.
Used internally by GNUNET_log*()
caller_level | loglevel the caller wants to use |
comp | component name the caller uses (NULL means that global component name is used) |
file | file name containing the logging call, usually FILE |
function | function which tries to make a logging call, usually FUNCTION |
line | line at which the call is made, usually LINE |
Definition at line 479 of file common_logging.c.
References component_nopid, LogDef::component_regex, LogDef::file_regex, LogDef::force, LogDef::from_line, LogDef::function_regex, GNUNET_ERROR_TYPE_MESSAGE, gnunet_force_log_present, GNUNET_NO, LogDef::level, logdefs_len, min_level, and LogDef::to_line.
Referenced by GCC_debug(), GCCH_debug(), GCT_debug(), and get_nick_record().
|
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 549 of file common_logging.c.
References _, add_definition(), 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 683 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 809 of file common_logging.c.
References current_async_scope, end, 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, 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 878 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 963 of file common_logging.c.
References GNUNET_TIME_Absolute::abs_value_us, buf, 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 1058 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 1078 of file common_logging.c.
References component_nopid, GNUNET_snprintf(), and mylog().
void GNUNET_async_scope_enter | ( | const struct GNUNET_AsyncScopeId * | aid, |
struct GNUNET_AsyncScopeSave * | old_scope | ||
) |
Set the async scope for the current thread.
aid | the async scope identifier |
old_scope[out] | location to save the old scope |
Definition at line 1499 of file common_logging.c.
References current_async_scope, GNUNET_YES, GNUNET_AsyncScopeSave::have_scope, and GNUNET_AsyncScopeSave::scope_id.
Referenced by GNUNET_SCHEDULER_begin_async_scope(), and GNUNET_SCHEDULER_do_work().
void GNUNET_async_scope_restore | ( | struct GNUNET_AsyncScopeSave * | old_scope | ) |
Clear the current thread's async scope.
old_scope | scope to restore |
Definition at line 1514 of file common_logging.c.
References current_async_scope.
Referenced by GNUNET_SCHEDULER_do_work().
void GNUNET_async_scope_fresh | ( | struct GNUNET_AsyncScopeId * | aid_ret | ) |
Generate a fresh async scope identifier.
[out] | aid_ret | pointer to where the result is stored |
Definition at line 1526 of file common_logging.c.
References GNUNET_CRYPTO_QUALITY_WEAK, and GNUNET_CRYPTO_random_block().
void GNUNET_async_scope_get | ( | struct GNUNET_AsyncScopeSave * | scope_ret | ) |
Get the current async scope.
[out] | scope_ret | pointer to where the result is stored |
Definition at line 1540 of file common_logging.c.
References current_async_scope.
Referenced by add_without_sets(), GNUNET_SCHEDULER_add_at_with_priority(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_select(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_do_work(), and setup_job_headers().
void __attribute__ | ( | (constructor) | ) |
Initializer.
Definition at line 1549 of file common_logging.c.
References GNUNET_stderr.
void __attribute__ | ( | (destructor) | ) |
|
static |
Asynchronous scope of the current thread, or NULL if we have not entered an async scope yet.
Definition at line 103 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 110 of file common_logging.c.
|
static |
Type of the last bulk message.
Definition at line 115 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 120 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 125 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 130 of file common_logging.c.
Referenced by flush_bulk(), and mylog().
|
static |
Running component.
Definition at line 135 of file common_logging.c.
Referenced by GNUNET_log_nocheck(), and GNUNET_log_setup().
|
static |
Running component (without pid).
Definition at line 140 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 145 of file common_logging.c.
Referenced by GNUNET_log_setup(), and setup_log_file().
|
static |
Minimum log level.
Definition at line 150 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 155 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 160 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 165 of file common_logging.c.
Referenced by __attribute__(), output_message(), and setup_log_file().
|
static |
Dynamic array of logging definitions.
Definition at line 218 of file common_logging.c.
|
static |
Allocated size of logdefs array (in units)
Definition at line 223 of file common_logging.c.
Referenced by add_definition(), and resize_logdefs().
|
static |
The number of units used in logdefs array.
Definition at line 228 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 233 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 238 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 243 of file common_logging.c.
Referenced by GNUNET_get_log_call_status(), and parse_all_definitions().