summaryrefslogtreecommitdiffstats
path: root/loader
diff options
context:
space:
mode:
authorAles Kozumplik <akozumpl@redhat.com>2010-02-23 10:33:24 +0100
committerAles Kozumplik <akozumpl@redhat.com>2010-02-24 10:45:24 +0100
commit3fb12e4eafebfa3885c25b9ab93e9c35f6847425 (patch)
tree0142414b2922467ba07e3f41e910f898cfe83a17 /loader
parent482d84b81cc7e65b0e605b970da126a2516c8025 (diff)
downloadanaconda-3fb12e4eafebfa3885c25b9ab93e9c35f6847425.tar.gz
anaconda-3fb12e4eafebfa3885c25b9ab93e9c35f6847425.tar.xz
anaconda-3fb12e4eafebfa3885c25b9ab93e9c35f6847425.zip
Make loader log into syslog (so remote logging works for it as well) (#524980)
Diffstat (limited to 'loader')
-rw-r--r--loader/loader.c2
-rw-r--r--loader/log.c47
2 files changed, 34 insertions, 15 deletions
diff --git a/loader/loader.c b/loader/loader.c
index 95d07be11..265fa859d 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -38,7 +38,6 @@
#include <stdlib.h>
#include <string.h>
#include <strings.h>
-#include <syslog.h>
#include <unistd.h>
#include <stdint.h>
#include <dirent.h>
@@ -1933,7 +1932,6 @@ int main(int argc, char ** argv) {
#endif
openLog();
- openlog("loader", 0, LOG_LOCAL0);
/* XXX if RHEL, enable the AUTODD feature by default,
* but we should come with more general way how to control this */
diff --git a/loader/log.c b/loader/log.c
index 0d1fa98af..4682c8133 100644
--- a/loader/log.c
+++ b/loader/log.c
@@ -30,12 +30,34 @@
#include <time.h>
#include <unistd.h>
#include <sys/time.h>
+#include <syslog.h>
#include "log.h"
static FILE * tty_logfile = NULL;
static FILE * file_logfile = NULL;
static int minLevel = INFO;
+static const char * syslog_facility = "loader";
+
+/* maps our loglevel to syslog loglevel */
+static int mapLogLevel(int level)
+{
+ switch (level) {
+ case DEBUGLVL:
+ return LOG_DEBUG;
+ case INFO:
+ return LOG_INFO;
+ case WARNING:
+ return LOG_WARNING;
+ case CRITICAL:
+ return LOG_CRIT;
+ case ERROR:
+ default:
+ /* if someone called us with an invalid level value, log it as an error
+ too. */
+ return LOG_ERR;
+ }
+}
static void printLogHeader(int level, FILE *outfile) {
struct timeval current_time;
@@ -74,34 +96,28 @@ static void printLogHeader(int level, FILE *outfile) {
}
void logMessageV(int level, const char * s, va_list ap) {
+ va_list apc;
+ va_copy(apc, ap);
+ /* Log everything into syslog */
+ vsyslog(mapLogLevel(level), s, apc);
/* Only log to the screen things that are above the minimum level. */
if (tty_logfile && level >= minLevel) {
- va_list apc;
-
- va_copy(apc, ap);
-
printLogHeader(level, tty_logfile);
vfprintf(tty_logfile, s, apc);
fprintf(tty_logfile, "\n");
fflush(tty_logfile);
-
- va_end(apc);
}
/* But log everything to the file. */
if (file_logfile) {
- va_list apc;
-
- va_copy(apc, ap);
-
printLogHeader(level, file_logfile);
vfprintf(file_logfile, s, apc);
fprintf(file_logfile, "\n");
fflush(file_logfile);
-
- va_end(apc);
}
+
+ va_end(apc);
}
void logMessage(int level, const char * s, ...) {
@@ -116,8 +132,11 @@ int tty_logfd = -1;
int file_logfd = -1;
void openLog() {
- int flags;
+ /* init syslog logging (so loader messages can also be forwarded to a remote
+ syslog daemon */
+ openlog(syslog_facility, 0, LOG_LOCAL1);
+ int flags;
tty_logfile = fopen("/dev/tty3", "w");
file_logfile = fopen("/tmp/anaconda.log", "w");
@@ -140,6 +159,8 @@ void closeLog(void) {
if (file_logfile)
fclose(file_logfile);
+ /* close syslog logger */
+ closelog();
}
/* set the level. higher means you see more verbosity */