|QBLOG.H(3)||libqb Programmer's Manual||QBLOG.H(3)|
qblog.h - The logging API provides four main parts (basics, filtering, threading & blackbox).
The idea behind this logging system is not to be prescriptive but to provide a set of tools to help the developer achieve what they want quickly and easily.
Simplest possible use:
To enable a target do the following:
syslog, stderr, the blackbox, and stdout are static (they don't need to be created, just enabled or disabled). However, you can open multiple logfiles (falling within inclusive range up to ). To do this, use the following code:
Once your targets are enabled/opened, you can configure them as follows: Configure the size of blackbox:
Make logging to file threaded:
Sometimes, syslog daemons are (pre)configured to filter messages not exceeding a particular priority. When this happens to be the logging target, the designated priority of the message is passed along unchanged, possibly resulting in message loss. For messages up to importance, this can be worked around by proportionally bumping the priorities to be passed to syslog (here, the step is such that gets promoted to ):
To ensure all logs to file targets are fsync'ed (new messages expressly transferred to the storage device as they keep coming, otherwise defaults to ):
So to make all logs from evil_function() go to stderr, do the following:
So to make all logs from totem* (with a priority <= LOG_INFO) go to stderr, do the following:
So to make all logs with the substring "ringbuffer" go to stderr, do the following:
To achieve non-blocking logging, so that any calls to write() or syslog() will not hold up your program, you can use threaded logging as well.
Threaded logging use:
The code above will produce:
the blackbox is not enabled by default.
qb_log_filter_fn_set(3), qb_log_thread_start(3), qb_log_target_user_data_get(3), qb_log_tags_stringify_fn_set(3), qb_log_file_reopen(3), qb_log_fini(3), qb_log_callsites_dump(3), qb_log_ctl2(3), qb_log_target_user_data_set(3), qb_log_target_format(3), qb_log_thread_priority_set(3), qb_log_facility2int(3), qb_log_callsites_register(3), qb_log_filter_ctl2(3), qb_log_file_close(3), qb_log_format_set(3), qb_log_real_(3), qb_log_from_external_source_va(3), qb_log_callsite_get(3), qb_log_blackbox_write_to_file(3), qb_log_real_va_(3), qb_log_from_external_source(3), qb_log_blackbox_print_from_file(3), qb_log_facility2str(3), qb_log_ctl(3), qb_log_filter_ctl(3), qb_log_custom_close(3), qb_log_init(3), qb_log_file_open(3), qb_log_custom_open(3)
Copyright (C) 2010-2020 Red Hat, Inc. All rights reserved.