+/*
+ * UCW Library -- Logging
+ *
+ * (c) 2008 Tomas Gavenciak <gavento@ucw.cz>
+ * (c) 2009 Martin Mares <mj@ucw.cz>
+ *
+ * This software may be freely distributed and used according to the terms
+ * of the GNU Lesser General Public License.
+ */
+
#include "ucw/lib.h"
#include "ucw/clists.h"
#include "ucw/simple-lists.h"
+#include "ucw/logstream.h"
#include <syslog.h>
#include <string.h>
#include <time.h>
#include <alloca.h>
#include <fcntl.h>
-#include "ucw/logstream.h"
/* forward declaration */
static int ls_fdfile_handler(struct log_stream* ls, const char *m, u32 cat);
* the first ls_new() (for backward compatibility and ease of use). */
static void ls_init_module(void)
{
- unsigned int i;
if (ls_initialized) return;
/* create the grow array */
- ls_streams.ptr = NULL;
- ls_streams.len = 0;
+ lsbuf_init(&ls_streams);
lsbuf_set_size(&ls_streams, LS_INIT_STREAMS);
- /* bzero */
- memset(ls_streams.ptr, 0, sizeof(struct log_stream*) * (ls_streams.len));
+ bzero(ls_streams.ptr, sizeof(struct log_stream*) * (ls_streams.len));
ls_streams_free = -1;
ls_initialized = 1;
{
if (n==0)
return (struct log_stream *)&ls_default_log;
- else return NULL;
+ else
+ return NULL;
}
return ls_streams.ptr[n];
}
char sutime[12];
char *buf,*p;
int len;
- int level=LS_GET_LEVEL(cat);
struct log_stream *ls=ls_bynum(cat);
/* Check the stream existence */
}
/* handler for standard files */
-static int ls_fdfile_handler(struct log_stream* ls, const char *m, u32 cat)
+static int ls_fdfile_handler(struct log_stream* ls, const char *m, u32 cat UNUSED)
{
int len = strlen(m);
int r = write(ls->idata, m, len);
+/*
+ * UCW Library -- Logging
+ *
+ * (c) 2008 Tomas Gavenciak <gavento@ucw.cz>
+ * (c) 2009 Martin Mares <mj@ucw.cz>
+ *
+ * This software may be freely distributed and used according to the terms
+ * of the GNU Lesser General Public License.
+ */
+
#ifndef _UCW_LOGSTREAM_H_
#define _UCW_LOGSTREAM_H_
void (*close)(struct log_stream* ls);
};
-/* the deafult logger */
+/* the default logger */
extern const struct log_stream ls_default_log;
/* A message is processed as follows:
*/
/* log header verbosity specifying message passed to handler */
-enum LS_FMT
+enum ls_fmt
{
LSFMT_LEVEL=1, /* log severity level (one letter) */
LSFMT_TIME=2, /* log time (date-seconds) */
LSFMT_DEFAULT=LSFMT_LEVEL+LSFMT_TIME
};
-enum LS_LEVELS
+enum ls_levels
{
L_DEBUG=0, /* 'D' - Debugging messages */
L_INFO, /* 'I' - Informational */
// <8 bits: severity level> LSB
// Bits per section
-enum LS_FLAGBITS {
+enum ls_flagbits {
LS_LEVEL_BITS = 8,
LS_STRNUM_BITS = 16,
LS_FLAGS_BITS = 5,
};
// Section shifts
-enum LS_FLAGPOS {
+enum ls_flagpos {
LS_LEVEL_POS = 0,
LS_STRNUM_POS = LS_LEVEL_POS + LS_LEVEL_BITS,
LS_FLAGS_POS = LS_STRNUM_POS + LS_STRNUM_BITS,
};
// Bitmasks
-enum LS_FLAGMASKS {
+enum ls_flagmasks {
LS_LEVEL_MASK = (( 1 << LS_LEVEL_BITS ) - 1 ) << LS_LEVEL_POS,
LS_STRNUM_MASK = (( 1 << LS_STRNUM_BITS ) - 1 ) << LS_STRNUM_POS,
LS_FLAGS_MASK = (( 1 << LS_FLAGS_BITS ) - 1 ) << LS_FLAGS_POS,
#define LSFLAG_SIGHANDLER LS_SET_INTERNAL(0x001)
// The module is initialized when a first stream is created.
-// Before that only the default log exists.
+// Before that only the default stream exists.
// Initial number of streams to allocate (must be >=2)
#define LS_INIT_STREAMS 8
* use only ls_default_log */
void ls_close_all(void);
-/* add a new substream, malloc()-ate a new simp_node */
+/* add a new substream, xmalloc()-ate a new simp_node */
void ls_add_substream(struct log_stream *where, struct log_stream *what);
/* remove all occurences of a substream, free() the simp_node */