diff --git a/doc/example.conf b/doc/example.conf index 3e03f1366..2477954ef 100644 --- a/doc/example.conf +++ b/doc/example.conf @@ -61,6 +61,10 @@ log { # LVM2. There are three levels of verbosity, 3 being the most # verbose. verbose = 0 + + # Should we send log messages through syslog? + # 1 is yes; 0 is no. + syslog = 1 } # Configuration of metadata backups and archiving. In LVM2 when we diff --git a/lib/log/log.c b/lib/log/log.c index 40cd3eb0e..1906b36f5 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -29,7 +29,8 @@ void fin_log() { } void fin_syslog() { - closelog(); + if (_syslog) + closelog(); _syslog = 0; } diff --git a/man/lvm.conf.5 b/man/lvm.conf.5 index fefd672a6..b2fcb8af3 100644 --- a/man/lvm.conf.5 +++ b/man/lvm.conf.5 @@ -105,6 +105,12 @@ is invoked. By default tools append messages to the log file. .IP \fBverbose\fP \(em Default level (0-3) of messages sent to stdout or stderr. 3 is the most verbose; 0 should produce the least output. +.IP +\fBsyslog\fP \(em Set to 1 (the default) to send log messages through syslog. +Turn off by setting to 0. If you set to an integer greater than one, +this is used - unvalidated - as the facility. The default is LOG_USER. +See /usr/include/sys/syslog.h for safe facility values to use. +For example, LOG_LOCAL0 might be 128. .TP \fBbackup\fP \(em Configuration for metadata backups. .IP @@ -159,3 +165,5 @@ Use 022 to allow other users to read the files by default. .SH SEE ALSO .BR lvm (8) .BR umask (2) +.BR syslog (3) +.BR syslog.conf (5) diff --git a/tools/lvm.c b/tools/lvm.c index c98c66cb9..56c3f3acd 100644 --- a/tools/lvm.c +++ b/tools/lvm.c @@ -72,6 +72,7 @@ struct config_info { int debug; int verbose; int test; + int syslog; int archive; /* should we archive ? */ int backup; /* should we backup ? */ @@ -710,21 +711,31 @@ static void __init_log(struct config_file *cf) { char *open_mode = "a"; - const char *log_file = find_config_str(cf->root, "log/file", '/', 0); + const char *log_file; + + + _default_settings.syslog = + find_config_int(cf->root, "log/syslog", '/', 1); + if (_default_settings.syslog != 1) + fin_syslog(); + + if (_default_settings.syslog > 1) + init_syslog(_default_settings.syslog); _default_settings.debug = find_config_int(cf->root, "log/level", '/', 0); + init_debug(_default_settings.debug); + _default_settings.verbose = find_config_int(cf->root, "log/verbose", '/', 0); + init_verbose(_default_settings.verbose); + _default_settings.test = find_config_int(cf->root, "global/test", '/', 0); - if (find_config_int(cf->root, "log/overwrite", '/', 0)) open_mode = "w"; - init_debug(_default_settings.debug); - init_verbose(_default_settings.verbose); - + log_file = find_config_str(cf->root, "log/file", '/', 0); if (log_file) { /* set up the logging */ if (!(_log = fopen(log_file, open_mode))) @@ -1078,6 +1089,7 @@ static void fin(void) dump_memory(); fin_log(); + fin_syslog(); if (_log) fclose(_log);