Make WvStreams compile with gcc 4.4.
[wvstreams.git] / streams / wvsyslog.cc
blobdf83a31eadd8e3a3d58fcb3b20b941e05d86c0db
1 /*
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4 *
5 * WvSyslog is a descendant of WvLogRcv that sends messages to the syslogd
6 * daemon.
7 */
8 #include "wvsyslog.h"
9 #include "strutils.h"
10 #include <time.h>
11 #include <syslog.h>
13 WvSyslog::WvSyslog(WvStringParm _prefix, bool _include_appname,
14 WvLog::LogLevel _first_debug,
15 WvLog::LogLevel _max_level)
16 : WvLogRcv(_max_level), syslog_prefix(_prefix)
18 first_debug = _first_debug;
19 include_appname = _include_appname;
20 openlog(syslog_prefix, 0, LOG_DAEMON);
24 WvSyslog::~WvSyslog()
26 end_line();
27 closelog();
31 void WvSyslog::_begin_line()
33 if (include_appname)
34 current.put(prefix, prelen);
38 void WvSyslog::_mid_line(const char *str, size_t len)
40 current.put(str, len);
44 void WvSyslog::_end_line()
46 int lev, count;
47 struct LevMap
49 int wvlog_lvl;
50 int syslog_lvl;
53 static LevMap levmap[] = {
54 {WvLog::Critical, LOG_CRIT},
55 {WvLog::Error, LOG_ERR},
56 {WvLog::Warning, LOG_WARNING},
57 {WvLog::Notice, LOG_NOTICE},
58 {WvLog::Info, LOG_INFO},
59 {WvLog::Debug, LOG_DEBUG},
60 {WvLog::Debug2, -1},
61 {-1, -1}
64 if (current.used())
66 lev = -1;
68 for (count = 0; levmap[count].wvlog_lvl >= 0; count++)
70 if (last_level >= levmap[count].wvlog_lvl)
71 lev = levmap[count].syslog_lvl;
74 if (last_level < first_debug && lev == LOG_DEBUG)
75 lev = LOG_INFO;
77 if (lev >= 0)
79 current.put("", 1); // null-terminate
80 syslog(lev, "%s", current.get(current.used()));
82 else
83 current.zap(); // not important enough to print this message