YAZ  5.34.0
Macros | Functions
log.h File Reference

Logging utility. More...

#include <stdio.h>
#include <yaz/yconfig.h>

Go to the source code of this file.

Macros

#define YLOG_FATAL   0x00000001
 log level: fatal More...
 
#define YLOG_DEBUG   0x00000002
 log level: debugging More...
 
#define YLOG_WARN   0x00000004
 log level: warning More...
 
#define YLOG_LOG   0x00000008
 log level: log (regular) More...
 
#define YLOG_ERRNO   0x00000010
 log level: append system error message More...
 
#define YLOG_TID   0x00000020
 log level: append thread Id More...
 
#define YLOG_APP   0x00000040
 log level: application More...
 
#define YLOG_MALLOC   0x00000080
 log level: malloc debug More...
 
#define YLOG_NOTIME   0x00000100
 log level: do not output date and time More...
 
#define YLOG_APP2   0x00000200
 log level: application 2 More...
 
#define YLOG_APP3   0x00000400
 log level: application 3 More...
 
#define YLOG_FLUSH   0x00000800
 log level: flush More...
 
#define YLOG_LOGLVL   0x00001000 /* log when modules query log levels */
 dynamic log level start More...
 
#define YLOG_ALL   (0xffff&~YLOG_MALLOC&~YLOG_NOTIME)
 
#define YLOG_DEFAULT_LEVEL    (YLOG_FATAL | YLOG_ERRNO | YLOG_LOG | YLOG_WARN | YLOG_FLUSH)
 default log level More...
 
#define YLOG_LAST_BIT   YLOG_LOGLVL
 last bit for regular log bits . Rest are dynamic More...
 

Functions

void yaz_log_init (int level, const char *prefix, const char *fname)
 sets level, prefix and filename for logging More...
 
void yaz_log_init_file (const char *fname)
 sets log file More...
 
void yaz_log_init_level (int level)
 sets log level More...
 
void yaz_log_init_prefix (const char *prefix)
 sets log message prefix More...
 
void yaz_log_init_prefix2 (const char *prefix)
 sets second log message prefix More...
 
void yaz_log_time_format (const char *fmt)
 sets time format for log mesages More...
 
void yaz_log_init_max_size (int mx)
 sets limit in bytes for size for log file More...
 
void yaz_log (int level, const char *fmt,...)
 Writes log message. More...
 
int yaz_log_mask_str (const char *str)
 converts log level string to log level (integer) More...
 
int yaz_log_mask_str_x (const char *str, int level)
 converts log level string to log level with "start" level More...
 
int yaz_log_module_level (const char *name)
 returns level for module More...
 
FILE * yaz_log_file (void)
 returns FILE handle for log or NULL if no file is in use More...
 
void yaz_log_set_handler (void(*func)(int, const char *, void *), void *info)
 sets custom log handler More...
 
void yaz_log_reopen (void)
 reopen current log file (unless disabled or stderr) More...
 
void yaz_log_trunc (void)
 Truncate the log file. More...
 
void log_event_start (void(*func)(int level, const char *msg, void *info), void *info)
 installs hook to be called before each log msg More...
 
void log_event_end (void(*func)(int level, const char *msg, void *info), void *info)
 installs hook to be called after each log msg More...
 
void yaz_log_xml_errors (const char *prefix, int log_level)
 Makes Libxml2 and Libxslt log errors through yaz_log. More...
 
void yaz_log_lock (void)
 Lock for YAZ log writes. More...
 
void yaz_log_unlock (void)
 Unlock for YAZ log writes. More...
 

Detailed Description

Logging utility.

Definition in file log.h.

Macro Definition Documentation

◆ YLOG_ALL

#define YLOG_ALL   (0xffff&~YLOG_MALLOC&~YLOG_NOTIME)

Definition at line 69 of file log.h.

◆ YLOG_APP

#define YLOG_APP   0x00000040

log level: application

Definition at line 54 of file log.h.

◆ YLOG_APP2

#define YLOG_APP2   0x00000200

log level: application 2

Definition at line 60 of file log.h.

◆ YLOG_APP3

#define YLOG_APP3   0x00000400

log level: application 3

Definition at line 62 of file log.h.

◆ YLOG_DEBUG

#define YLOG_DEBUG   0x00000002

log level: debugging

Definition at line 44 of file log.h.

◆ YLOG_DEFAULT_LEVEL

#define YLOG_DEFAULT_LEVEL    (YLOG_FATAL | YLOG_ERRNO | YLOG_LOG | YLOG_WARN | YLOG_FLUSH)

default log level

Definition at line 72 of file log.h.

◆ YLOG_ERRNO

#define YLOG_ERRNO   0x00000010

log level: append system error message

Definition at line 50 of file log.h.

◆ YLOG_FATAL

#define YLOG_FATAL   0x00000001

log level: fatal

Definition at line 42 of file log.h.

◆ YLOG_FLUSH

#define YLOG_FLUSH   0x00000800

log level: flush

Definition at line 64 of file log.h.

◆ YLOG_LAST_BIT

#define YLOG_LAST_BIT   YLOG_LOGLVL

last bit for regular log bits . Rest are dynamic

Definition at line 78 of file log.h.

◆ YLOG_LOG

#define YLOG_LOG   0x00000008

log level: log (regular)

Definition at line 48 of file log.h.

◆ YLOG_LOGLVL

#define YLOG_LOGLVL   0x00001000 /* log when modules query log levels */

dynamic log level start

Definition at line 66 of file log.h.

◆ YLOG_MALLOC

#define YLOG_MALLOC   0x00000080

log level: malloc debug

Definition at line 56 of file log.h.

◆ YLOG_NOTIME

#define YLOG_NOTIME   0x00000100

log level: do not output date and time

Definition at line 58 of file log.h.

◆ YLOG_TID

#define YLOG_TID   0x00000020

log level: append thread Id

Definition at line 52 of file log.h.

◆ YLOG_WARN

#define YLOG_WARN   0x00000004

log level: warning

Definition at line 46 of file log.h.

Function Documentation

◆ log_event_end()

void log_event_end ( void(*)(int level, const char *msg, void *info)  func,
void *  info 
)

installs hook to be called after each log msg

Parameters
funcfunction to be called
infouser data to be passed to function

◆ log_event_start()

void log_event_start ( void(*)(int level, const char *msg, void *info)  func,
void *  info 
)

installs hook to be called before each log msg

Parameters
funcfunction to be called
infouser data to be passed to function

◆ yaz_log()

void yaz_log ( int  level,
const char *  fmt,
  ... 
)

Writes log message.

Parameters
levellog level mask
fmtformat 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 487 of file log.c.

References end_hook_func, end_hook_info, hook_func, hook_info, l_level, start_hook_func, start_hook_info, yaz_init_globals(), 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(), construct_rdf_lookup(), cont_connect(), control_association(), convert_rdf_lookup(), cql2pqf(), cql_transform_parse_tok_line(), create_association(), create_net_socket(), define_module_bit(), destroy_rdf_lookup(), diagrec(), do_close_req(), do_read(), do_write_ex(), encode_APDU(), free_block(), get_block(), get_zoom_facet_field(), gfs_server_chdir(), handle_http(), handle_srw_response(), handle_Z3950_records(), inetd_connection(), init_diagnostics(), iochan_event_loop(), ir_read(), ir_session(), listener(), log_scan_term_level(), log_warn(), 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(), rdf_lookup_debug_comment(), rdf_lookup_node(), read_file(), read_grs1(), readconf(), response_searchRequest(), resultset_destroy(), send_APDU(), send_package(), send_Z3950_sort(), srw_bend_explain(), srw_bend_init(), srw_bend_scan(), srw_bend_search(), srw_bend_update(), statserv_sc_main(), statserv_setcontrol(), surrogatediagrec(), tcpip_accept(), tcpip_bind(), tcpip_close(), tcpip_connect(), tcpip_get(), tcpip_listen(), tcpip_put(), tcpip_rcvconnect(), tcpip_type(), unix_accept(), unix_bind(), unix_close(), unix_connect(), unix_get(), unix_listen(), unix_put(), unix_rcvconnect(), unix_straddr1(), unix_strtoaddr(), unix_strtoaddr_ex(), unix_type(), 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(), yaz_sru_proxy_decode_facet_field(), Z3950_send_present(), Z3950_send_search(), 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_show_task(), ZOOM_connection_show_tasks(), ZOOM_connection_Z3950_search(), ZOOM_connection_Z3950_send_scan(), ZOOM_event_nonblock(), ZOOM_handle_facet_list(), ZOOM_handle_Z3950_apdu(), ZOOM_memcached_add(), ZOOM_memcached_hitcount(), ZOOM_memcached_lookup(), ZOOM_memcached_search(), ZOOM_resultset_addref(), ZOOM_resultset_create(), ZOOM_resultset_records(), ZOOM_resultset_retrieve(), ZOOM_resultset_sort1(), ZOOM_set_dset_error(), zoom_yaz_str_to_z3950oid(), ztest_esrequest(), and ztest_search().

◆ yaz_log_file()

FILE* yaz_log_file ( void  )

returns FILE handle for log or NULL if no file is in use

Return values
FILEFILE handle in use (possibly stderr)
NULLlog is currently not written to a file

Definition at line 138 of file log.c.

References use_file, use_none, use_stderr, and yaz_log_info.

Referenced by cql_transform_parse_tok_line(), create_association(), do_read(), ir_read(), yaz_daemon(), yaz_log(), yaz_log_to_file(), ZOOM_connection_connect(), and ztest_esrequest().

◆ yaz_log_init()

void yaz_log_init ( int  level,
const char *  prefix,
const char *  fname 
)

sets level, prefix and filename for logging

Parameters
levellog level
prefixlog message prefix
fnamefilename

If fname is NULL, the filename logging is not changed.

Definition at line 281 of file log.c.

References yaz_init_globals(), yaz_log_init_file(), yaz_log_init_level(), and yaz_log_init_prefix().

◆ yaz_log_init_file()

void yaz_log_init_file ( const char *  fname)

sets log file

Parameters
fnamefilename

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 168 of file log.c.

References use_file, use_none, use_stderr, yaz_init_globals(), yaz_log_close(), yaz_log_info, and yaz_log_open().

Referenced by check_options(), yaz_check_init_log(), and yaz_log_init().

◆ yaz_log_init_level()

void yaz_log_init_level ( int  level)

sets log level

Parameters
level(combination of YLOG_..)

Definition at line 228 of file log.c.

References l_level, mask, mask_names, name, yaz_init_globals(), yaz_log(), yaz_log_open(), YLOG_FLUSH, YLOG_LAST_BIT, and YLOG_LOGLVL.

Referenced by check_options(), and yaz_log_init().

◆ yaz_log_init_max_size()

void yaz_log_init_max_size ( int  mx)

sets limit in bytes for size for log file

Parameters
mxsize in bytes

Sets the max size for a log file. Zero means no limit. Negative means built-in limit (1GB)

Definition at line 290 of file log.c.

References l_max_size.

Referenced by check_options().

◆ yaz_log_init_prefix()

void yaz_log_init_prefix ( const char *  prefix)

sets log message prefix

Parameters
prefixlog message prefix

Definition at line 263 of file log.c.

References yaz_log_info, and yaz_snprintf().

Referenced by listener(), and yaz_log_init().

◆ yaz_log_init_prefix2()

void yaz_log_init_prefix2 ( const char *  prefix)

sets second log message prefix

Parameters
prefixlog message prefix

Definition at line 272 of file log.c.

References yaz_log_info, and yaz_snprintf().

◆ yaz_log_lock()

void yaz_log_lock ( void  )

Lock for YAZ log writes.

Definition at line 114 of file log.c.

References log_mutex, and yaz_mutex_enter().

Referenced by yaz_log_do_reopen(), yaz_log_init_globals(), and yaz_log_to_file().

◆ yaz_log_mask_str()

int yaz_log_mask_str ( const char *  str)

converts log level string to log level (integer)

Parameters
strlog level string
Returns
log level mask

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 606 of file log.c.

References l_level, yaz_init_globals(), and yaz_log_mask_str_x().

Referenced by check_options().

◆ yaz_log_mask_str_x()

int yaz_log_mask_str_x ( const char *  str,
int  level 
)

converts log level string to log level with "start" level

Parameters
strlog level string
levelinitialing log level
Returns
log level mask

yaz_log_mask_str_x() is like yaz_log_mask_str(), but with a given start value.

Definition at line 614 of file log.c.

Referenced by yaz_log_init_globals(), and yaz_log_mask_str().

◆ yaz_log_module_level()

int yaz_log_module_level ( const char *  name)

returns level for module

Parameters
namemodule name
Returns
log level for module

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 586 of file log.c.

References clean_name(), mask, mask_names, name, yaz_init_globals(), yaz_log(), and YLOG_LOGLVL.

Referenced by bend_init(), get_logbits(), initlog(), iochan_create(), nmem_create(), odr_createmem(), odr_reset(), tcpip_init(), unix_init(), xcalloc_f(), xmalloc_f(), xmalloc_trav_f(), xrealloc_f(), and xstrdup_f().

◆ yaz_log_reopen()

void yaz_log_reopen ( void  )

reopen current log file (unless disabled or stderr)

Definition at line 391 of file log.c.

References yaz_log_reopen_flag.

◆ yaz_log_set_handler()

void yaz_log_set_handler ( void(*)(int, const char *, void *)  func,
void *  info 
)

sets custom log handler

Parameters
funccustom log handler
infocustom pointer to be passed to func handler

Allows log output to be captured to something else.. The func parameter takes a log level, a message + custom pointer

Definition at line 298 of file log.c.

References hook_func, and hook_info.

◆ yaz_log_time_format()

void yaz_log_time_format ( const char *  fmt)

sets time format for log mesages

Parameters
fmtformat (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 529 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().

◆ yaz_log_trunc()

void yaz_log_trunc ( void  )

Truncate the log file.

Definition at line 401 of file log.c.

References yaz_log_do_reopen().

Referenced by yaz_check_init_log().

◆ yaz_log_unlock()

void yaz_log_unlock ( void  )

Unlock for YAZ log writes.

Definition at line 119 of file log.c.

References log_mutex, and yaz_mutex_leave().

Referenced by yaz_log_do_reopen(), yaz_log_init_globals(), and yaz_log_to_file().

◆ yaz_log_xml_errors()

void yaz_log_xml_errors ( const char *  prefix,
int  log_level 
)

Makes Libxml2 and Libxslt log errors through yaz_log.

Parameters
prefixprefix to use for log messages (may be 0)
log_levellog level to use for Libxml2/Libxslt messages

Definition at line 47 of file xmlerror.c.

References log_level, xml_error_handler(), and xml_error_log_level.

Referenced by new_session().