2 Copyright (C) Slava Astashonok <sla@0n.ru>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License.
7 $Id: my_log.c,v 1.3.2.2 2004/02/02 08:06:24 sla Exp $
19 static char *my_log_indent;
20 static unsigned my_log_min_level;
21 static unsigned my_log_flags;
22 static char *my_log_names[] = {
23 "EMERG", "ALERT", "CRIT", "ERR", "WARNING", "NOTICE", "INFO", "DEBUG"
26 void my_log_open(char *indent, unsigned min_level, unsigned flags)
28 my_log_indent = indent;
29 my_log_min_level = min_level;
31 //openlog(0, LOG_PID, MY_LOG_SYSLOG_FACILITY);
32 openlog(my_log_indent, 0, MY_LOG_SYSLOG_FACILITY);
35 void my_log_close(void)
40 void my_log(unsigned level, const char *format, ...)
46 if (level <= my_log_min_level) {
47 va_start(args, format);
48 vsnprintf(msg, sizeof(msg), format, args);
49 snprintf(msg_prefix, sizeof(msg_prefix), "[%s]: ", my_log_names[level]);
51 if (my_log_flags & MY_LOG_SYSLOG)
52 syslog(level, "%s%s", msg_prefix, msg);
54 if (my_log_flags & MY_LOG_STDOUT)
55 fprintf(stdout, "%s%s\n", msg_prefix, msg);