[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] Allow multiple logfiles at different severity ranges
Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv6604/src/common
Modified Files:
log.c log.h
Log Message:
Allow multiple logfiles at different severity ranges
Index: log.c
===================================================================
RCS file: /home/or/cvsroot/src/common/log.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- log.c 10 May 2004 10:27:52 -0000 1.40
+++ log.c 19 May 2004 20:07:07 -0000 1.41
@@ -11,6 +11,7 @@
#include <stdarg.h>
#include <assert.h>
#include <stdlib.h>
+#include <string.h>
#include "orconfig.h"
#include "./util.h"
#include "./log.h"
@@ -162,14 +163,14 @@
/** Add a log handler to send all messages of severity <b>loglevel</b>
* or higher to <b>stream</b>. */
-void add_stream_log(int loglevel, const char *name, FILE *stream)
+void add_stream_log(int loglevelMin, int loglevelMax, const char *name, FILE *stream)
{
logfile_t *lf;
lf = tor_malloc(sizeof(logfile_t));
lf->filename = name;
lf->needs_close = 0;
- lf->loglevel = loglevel;
- lf->max_loglevel = LOG_ERR;
+ lf->loglevel = loglevelMin;
+ lf->max_loglevel = loglevelMax;
lf->file = stream;
lf->next = logfiles;
logfiles = lf;
@@ -180,16 +181,43 @@
* the logfile fails, -1 is returned and errno is set appropriately
* (by fopen).
*/
-int add_file_log(int loglevel, const char *filename)
+int add_file_log(int loglevelMin, int loglevelMax, const char *filename)
{
FILE *f;
f = fopen(filename, "a");
if (!f) return -1;
- add_stream_log(loglevel, filename, f);
+ add_stream_log(loglevelMin, loglevelMax, filename, f);
logfiles->needs_close = 1;
return 0;
}
+/** If <b>level</b> is a valid log severity, return the corresponding
+ * numeric value. Otherwise, return -1. */
+int parse_log_level(const char *level) {
+ if (!strcasecmp(level, "err"))
+ return LOG_ERR;
+ else if (!strcasecmp(level, "notice"))
+ return LOG_NOTICE;
+ else if (!strcasecmp(level, "info"))
+ return LOG_INFO;
+ else if (!strcasecmp(level, "debug"))
+ return LOG_DEBUG;
+ else
+ return -1;
+}
+
+int get_min_log_level(void)
+{
+ logfile_t *lf;
+ int min = LOG_ERR;
+ for (lf = logfiles; lf; lf = lf->next) {
+ if (lf->loglevel < min)
+ min = lf->loglevel;
+ }
+ return min;
+}
+
+
/*
Local Variables:
mode:c
Index: log.h
===================================================================
RCS file: /home/or/cvsroot/src/common/log.h,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- log.h 10 May 2004 07:54:13 -0000 1.24
+++ log.h 19 May 2004 20:07:07 -0000 1.25
@@ -46,8 +46,10 @@
#define CHECK_PRINTF(formatIdx, firstArg)
#endif
-void add_stream_log(int loglevel, const char *name, FILE *stream);
-int add_file_log(int severity, const char *filename);
+int parse_log_level(const char *level);
+void add_stream_log(int severityMin, int severityMax, const char *name, FILE *stream);
+int add_file_log(int severityMin, int severityMax, const char *filename);
+int get_min_log_level(void);
void close_logs();
void reset_logs();