Must use (void) instead of () for function declarations.
[lwes-journaller.git] / src / log.c
blobb0b3032389de07839fb569d3ac0746d7f4935808
1 /*======================================================================*
2 * Copyright (C) 2008 Light Weight Event System *
3 * All rights reserved. *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
18 * Boston, MA 02110-1301 USA. *
19 *======================================================================*/
21 #include "config.h"
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <stdarg.h>
26 #include <unistd.h>
27 #include <string.h>
28 #include "log.h"
29 #include "opt.h"
31 void log_msg(int level, const char* fname, int lineno, const char* format, ...) {
32 char buf[1024];
33 va_list ap;
35 /* check for illegal logging level */
36 if(level <= 0)
38 printf ("logging level <= 0\n");
39 return;
42 /* check for ignored message logging level */
43 if((level & arg_log_level) == 0)
45 return;
48 va_start(ap, format);
49 vsnprintf(buf, sizeof(buf), format, ap);
50 va_end(ap);
52 fprintf(stdout, "%s:%d : %s", fname, lineno, buf);
55 void log_get_level_string(char* str, int len)
57 *str = '\0';
59 if ( LOG_MASK_ERROR & arg_log_level )
61 strncat(str, "ERROR ", len - strlen(str));
64 if ( LOG_MASK_WARNING & arg_log_level )
66 strncat(str, "WARNING ", len - strlen(str));
69 if ( LOG_MASK_INFO & arg_log_level )
71 strncat(str, "INFO ", len - strlen(str));
74 if ( LOG_MASK_PROGRESS & arg_log_level )
76 strncat(str, "PROGRESS ", len - strlen(str));
79 str[len - 1] = '\0';