OSSP CVS Repository

ossp - Difference in ossp-pkg/l2/l2_stream.c versions 1.6 and 1.7
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/l2/l2_stream.c 1.6 -> 1.7

--- l2_stream.c  2001/09/03 12:16:44     1.6
+++ l2_stream.c  2001/09/03 13:43:33     1.7
@@ -40,9 +40,9 @@
         return NULL;
     st->levelmask = 0;
     for (i = 0; i < L2_MAX_CHANNELS; i++)
-        st->channels[i] = NULL;
+        st->channels[i].ch = NULL;
     for (i = 0; i < L2_MAX_FORMATTERS; i++)
-        st->formatters[i].name = NULL;
+        st->formatters[i].cb = NULL;
     return st;
 }
 
@@ -50,13 +50,14 @@
 {
     int i;
 
-    if (st == NULL || ch == NULL)
+    if (st == NULL || ch == NULL || levelmask == 0)
         return L2_ERROR;
-    for (i = 0; i < L2_MAX_CHANNELS && st->channels[i] != NULL; i++)
+    for (i = 0; i < L2_MAX_CHANNELS && st->channels[i].ch != NULL; i++)
         ;
     if (i == L2_MAX_CHANNELS)
         return L2_ERROR;
-    st->channels[i] = ch;
+    st->channels[i].ch = ch;
+    st->channels[i].levelmask = levelmask;
     return L2_OK;
 }
 
@@ -66,13 +67,13 @@
 
     if (st == NULL || name == NULL || cb != NULL)
         return L2_ERROR;
-    for (i = 0; i < L2_MAX_FORMATTERS && st->formatters[i].name != NULL; i++)
+    for (i = 0; i < L2_MAX_FORMATTERS && st->formatters[i].cb != NULL; i++)
         ;
     if (i == L2_MAX_FORMATTERS)
         return L2_ERROR;
     st->formatters[i].name = strdup(name);
-    st->formatters[i].context = ctx;
-    st->formatters[i].callback = cb;
+    st->formatters[i].ctx  = ctx;
+    st->formatters[i].cb   = cb;
     return L2_OK;
 }
 
@@ -86,36 +87,48 @@
     return L2_OK;
 }
 
-l2_result_t l2_stream_log(l2_stream_t *st, unsigned int log_level, const char *fmt, ...)
+l2_result_t l2_stream_log(l2_stream_t *st, unsigned int level, const char *fmt, ...)
 {
     va_list ap;
     l2_result_t rv;
 
-    if (st == NULL || log_level == 0 || fmt == NULL)
+    if (st == NULL || level == 0 || fmt == NULL)
         return L2_ERROR;
     va_start(ap, fmt);
-    rv = l2_stream_vlog(st, log_level, fmt, ap);
+    rv = l2_stream_vlog(st, level, fmt, ap);
     va_end(ap);
     return rv;
 }
 
-l2_result_t l2_stream_vlog(l2_stream_t *st, unsigned int log_level, const char *fmt, va_list ap)
+l2_result_t l2_stream_vlog(l2_stream_t *st, unsigned int level, const char *fmt, va_list ap)
 {
     int i;
+    int l, j;
     size_t len;
     l2_result_t rv;
 
-    if (st == NULL || log_level == 0 || fmt == NULL || ap == NULL)
+    if (st == NULL || fmt == NULL || ap == NULL)
         return L2_ERROR;
 
+    /* make sure only a single level is specified */
+    for (l = level, j = 0; l != 0; l = (l >> 1))
+        j++;
+    if (j != 1)
+        return L2_ERROR;
+
+    /* check whether level is globally enabled */
+    if (!(st->levelmask & level))
+        return L2_OK;
+
     /* XXX use st->formatter!! XXX */
     len = vsnprintf(st->message, L2_MAX_MSGSIZE, fmt, ap);
 
     rv = L2_OK;
-    for (i = 0; i < L2_MAX_CHANNELS && st->channels[i] != NULL; i++) {
-        /* XXX write only if st->levelmask contains log_level */
-        if ((rv = l2_channel_write(st->channels[i], st->message, len)) != L2_OK)
-            break;
+    for (i = 0; i < L2_MAX_CHANNELS && st->channels[i].ch != NULL; i++) {
+        if (st->channels[i].levelmask & level) {
+            if ((rv = l2_channel_write(st->channels[i].ch, st->message, len)) != L2_OK)
+                break;
+        }
     }
     return rv;
 }
@@ -126,9 +139,9 @@
 
     if (st == NULL)
         return L2_ERROR;
-    for (i = 0; i < L2_MAX_CHANNELS && st->channels[i] != NULL; i++)
-        l2_channel_destroy(st->channels[i]);
-    for (i = 0; i < L2_MAX_FORMATTERS && st->formatters[i].name != NULL; i++)
+    for (i = 0; i < L2_MAX_CHANNELS && st->channels[i].ch != NULL; i++)
+        l2_channel_destroy(st->channels[i].ch);
+    for (i = 0; i < L2_MAX_FORMATTERS && st->formatters[i].cb != NULL; i++)
         free(st->formatters[i].name);
     free(st);
     return L2_OK;

CVSTrac 2.0.1