]> the.earth.li Git - onak.git/blobdiff - log.c
Switch to re-entrant versions of *time functions
[onak.git] / log.c
diff --git a/log.c b/log.c
index dc8c2e8d6198c418f92fab0d75d182044ec06b30..7c6f2eeee5312e3e6e5dfd21fc4b976db5d2bc15 100644 (file)
--- a/log.c
+++ b/log.c
@@ -1,11 +1,19 @@
 /*
  * log.c - Simple logging framework.
  *
- * Jonathan McDowell <noodles@earth.li>
+ * Copyright 2003 Jonathan McDowell <noodles@earth.li>
  *
- * Copyright 2003 Project Purple
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; version 2 of the License.
  *
- * $Id: log.c,v 1.4 2003/06/04 20:57:10 noodles Exp $
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
 #include <stdarg.h>
@@ -24,7 +32,7 @@
  *     logs - if we're asked to log something below this level we won't output
  *     it.
  */
-static loglevels logthres = LOGTHING_DEBUG;
+static loglevels logthres = LOGTHING_NOTICE;
 
 /*
  *     logappname - the name of the application using us.
@@ -102,6 +110,17 @@ loglevels setlogthreshold(loglevels loglevel)
        return oldlevel;
 }
 
+/*
+ *     getlogthreshold - get the threshold for log output
+ *
+ *     Returns the threshold for log output; anything logged with a log level
+ *     lower than this will be silently dropped.
+ */
+loglevels getlogthreshold(void)
+{
+       return logthres;
+}
+
 /*
  *     vflog - write a log entry to an already opened log file.
  *      @logfile: The FILE * handle of the open log file.
@@ -114,19 +133,19 @@ loglevels setlogthreshold(loglevels loglevel)
  */
 static void vflog(FILE *logfile, const char *format, va_list ap)
 {
-       struct tm *timestamp = NULL;
-       time_t     timer = 0;
+       struct tm timestamp;
+       time_t    timer = 0;
 
        timer = time(NULL);
-       timestamp = localtime(&timer);
+       localtime_r(&timer, &timestamp);
 
        fprintf(logfile, "[%02d/%02d/%4d %02d:%02d:%02d] %s[%d]: ",
-                       timestamp->tm_mday,
-                       timestamp->tm_mon + 1,
-                       timestamp->tm_year + 1900,
-                       timestamp->tm_hour,
-                       timestamp->tm_min,
-                       timestamp->tm_sec,
+                       timestamp.tm_mday,
+                       timestamp.tm_mon + 1,
+                       timestamp.tm_year + 1900,
+                       timestamp.tm_hour,
+                       timestamp.tm_min,
+                       timestamp.tm_sec,
                        (logappname == NULL) ? "" : logappname,
                        getpid());
        vfprintf(logfile, format, ap);