.handler = ls_fdfile_handler,
.levels = LS_ALL_LEVELS,
.msgfmt = LSFMT_DEFAULT,
- // empty clist
+ // empty clist
.substreams.head.next = (cnode *) &ls_default_log.substreams.head,
.substreams.head.prev = (cnode *) &ls_default_log.substreams.head,
};
/* user de/allocated program/process name for use in the logsystem (for LSFMT_TITLE) */
-char *ls_title = NULL;
+char *ls_title = NULL;
/* Define an array (growing buffer) for pointers to log_streams. */
#define GBUF_TYPE struct log_stream*
int ls_streams_after = 0;
/* Initialize the logstream module.
- * It is not neccessary to call this explicitely as it is called by
+ * It is not neccessary to call this explicitely as it is called by
* the first ls_new() (for backward compatibility and ease of use). */
static void ls_init_module(void)
{
/* create the grow array */
ls_streams.ptr = NULL;
ls_streams.len = 0;
- lsbuf_set_size(&ls_streams, LS_INIT_STREAMS);
+ lsbuf_set_size(&ls_streams, LS_INIT_STREAMS);
/* bzero */
memset(ls_streams.ptr, 0, sizeof(struct log_stream*) * (ls_streams.len));
ls_streams_free = -1;
-
+
ls_initialized = 1;
-
+
/* init the default stream (0) as forwarder to fd2 */
struct log_stream *ls = ls_new();
ASSERT(ls == ls_streams.ptr[0]);
ASSERT(ls->regnum == 0);
ls->name = "default";
ls_add_substream(ls, (struct log_stream *) &ls_default_log);
-
+
/* log this */
ls_msg(L_DEBUG, "logstream module initialized.");
}
-/* close all open streams, un-initialize the module, free all memory,
+/* close all open streams, un-initialize the module, free all memory,
* use only ls_default_log */
void ls_close_all(void)
{
clist_remove((cnode*)i);
xfree(i);
cnt++;
- }
+ }
return cnt;
}
{
clist_remove((cnode*)i);
xfree(i);
- }
+ }
/* close and remember the stream */
if (ls->close!=NULL)
{
/* get the real number */
int n = LS_GET_STRNUM(num);
- if ((n<0) || (n>=ls_streams_after) || (ls_streams.ptr[n]->regnum==-1) )
+ if ((n<0) || (n>=ls_streams_after) || (ls_streams.ptr[n]->regnum==-1) )
{
- if (n==0)
+ if (n==0)
return (struct log_stream *)&ls_default_log;
else return NULL;
}
snprintf(stime, 24, "\?\?\?\?-\?\?-\?\? \?\?:\?\?:\?\?");
snprintf(sutime, 12, ".\?\?\?\?\?\?");
}
-
+
/* generate the message string */
va_copy(args2, args);
/* WARN: this may be C99 specefic */
}
xfree(buf);
-}
+}
/* The proposed alternative to original msg() */
void ls_msg(unsigned int cat, const char *fmt, ...)
va_start(args, fmt);
ls_vmsg(L_FATAL, fmt, args);
va_end(args);
-///// why this?
+///// why this?
// if (log_die_hook)
// log_die_hook();
#ifdef DEBUG_DIE_BY_ABORT
/* process a message (string) */
/* depth prevents undetected looping */
-/* returns 1 in case of loop detection or other fatal error
+/* returns 1 in case of loop detection or other fatal error
* 0 otherwise */
int ls_passmsg(int depth, struct log_stream *ls, const char *stime, const char *sutime, const char *m, u32 cat)
{
/* Check recursion depth */
if( depth > LS_MAX_DEPTH )
{
- ls_passmsg(0, (struct log_stream *)&ls_default_log, stime, sutime,
+ ls_passmsg(0, (struct log_stream *)&ls_default_log, stime, sutime,
"Loop in the log_stream system detected.", L_ERROR | (cat&LS_INTERNAL_MASK) );
return 1;
}
-
+
/* Filter by level and filter hook */
if(!( (1<<LS_GET_LEVEL(cat)) & ls->levels )) return 0;
if( ls->filter )
/* Prepare for handler */
if(ls->handler)
{
- int len = strlen(m) + strlen(stime) + strlen(sutime) + 32;
+ int len = strlen(m) + strlen(stime) + strlen(sutime) + 32;
/* SHOULD be enough for all information, but beware */
if (ls_title) len += strlen(ls_title);
if (ls->name) len += strlen(ls->name);
*p++=LS_LEVEL_LETTER(LS_GET_LEVEL(cat));
*p++=' ';
}
-
+
/* Time (|stime| + |sutime| + 1 chars) */
if(ls->msgfmt & LSFMT_TIME)
{
{
struct log_stream *ls;
int fd = open(path, O_WRONLY | O_CREAT | O_APPEND, 0666);
- if (fd<0)
+ if (fd<0)
{
ls_msg(L_ERROR, "Opening logfile '%s' failed: %m.", path);
return NULL;
int prio;
ASSERT(ls);
ASSERT(m);
-
+
prio = ls_syslog_convert_level(LS_GET_LEVEL(flags)) | (ls->idata);
if (ls->name)
syslog(prio | (ls->idata), "%s: %s", ls->name, m);
ls->close = ls_syslog_close;
return ls;
}
-
#define _UCW_LOGSTREAM_H_
#include "ucw/clists.h"
-
+
/* user de/allocated program/process name for use in the logsystem */
extern char *ls_title;
extern const struct log_stream ls_default_log;
/* A message is processed as follows:
- * 1. Discard if message level not in levels
+ * 1. Discard if message level not in levels
* 2. Run filter (if any), discard if ret. nonzero
* 3. Pass the message to all log_streams in substreams
* 4. Format the message informaion acc. to msgfmt
///// Macros for extracting parts of the flags parameter
// The division of the flags parameter is decided only here
// The current division is (for 32 bit flags):
-// MSB <5 bits: any internal log flags> <8 bits: "user" flags> <10 bits: stream number>
+// MSB <5 bits: any internal log flags> <8 bits: "user" flags> <10 bits: stream number>
// <8 bits: severity level> LSB
// Bits per section
#define LS_SET_FLAGS(flags) (( flags ) << LS_FLAGS_POS )
#define LS_SET_INTERNAL(intern) (( intern ) << LS_INTERNAL_POS )
-// Internal flags of the logsystem
-// Avoid operations that are unsafe in signal handlers
-#define LSFLAG_SIGHANDLER LS_SET_INTERNAL(0x001)
+// Internal flags of the logsystem
+// Avoid operations that are unsafe in signal handlers
+#define LSFLAG_SIGHANDLER LS_SET_INTERNAL(0x001)
// The module is initialized when a first stream is created.
// Before that only the default log exists.
/* close all open streams, un-initialize the module, free all memory,
* use only ls_default_log */
void ls_close_all(void);
-
+
/* add a new substream, malloc()-ate a new simp_node */
void ls_add_substream(struct log_stream *where, struct log_stream *what);
/* depth prevents undetected looping */
/* returns 1 in case of loop detection or other fatal error
* 0 otherwise */
-int ls_passmsg(int depth, struct log_stream *ls, const char *stime, const char *sutime,
+int ls_passmsg(int depth, struct log_stream *ls, const char *stime, const char *sutime,
const char *msg, u32 cat);
/* Maximal depth of ls_passmsg recursion */
// NOTE:
// under unix, for ordinary files open in append mode, the writes
// are atomic (unless you meet the quota or other bad things happen),
-// so using a single log_stream is thread-safe and the file can be shared
+// so using a single log_stream is thread-safe and the file can be shared
// among multiple processes
/* assign log to a file descriptor */
/**** syslog */
-// NOTE:
+// NOTE:
// The syslog uses a bit different severity levels, for details, see
// ls_syslog_convert_level().
-// syslog also prepends it's own time and severity info, so the default
-// messaging passes only clean message
+// syslog also prepends it's own time and severity info, so the default
+// messaging passes only clean message
/* assign log to a syslog facility */
/* initialize with no formatting (syslog adds these inforamtion) */