Logging utility. More...
#include <stdio.h>#include <stdlib.h>#include <ctype.h>#include <string.h>#include <stdarg.h>#include <errno.h>#include <time.h>#include <yaz/thread_id.h>#include <yaz/log.h>#include <yaz/snprintf.h>#include <yaz/xmalloc.h>Go to the source code of this file.
Defines | |
| #define | TIMEFORMAT_LEN 50 |
| #define | TID_LEN 30 |
| #define | MAX_MASK_NAMES 35 |
Enumerations | |
| enum | l_file_type { use_stderr, use_none, use_file } |
Functions | |
| static void | internal_log_init (void) |
| FILE * | yaz_log_file (void) |
| returns FILE handle for log or NULL if no file is in use | |
| void | yaz_log_close (void) |
| void | yaz_log_init_file (const char *fname) |
| sets log file | |
| static void | rotate_log (const char *cur_fname) |
| void | yaz_log_init_level (int level) |
| sets log level | |
| void | yaz_log_init_prefix (const char *prefix) |
| sets log message prefix | |
| void | yaz_log_init_prefix2 (const char *prefix) |
| sets second log message prefix | |
| void | yaz_log_init (int level, const char *prefix, const char *fname) |
| sets level, prefix and filename for logging | |
| void | yaz_log_init_max_size (int mx) |
| sets limit in bytes for size for log file | |
| void | yaz_log_set_handler (void(*func)(int, const char *, void *), void *info) |
| sets custom log handler | |
| void | log_event_start (void(*func)(int, const char *, void *), void *info) |
| void | log_event_end (void(*func)(int, const char *, void *), void *info) |
| static void | yaz_log_open_check (struct tm *tm, int force, const char *filemode) |
| static void | yaz_log_do_reopen (const char *filemode) |
| void | yaz_log_reopen () |
| reopen current log file (unless disabled or stderr) | |
| void | yaz_log_trunc () |
| Truncate the log file. | |
| static void | yaz_strftime (char *dst, size_t sz, const char *fmt, const struct tm *tm) |
| static void | yaz_log_to_file (int level, const char *log_message) |
| void | yaz_log (int level, const char *fmt,...) |
| Writes log message. | |
| void | yaz_log_time_format (const char *fmt) |
| sets time format for log mesages | |
| static char * | clean_name (const char *name, size_t len, char *namebuf, size_t buflen) |
| static int | define_module_bit (const char *name) |
| int | yaz_log_module_level (const char *name) |
| returns level for module | |
| int | yaz_log_mask_str (const char *str) |
| converts log level string to log level (integer) | |
| int | yaz_log_mask_str_x (const char *str, int level) |
| converts log level string to log level with "start" level | |
Variables | |
| static int | l_level = YLOG_DEFAULT_LEVEL |
| static enum l_file_type | yaz_file_type = use_stderr |
| static FILE * | yaz_global_log_file = NULL |
| static void(* | start_hook_func )(int, const char *, void *) = NULL |
| static void * | start_hook_info |
| static void(* | end_hook_func )(int, const char *, void *) = NULL |
| static void * | end_hook_info |
| static void(* | hook_func )(int, const char *, void *) = NULL |
| static void * | hook_info |
| static char | l_prefix [512] = "" |
| static char | l_prefix2 [512] = "" |
| static char | l_fname [512] = "" |
| static char | l_old_default_format [] = "%H:%M:%S-%d/%m" |
| static char | l_new_default_format [] = "%Y%m%d-%H%M%S" |
| static char | l_custom_format [TIMEFORMAT_LEN] = "" |
| static char * | l_actual_format = l_old_default_format |
| static int | l_max_size = 0 |
| struct { | |
| int mask | |
| char * name | |
| } | mask_names [MAX_MASK_NAMES] |
| static unsigned int | next_log_bit = YLOG_LAST_BIT<<1 |
Logging utility.
Definition in file log.c.
| #define MAX_MASK_NAMES 35 |
Definition at line 72 of file log.c.
Referenced by define_module_bit().
| #define TID_LEN 30 |
Definition at line 59 of file log.c.
Referenced by yaz_log_to_file().
| #define TIMEFORMAT_LEN 50 |
Definition at line 58 of file log.c.
Referenced by yaz_log_time_format(), and yaz_log_to_file().
| enum l_file_type |
| static char* clean_name | ( | const char * | name, | |
| size_t | len, | |||
| char * | namebuf, | |||
| size_t | buflen | |||
| ) | [static] |
cleans a loglevel name from leading paths and suffixes
Definition at line 492 of file log.c.
Referenced by yaz_log_mask_str_x(), and yaz_log_module_level().
| static int define_module_bit | ( | const char * | name | ) | [static] |
Definition at line 507 of file log.c.
References mask_names, MAX_MASK_NAMES, next_log_bit, yaz_log(), and YLOG_WARN.
Referenced by yaz_log_mask_str_x().
| static void internal_log_init | ( | void | ) | [static] |
Definition at line 99 of file log.c.
References l_level, and yaz_log_mask_str_x().
Referenced by yaz_log(), yaz_log_init(), yaz_log_init_file(), yaz_log_init_level(), yaz_log_mask_str(), yaz_log_mask_str_x(), yaz_log_module_level(), and yaz_log_to_file().
| void log_event_end | ( | void(*)(int, const char *, void *) | func, | |
| void * | info | |||
| ) |
Definition at line 275 of file log.c.
References end_hook_func, and end_hook_info.
| void log_event_start | ( | void(*)(int, const char *, void *) | func, | |
| void * | info | |||
| ) |
Definition at line 269 of file log.c.
References start_hook_func, and start_hook_info.
| static void rotate_log | ( | const char * | cur_fname | ) | [static] |
Definition at line 157 of file log.c.
References yaz_log_close(), and yaz_snprintf().
Referenced by yaz_log_open_check().
| void yaz_log | ( | int | level, | |
| const char * | fmt, | |||
| ... | ||||
| ) |
Writes log message.
| level | log level mask | |
| fmt | format string ala printf |
Writes an entry in the log. Defaults to stderr if not initialized or to a file with yaz_log_init_file(). The level must match the level set via yaz_log_init_level(), optionally defined via yaz_log_mask_str().
Definition at line 434 of file log.c.
References end_hook_func, end_hook_info, hook_func, hook_info, internal_log_init(), l_level, start_hook_func, start_hook_info, yaz_log_file(), yaz_log_to_file(), yaz_strerror(), yaz_vsnprintf(), and YLOG_ERRNO.
Referenced by add_listener(), addterms(), assoc_init_reset(), build_facet_response(), ccl_qual_field(), check_ip_tcpd(), check_slow(), completeBER(), completeBER_n(), config_include_one(), control_association(), cql2pqf(), cql_transform_parse_tok_line(), create_association(), define_module_bit(), diagrec(), do_close_req(), do_connect_host(), do_read(), do_write_ex(), encode_APDU(), free_block(), get_block(), get_zoom_facet_field(), gfs_server_chdir(), handle_facet_result(), handle_http(), handle_records(), handle_srw_response(), inetd_connection(), init_diagnostics(), iochan_event_loop(), ir_read(), ir_session(), limitattr(), listener(), log_scan_term_level(), new_session(), nmem_malloc(), nmem_reset(), odr_createmem(), odr_destroy(), odr_reset(), pack_records(), process_close(), process_deleteRequest(), process_ESRequest(), process_gdu_response(), process_http_request(), process_initRequest(), process_presentRequest(), process_scanRequest(), process_searchRequest(), process_sortRequest(), process_z_request(), read_file(), read_grs1(), readconf(), recv_apdu(), response_searchRequest(), resultset_destroy(), send_APDU(), send_package(), send_present(), set_dset_error(), srw_bend_explain(), srw_bend_init(), srw_bend_scan(), srw_bend_search(), srw_bend_update(), statserv_sc_main(), statserv_setcontrol(), surrogatediagrec(), useattr(), xcalloc_f(), xfree_f(), xmalloc_f(), xml_config_bend_start(), xml_config_bend_stop(), xml_config_get_root(), xml_config_open(), xml_config_read(), xml_error_handler(), xrealloc_f(), xstrdup_f(), yaz_check_print1(), yaz_daemon(), yaz_facet_attr_get_z_attributes(), yaz_log_init_level(), yaz_log_module_level(), yaz_log_zquery_level(), yaz_mutex_enter(), yaz_mutex_leave(), yaz_sc_program(), z_External(), zlog_attributes(), zlog_structure(), ZOOM_connection_connect(), ZOOM_connection_create(), ZOOM_connection_destroy(), ZOOM_connection_do_io(), ZOOM_connection_exec_task(), ZOOM_connection_search(), ZOOM_connection_send_scan(), ZOOM_connection_send_search(), ZOOM_connection_show_task(), ZOOM_connection_show_tasks(), ZOOM_Event_create(), ZOOM_event_nonblock(), ZOOM_query_cql(), ZOOM_query_cql2rpn(), ZOOM_query_create(), ZOOM_query_destroy(), ZOOM_query_prefix(), ZOOM_query_sortby(), ZOOM_record_clone(), ZOOM_record_destroy(), ZOOM_resultset_addref(), ZOOM_resultset_create(), ZOOM_resultset_records(), ZOOM_resultset_retrieve(), ZOOM_resultset_size(), ZOOM_resultset_sort1(), zoom_yaz_str_to_z3950oid(), ztest_esrequest(), and ztest_search().
| void yaz_log_close | ( | void | ) |
Definition at line 126 of file log.c.
References use_file, yaz_file_type, and yaz_global_log_file.
Referenced by rotate_log(), yaz_log_init_file(), and yaz_log_open_check().
| static void yaz_log_do_reopen | ( | const char * | filemode | ) | [static] |
Definition at line 330 of file log.c.
References yaz_log_open_check().
Referenced by yaz_log_reopen(), and yaz_log_trunc().
| FILE* yaz_log_file | ( | void | ) |
returns FILE handle for log or NULL if no file is in use
| FILE | FILE handle in use (possibly stderr) | |
| NULL | log is currently not written to a file |
Definition at line 114 of file log.c.
References use_file, use_none, use_stderr, yaz_file_type, and yaz_global_log_file.
Referenced by cql_transform_parse_tok_line(), create_association(), do_read(), ir_read(), yaz_log(), yaz_log_to_file(), ZOOM_connection_connect(), and ztest_esrequest().
| void yaz_log_init | ( | int | level, | |
| const char * | prefix, | |||
| const char * | fname | |||
| ) |
sets level, prefix and filename for logging
| level | log level | |
| prefix | log message prefix | |
| fname | filename |
If fname is NULL, the filename logging is not changed.
Definition at line 246 of file log.c.
References internal_log_init(), yaz_log_init_file(), yaz_log_init_level(), and yaz_log_init_prefix().
| void yaz_log_init_file | ( | const char * | fname | ) |
sets log file
| fname | filename |
A filename of NULL makes the log to be completely disabled. A filename which is the empty string ("") makes the system log to stderr (which is also the default). Otherwise the filename given is used.
Definition at line 135 of file log.c.
References internal_log_init(), l_fname, use_file, use_none, use_stderr, yaz_file_type, yaz_log_close(), and yaz_log_reopen().
Referenced by check_options(), yaz_check_init_log(), and yaz_log_init().
| void yaz_log_init_level | ( | int | level | ) |
sets log level
| level | (combination of YLOG_..) |
Definition at line 195 of file log.c.
References internal_log_init(), l_level, mask, mask_names, name, yaz_log(), yaz_log_reopen(), YLOG_FLUSH, YLOG_LAST_BIT, and YLOG_LOGLVL.
Referenced by check_options(), and yaz_log_init().
| void yaz_log_init_max_size | ( | int | mx | ) |
sets limit in bytes for size for log file
| mx | size in bytes |
Sets the max size for a log file. Zero means no limit. Negative means built-in limit (1GB)
Definition at line 255 of file log.c.
References l_max_size.
Referenced by check_options().
| void yaz_log_init_prefix | ( | const char * | prefix | ) |
sets log message prefix
| prefix | log message prefix |
Definition at line 230 of file log.c.
References l_prefix, and yaz_snprintf().
Referenced by listener(), and yaz_log_init().
| void yaz_log_init_prefix2 | ( | const char * | prefix | ) |
sets second log message prefix
| prefix | log message prefix |
Definition at line 238 of file log.c.
References l_prefix2, and yaz_snprintf().
| int yaz_log_mask_str | ( | const char * | str | ) |
converts log level string to log level (integer)
| str | log level string |
yaz_log_mask_str() converts a comma-separated list of log levels to a bit mask. Starts from default level, and adds bits as specified, unless 'none' is specified, which clears the list. If a name matches the name of a YLOG_BIT above, that one is set. Otherwise a new value is picked, and given to that name, to be found with yaz_log_module_level()
Definition at line 550 of file log.c.
References internal_log_init(), l_level, and yaz_log_mask_str_x().
Referenced by check_options().
| int yaz_log_mask_str_x | ( | const char * | str, | |
| int | level | |||
| ) |
converts log level string to log level with "start" level
| str | log level string | |
| level | initialing log level |
yaz_log_mask_str_x() is like yaz_log_mask_str(), but with a given start value.
Definition at line 556 of file log.c.
References clean_name(), define_module_bit(), internal_log_init(), and mask.
Referenced by internal_log_init(), and yaz_log_mask_str().
| int yaz_log_module_level | ( | const char * | name | ) |
returns level for module
| name | module name |
yaz_log_module_level() returns a log level mask corresponding to the module name. If that had been specified on the -v arguments (that is passed to yaz_log_mask_str()), then a non-zero mask is returned. If not, we get a zero. This can later be used in yaz_log for the level argument
Definition at line 530 of file log.c.
References clean_name(), internal_log_init(), mask, mask_names, yaz_log(), and YLOG_LOGLVL.
Referenced by bend_init(), get_logbits(), initlog(), iochan_create(), nmem_create(), odr_createmem(), odr_reset(), xcalloc_f(), xmalloc_f(), xmalloc_trav_f(), xrealloc_f(), and xstrdup_f().
| static void yaz_log_open_check | ( | struct tm * | tm, | |
| int | force, | |||
| const char * | filemode | |||
| ) | [static] |
Definition at line 281 of file log.c.
References l_fname, l_level, l_max_size, rotate_log(), use_file, yaz_file_type, yaz_global_log_file, yaz_log_close(), and YLOG_FLUSH.
Referenced by yaz_log_do_reopen(), and yaz_log_to_file().
| void yaz_log_reopen | ( | void | ) |
reopen current log file (unless disabled or stderr)
Definition at line 348 of file log.c.
References yaz_log_do_reopen().
Referenced by yaz_log_init_file(), and yaz_log_init_level().
| void yaz_log_set_handler | ( | void(*)(int, const char *, void *) | func, | |
| void * | info | |||
| ) |
| void yaz_log_time_format | ( | const char * | fmt | ) |
sets time format for log mesages
| fmt | format (strftime) |
Sets the format of the timestamp. See man 3 strftime. Calling with "old" sets to the old format "11:55:06-02/11" Calling with NULL or "" sets to the new format "20041102-115719" If not called at all, the old format is used, for backward compatibility
Definition at line 473 of file log.c.
References l_actual_format, l_custom_format, l_new_default_format, l_old_default_format, and TIMEFORMAT_LEN.
Referenced by check_options().
| static void yaz_log_to_file | ( | int | level, | |
| const char * | log_message | |||
| ) | [static] |
Definition at line 364 of file log.c.
References internal_log_init(), l_actual_format, l_level, l_prefix, l_prefix2, mask, mask_names, name, TID_LEN, TIMEFORMAT_LEN, yaz_log_file(), yaz_log_open_check(), yaz_strftime(), yaz_thread_id_cstr(), YLOG_ALL, YLOG_FLUSH, YLOG_NOTIME, and YLOG_TID.
Referenced by yaz_log().
| void yaz_log_trunc | ( | void | ) |
Truncate the log file.
Definition at line 353 of file log.c.
References yaz_log_do_reopen().
Referenced by yaz_check_init_log().
| static void yaz_strftime | ( | char * | dst, | |
| size_t | sz, | |||
| const char * | fmt, | |||
| const struct tm * | tm | |||
| ) | [static] |
Definition at line 358 of file log.c.
Referenced by yaz_log_to_file().
void(* end_hook_func)(int, const char *, void *) = NULL [static] |
Definition at line 45 of file log.c.
Referenced by log_event_end(), and yaz_log().
void* end_hook_info [static] |
Definition at line 46 of file log.c.
Referenced by log_event_end(), and yaz_log().
void(* hook_func)(int, const char *, void *) = NULL [static] |
Definition at line 48 of file log.c.
Referenced by yaz_log(), and yaz_log_set_handler().
void* hook_info [static] |
Definition at line 49 of file log.c.
Referenced by yaz_log(), and yaz_log_set_handler().
char* l_actual_format = l_old_default_format [static] |
Definition at line 61 of file log.c.
Referenced by yaz_log_time_format(), and yaz_log_to_file().
char l_custom_format[TIMEFORMAT_LEN] = "" [static] |
Definition at line 60 of file log.c.
Referenced by yaz_log_time_format().
char l_fname[512] = "" [static] |
Definition at line 53 of file log.c.
Referenced by yaz_log_init_file(), and yaz_log_open_check().
int l_level = YLOG_DEFAULT_LEVEL [static] |
Definition at line 36 of file log.c.
Referenced by internal_log_init(), yaz_log(), yaz_log_init_level(), yaz_log_mask_str(), yaz_log_open_check(), and yaz_log_to_file().
int l_max_size = 0 [static] |
l_max_size tells when to rotate the log. The default value is 0 which means DISABLED. This is to be preffered if YAZ runs as a server using logrotate etc. A positive size specifies the file size in bytes when a log rotate will occur. Note that in order for this to work YAZ must have permissions to do so.
Definition at line 70 of file log.c.
Referenced by yaz_log_init_max_size(), and yaz_log_open_check().
char l_new_default_format[] = "%Y%m%d-%H%M%S" [static] |
Definition at line 57 of file log.c.
Referenced by yaz_log_time_format().
char l_old_default_format[] = "%H:%M:%S-%d/%m" [static] |
Definition at line 56 of file log.c.
Referenced by yaz_log_time_format().
char l_prefix[512] = "" [static] |
Definition at line 51 of file log.c.
Referenced by yaz_log_init_prefix(), and yaz_log_to_file().
char l_prefix2[512] = "" [static] |
Definition at line 52 of file log.c.
Referenced by yaz_log_init_prefix2(), and yaz_log_to_file().
| int mask |
Definition at line 74 of file log.c.
Referenced by do_connect_host(), do_write_ex(), new_session(), yaz_log_init_level(), yaz_log_mask_str_x(), yaz_log_module_level(), yaz_log_to_file(), yaz_poll_select(), and ZOOM_event_sys_yaz_poll().
struct { ... } mask_names[MAX_MASK_NAMES] [static] |
Referenced by define_module_bit(), yaz_log_init_level(), yaz_log_module_level(), and yaz_log_to_file().
unsigned int next_log_bit = YLOG_LAST_BIT<<1 [static] |
Definition at line 97 of file log.c.
Referenced by define_module_bit().
void(* start_hook_func)(int, const char *, void *) = NULL [static] |
Definition at line 42 of file log.c.
Referenced by log_event_start(), and yaz_log().
void* start_hook_info [static] |
Definition at line 43 of file log.c.
Referenced by log_event_start(), and yaz_log().
enum l_file_type yaz_file_type = use_stderr [static] |
Definition at line 39 of file log.c.
Referenced by yaz_log_close(), yaz_log_file(), yaz_log_init_file(), and yaz_log_open_check().
FILE* yaz_global_log_file = NULL [static] |
Definition at line 40 of file log.c.
Referenced by yaz_log_close(), yaz_log_file(), and yaz_log_open_check().
1.6.3