diff options
| author | DukePyrolator <DukePyrolator@5417fbe8-f217-4b02-8779-1006273d7864> | 2010-01-31 06:15:29 +0000 |
|---|---|---|
| committer | DukePyrolator <DukePyrolator@5417fbe8-f217-4b02-8779-1006273d7864> | 2010-01-31 06:15:29 +0000 |
| commit | aa4b3e256377030d291fc2d5f4db94985ce04395 (patch) | |
| tree | 993302c0cbe754612f69c22bbbc57d00220cabd4 /src/log.c | |
| parent | 47504c9de5accda45a19627fd2b6ec13baa6ba95 (diff) | |
replaced the alog() command with a new type-safe and stream-based Alog()
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2777 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src/log.c')
| -rw-r--r-- | src/log.c | 72 |
1 files changed, 35 insertions, 37 deletions
@@ -147,43 +147,6 @@ char *log_gettimestamp() /*************************************************************************/ -/* Log stuff to the log file with a datestamp. Note that errno is - * preserved by this routine and log_perror(). - */ - -void alog(const char *fmt, ...) -{ - va_list args; - char *buf; - int errno_save = errno; - char str[BUFSIZE]; - - checkday(); - - if (!fmt) { - return; - } - - va_start(args, fmt); - vsnprintf(str, sizeof(str), fmt, args); - va_end(args); - - buf = log_gettimestamp(); - - if (logfile) { - fprintf(logfile, "%s %s\n", buf, str); - } - if (nofork) { - fprintf(stderr, "%s %s\n", buf, str); - } - if (Config.LogChannel && LogChan && !debug && findchan(Config.LogChannel)) { - ircdproto->SendPrivmsg(findbot(Config.s_GlobalNoticer), Config.LogChannel, "%s", str); - } - errno = errno_save; -} - -/*************************************************************************/ - /* Like alog(), but tack a ": " and a system error message (as returned by * strerror()) onto the end. */ @@ -292,3 +255,38 @@ void fatal_perror(const char *fmt, ...) exit(1); } +Alog::Alog(LogLevel val) +{ + if (val > debug) + logit = false; + else + { + logit = true; + if (val >= LOG_DEBUG) + buf << "Debug: "; + } +} + +Alog::~Alog() +{ + if (!logit) + return; + + char *tbuf; + int errno_save = errno; + + checkday(); + + tbuf = log_gettimestamp(); + + if (logfile) { + fprintf(logfile, "%s %s\n", tbuf, buf.str().c_str()); + } + if (nofork) { + fprintf(stderr, "%s %s\n", tbuf, buf.str().c_str()); + } + if (Config.LogChannel && LogChan && !debug && findchan(Config.LogChannel)) { + ircdproto->SendPrivmsg(findbot(Config.s_GlobalNoticer), Config.LogChannel, "%s", buf.str().c_str()); + } + errno = errno_save; +} |
