This document describes how to use the YaST2 logging.
Document author: Michal Svec <msvec@suse.cz>.
Contents:
Introduction
During execution YaST2 components create log messages. The purpose
is to inform the user or the programmer about errors and other incidents.
The logging should be used instead of fprintf(stderr,...) to create
logmessages of different types. It can be better controled, what to
log and what not, where to log and how to log.
Logging levels
There are existing six different log levels denoting incidents of
different importance:
In the default setting the level 1-5 are logged, level 0 (DEBUG) is switched off. See the Logging control and Environment control for more details how to control the logging and its levels.
Logging functions
According to the logging levels, use the following
logging functions:
void y2debug(const char *format, ...); void y2milestone(const char *format, ...); void y2warning(const char *format, ...); void y2error(const char *format, ...); void y2security(const char *format, ...); void y2internal(const char *format, ...);The parameter format is the format string like the one for printf(3).
Additional functions
Setting the logfile name:
void y2setLogfileName(const char *filename);This function sets the logfile name. If the name cannot be open for writing (append), it use the default logfiles. If you want to output the debug log the stderr, use "-" as the argument for the y2setLogfileName:
y2setLogfileName("-");
Universal logging functions:
void y2logger(loglevel_t level, const char *format, ...); void y2vlogger(loglevel_t level, const char *format, va_list ap);These functions are provided probably only for those who don't want to use the regular logging functions. For example for setting the loglevel acording to some rule.
Components
As the filenames are not unique over the whole YaST2 source,
you can specify the component name. Then the pair of the component
name and the filename will uniquely identify the message.
Note: I think that the filenames should be self explaining and thus unique overall the whole source. Then the component name can be removed, but as now the filename is not unique, you can optionally specify the component name.
As the component is a more general property then filename, it should be same in all messages in one file. So for one source file it is defined only once, at the beginning of the file. And because of implementation purposes (just) before the inclusion of y2log.h:
#define y2log_component "y2a_mods" #include <y2log.h>
Logfiles
The YaST2 log is written to a file. If you work as normal user,
the default logfile is ~/.y2log. If you work as root, the file
is /var/log/YaST2/y2log. The logfile is created with the permissions
600, since it may contain secret data when the debug level is turned on.
If the logfile cannot be open, the stderr is use instead.
FIXME: logfiles size and number control / env control.
Log entries
Each log entry consist of these fields:
The output format:
date time <level> hostname(pid) [component] filename(function):line message... date time <level> hostname(pid) filename(function):line message...
Example:
2000-10-13 15:35:36 <3> beholder(2971) [ag_modules] Modules.cc(quit):22 io=7 2000-10-13 15:35:37 <0> beholder(2971) ModulesAgent.cc(main):23 irq=7
Logging control
FIXME: As the logcontrol.ycp module is not functional for me, this section
remains to be completed.
Environment control
Additionally to the usual logfile control
you can control some logging feature by the environment variables.
bash$ Y2DEBUG=1 y2qt password
YaST2 logging TODO
Source: