diff options
Diffstat (limited to 'src/shared/libosmocore/src/logging.c')
-rw-r--r-- | src/shared/libosmocore/src/logging.c | 98 |
1 files changed, 89 insertions, 9 deletions
diff --git a/src/shared/libosmocore/src/logging.c b/src/shared/libosmocore/src/logging.c index 11d63ac9..9dd63e73 100644 --- a/src/shared/libosmocore/src/logging.c +++ b/src/shared/libosmocore/src/logging.c @@ -20,6 +20,12 @@ * */ +/* \addtogroup logging + * @{ + */ + +/* \file logging.c */ + #include "../config.h" #include <stdarg.h> @@ -113,16 +119,22 @@ static int subsys_lib2index(int subsys) return (subsys * -1) + (osmo_log_info->num_cat_user-1); } +/*! \brief Parse a human-readable log level into a numeric value */ int log_parse_level(const char *lvl) { return get_string_value(loglevel_strs, lvl); } +/*! \brief convert a numeric log level into human-readable string */ const char *log_level_str(unsigned int lvl) { return get_value_string(loglevel_strs, lvl); } +/*! \brief parse a human-readable log category into numeric form + * \param[in] category human-readable log category name + * \returns numeric category value, or -EINVAL otherwise + */ int log_parse_category(const char *category) { int i; @@ -137,8 +149,10 @@ int log_parse_category(const char *category) return -EINVAL; } -/* - * Parse the category mask. +/*! \brief parse the log category mask + * \param[in] target log target to be configured + * \param[in] _mask log category mask string + * * The format can be this: category1:category2:category3 * or category1,2:category2,3:... */ @@ -157,6 +171,11 @@ void log_parse_category_mask(struct log_target* target, const char *_mask) for (i = 0; i < osmo_log_info->num_cat; ++i) { char* colon = strstr(category_token, ","); int length = strlen(category_token); + int cat_length = strlen(osmo_log_info->cat[i].name); + + /* Use longest length not to match subocurrences. */ + if (cat_length > length) + length = cat_length; if (!osmo_log_info->cat[i].name) continue; @@ -238,8 +257,9 @@ err: target->output(target, level, buf); } -static void _logp(int subsys, int level, char *file, int line, - int cont, const char *format, va_list ap) +/*! \brief vararg version of logging function */ +void osmo_vlogp(int subsys, int level, char *file, int line, + int cont, const char *format, va_list ap) { struct log_target *tar; @@ -294,7 +314,7 @@ void logp(int subsys, char *file, int line, int cont, va_list ap; va_start(ap, format); - _logp(subsys, LOGL_DEBUG, file, line, cont, format, ap); + osmo_vlogp(subsys, LOGL_DEBUG, file, line, cont, format, ap); va_end(ap); } @@ -303,25 +323,42 @@ void logp2(int subsys, unsigned int level, char *file, int line, int cont, const va_list ap; va_start(ap, format); - _logp(subsys, level, file, line, cont, format, ap); + osmo_vlogp(subsys, level, file, line, cont, format, ap); va_end(ap); } +/*! \brief Register a new log target with the logging core + * \param[in] target Log target to be registered + */ void log_add_target(struct log_target *target) { llist_add_tail(&target->entry, &osmo_log_target_list); } +/*! \brief Unregister a log target from the logging core + * \param[in] target Log target to be unregistered + */ void log_del_target(struct log_target *target) { llist_del(&target->entry); } +/*! \brief Reset (clear) the logging context */ void log_reset_context(void) { memset(&log_context, 0, sizeof(log_context)); } +/*! \brief Set the logging context + * \param[in] ctx_nr logging context number + * \param[in] value value to which the context is to be set + * + * A logging context is something like the subscriber identity to which + * the currently processed message relates, or the BTS through which it + * was received. As soon as this data is known, it can be set using + * this function. The main use of context information is for logging + * filters. + */ int log_set_context(uint8_t ctx_nr, void *value) { if (ctx_nr > LOG_MAX_CTX) @@ -332,6 +369,14 @@ int log_set_context(uint8_t ctx_nr, void *value) return 0; } +/*! \brief Enable the \ref LOG_FILTER_ALL log filter + * \param[in] target Log target to be affected + * \param[in] all enable (1) or disable (0) the ALL filter + * + * When the \ref LOG_FILTER_ALL filter is enabled, all log messages will + * be printed. It acts as a wildcard. Setting it to \a 1 means there + * is no filtering. + */ void log_set_all_filter(struct log_target *target, int all) { if (all) @@ -340,16 +385,28 @@ void log_set_all_filter(struct log_target *target, int all) target->filter_map &= ~LOG_FILTER_ALL; } +/*! \brief Enable or disable the use of colored output + * \param[in] target Log target to be affected + * \param[in] use_color Use color (1) or don't use color (0) + */ void log_set_use_color(struct log_target *target, int use_color) { target->use_color = use_color; } +/*! \brief Enable or disable printing of timestamps while logging + * \param[in] target Log target to be affected + * \param[in] print_timestamp Enable (1) or disable (0) timestamps + */ void log_set_print_timestamp(struct log_target *target, int print_timestamp) { target->print_timestamp = print_timestamp; } +/*! \brief Set the global log level for a given log target + * \param[in] target Log target to be affected + * \param[in] log_level New global log level + */ void log_set_log_level(struct log_target *target, int log_level) { target->loglevel = log_level; @@ -371,6 +428,7 @@ static void _file_output(struct log_target *target, unsigned int level, fflush(target->tgt_file.out); } +/*! \brief Create a new log target skeleton */ struct log_target *log_target_create(void) { struct log_target *target; @@ -406,6 +464,7 @@ struct log_target *log_target_create(void) return target; } +/*! \brief Create the STDERR log target */ struct log_target *log_target_create_stderr(void) { /* since C89/C99 says stderr is a macro, we can safely do this! */ @@ -425,6 +484,10 @@ struct log_target *log_target_create_stderr(void) #endif /* stderr */ } +/*! \brief Create a new file-based log target + * \param[in] fname File name of the new log file + * \returns Log target in case of success, NULL otherwise + */ struct log_target *log_target_create_file(const char *fname) { struct log_target *target; @@ -445,6 +508,11 @@ struct log_target *log_target_create_file(const char *fname) return target; } +/*! \brief Find a registered log target + * \param[in] type Log target type + * \param[in] fname File name + * \returns Log target (if found), NULL otherwise + */ struct log_target *log_target_find(int type, const char *fname) { struct log_target *tgt; @@ -461,6 +529,7 @@ struct log_target *log_target_find(int type, const char *fname) return NULL; } +/*! \brief Unregister, close and delete a log target */ void log_target_destroy(struct log_target *target) { @@ -482,7 +551,7 @@ void log_target_destroy(struct log_target *target) talloc_free(target); } -/* close and re-open a log file (for log file rotation) */ +/*! \brief close and re-open a log file (for log file rotation) */ int log_target_file_reopen(struct log_target *target) { fclose(target->tgt_file.out); @@ -496,7 +565,9 @@ int log_target_file_reopen(struct log_target *target) return 0; } -/* This generates the logging command string for VTY. */ +/*! \brief Generates the logging command string for VTY + * \param[in] unused_info Deprecated parameter, no longer used! + */ const char *log_vty_command_string(const struct log_info *unused_info) { struct log_info *info = osmo_log_info; @@ -571,7 +642,9 @@ err: return str; } -/* This generates the logging command description for VTY. */ +/*! \brief Generates the logging command description for VTY + * \param[in] unused_info Deprecated parameter, no longer used! + */ const char *log_vty_command_description(const struct log_info *unused_info) { struct log_info *info = osmo_log_info; @@ -629,6 +702,11 @@ err: return str; } +/*! \brief Initialize the Osmocom logging core + * \param[in] inf Information regarding logging categories + * \param[in] ctx \ref talloc context for logging allocations + * \returns 0 in case of success, negative in case of error + */ int log_init(const struct log_info *inf, void *ctx) { int i; @@ -669,3 +747,5 @@ int log_init(const struct log_info *inf, void *ctx) return 0; } + +/*! }@ */ |