summaryrefslogtreecommitdiff
path: root/src/log.c
diff options
context:
space:
mode:
authorDukePyrolator <DukePyrolator@5417fbe8-f217-4b02-8779-1006273d7864>2010-01-31 06:15:29 +0000
committerDukePyrolator <DukePyrolator@5417fbe8-f217-4b02-8779-1006273d7864>2010-01-31 06:15:29 +0000
commitaa4b3e256377030d291fc2d5f4db94985ce04395 (patch)
tree993302c0cbe754612f69c22bbbc57d00220cabd4 /src/log.c
parent47504c9de5accda45a19627fd2b6ec13baa6ba95 (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.c72
1 files changed, 35 insertions, 37 deletions
diff --git a/src/log.c b/src/log.c
index 440b101eb..eb75769ab 100644
--- a/src/log.c
+++ b/src/log.c
@@ -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;
+}