]> mj.ucw.cz Git - libucw.git/commitdiff
Logging: Coding style cleanups.
authorMartin Mares <mj@ucw.cz>
Thu, 12 Feb 2009 23:07:30 +0000 (00:07 +0100)
committerMartin Mares <mj@ucw.cz>
Thu, 12 Feb 2009 23:07:30 +0000 (00:07 +0100)
Also removed a couple of unused variables.

ucw/logstream.c
ucw/logstream.h

index d12688c0cd4813e690f2a331030786e853ee5af2..97ef9d39f06c0abab467e93ca71004f908e61e77 100644 (file)
@@ -1,6 +1,17 @@
+/*
+ *     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>
@@ -13,7 +24,6 @@
 #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);
@@ -56,16 +66,13 @@ int ls_streams_after = 0;
  * 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;
@@ -201,7 +208,8 @@ struct log_stream *ls_bynum(int num)
   {
     if (n==0)
       return (struct log_stream *)&ls_default_log;
-    else return NULL;
+    else
+      return NULL;
   }
   return ls_streams.ptr[n];
 }
@@ -217,7 +225,6 @@ void ls_vmsg(unsigned int cat, const char *fmt, va_list args)
   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 */
@@ -419,7 +426,7 @@ static void ls_fdfile_close(struct log_stream *ls)
 }
 
 /* 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);
index 9948a8e10bf22c52a4e443a69a766d2c6bf23f63..67ac4d2763db714d004eac7051dab739e67a6b50 100644 (file)
@@ -1,3 +1,13 @@
+/*
+ *     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_
 
@@ -30,7 +40,7 @@ struct log_stream
   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:
@@ -42,7 +52,7 @@ extern const struct log_stream ls_default_log;
  */
 
 /* 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) */
@@ -55,7 +65,7 @@ enum LS_FMT
   LSFMT_DEFAULT=LSFMT_LEVEL+LSFMT_TIME
 };
 
-enum LS_LEVELS
+enum ls_levels
 {
   L_DEBUG=0,     /*  'D'  -  Debugging messages */
   L_INFO,        /*  'I'  -  Informational */
@@ -80,7 +90,7 @@ enum LS_LEVELS
 //     <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,
@@ -88,7 +98,7 @@ enum LS_FLAGBITS {
 };
 
 // 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,
@@ -96,7 +106,7 @@ enum LS_FLAGPOS {
 };
 
 // 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,
@@ -120,7 +130,7 @@ enum LS_FLAGMASKS {
 #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
@@ -136,7 +146,7 @@ void ls_close(struct log_stream *ls);
  * 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 */