This document describes how to use the YaST2 logging.
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.
There exist six different log levels denoting incidents of different importance:
In the default setting the levels 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.
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)
.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("-");
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.
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 <ycp/y2log.h>
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.
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
The log control uses a simple ini-like configuration file. It is looked for at /etc/YaST2/log.conf for root and at $HOME/.yast2/log.conf for regular users.
Example log.conf file could look like:
[Log] file = true syslog = false debug = false [Debug] YCP = true agent-pam = true packagemanager = false
"syslog=true", which basically means remote-logging. The similar option "file=true" means use the usual log files for logging. You could also turn those off which means no logging would be done at all, but rather don't do that ;-)
The "debug=true" means basically the same as Y2DEBUG=1 (that envirnoment variable overrides the log.conf settings) and that is log by default all debug messages (if not said otherwise).
You can turn debuggin on ("agent-pam=true") for a particular component (even if "debug=false") and also turn debugging off (for the case that "debug=true").
To provide a useful example, normal developers would need something like this $HOME/.yast2/log.conf (and unset Y2DEBUG):
[Debug] YCP = true agent-pam = true
It means turn YCP debug messages on and also turn on some particular agent. The other debug are in most uninteresting, so let them turned off.
During installation , define the variable "Loghost" on the command line with the log server ip address (Loghost=192.168.1.1 ) and all messages will be sent to this host. If you add y2debug, debugging will also be activated in log.conf.
On the server side, using syslog-ng, you can have logging per host using the following filters:
source network { tcp(); udp(); }; destination netmessages { file("/var/log/messages.$HOST"); }; log { source(network); filter(f_messages); destination(netmessages); };
Additionally to the usual logfile control you can control some logging feature by the environment variables.
Example: call the module password with QT interface and debugging messages set to on:
bash$ Y2DEBUG=1 yast2 users