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 controlled, what to log and what not, where
to log and how to log.
Use y2debug()
for debugging messages,
y2warning()
for warnings and y2error()
for error
messages, syntax is same as printf(3)
.
Set "export Y2DEBUG=1"
in your .profile
or
run "Y2DEBUG=1 yast2"
.
If root
, see /var/log/YaST2/y2log
, otherwise
~/.y2log
for the output.
In the y2log
, entries are uniquely identified by the
filename and line number.
There exist six different log levels denoting incidents of different importance:
Debug messages, which help the programmers.
Normal log messages. Some important actions are logged. For example each time a YaST2 module is started, a log entry is created.
Some error has occured, but the execution could be continued.
Some major error has occured. The execution may be continued, but probably more errors will occur.
Some security relevant incident has occured.
Internal error. Please enter into Bugzilla or directly contact the programmers.
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:
date
The date when the log entry has been made.
time
The time when the log entry has been made.
level
The log entry level. See Logging levels.
hostname
The hostname of host where the yast2 runs.
pid
The process ID of the yast2 process.
component
The name of the current component. Optional and probably obsolete.
filename
The name of the source file where the log entry has been made.
function
The name of the function where the log entry has been made.
line
The line number where the log entry has been made.
message
The text of the log message.
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.
By setting this variable to an arbitrary value you turn on the debug log output. But only when entry control is not covered by the usual logfile control.
By setting this variable to an arbitrary value you turn on the debug log output. Everything will be logged.
By setting this variable to an arbitrary value you turn on the debug log output for the bash_background processes.
By this variable you can control the size of logfiles. See Logfiles for details.
By this variable you can control the number of logfiles. See Logfiles for details.
Example: call the module password
with QT
interface and debugging messages set to on:
bash$ Y2DEBUG=1 yast2 users