Merge branch 'refs/heads/t/lopsub'
[osl.git] / log.h
1 /*
2 * Copyright (C) 1997-2009 Andre Noll <maan@tuebingen.mpg.de>
3 *
4 * Licensed under the GPL v2. For licencing details see COPYING.
5 */
6
7 #include <sys/stat.h>
8 #include <fcntl.h>
9 #include <sys/wait.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <time.h> /* time(), localtime() */
13 #include <unistd.h>
14 #include <errno.h>
15 #include <limits.h>
16 #include <stdarg.h>
17 #include <ctype.h>
18 #include <netinet/in.h>
19 #include <arpa/inet.h>
20 #include <sys/socket.h>
21 #include <sys/un.h> /* needed by create_pf_socket */
22 #include <string.h>
23 #include <assert.h>
24 #include "gcc-compat.h"
25
26 /** debug loglevel, gets really noisy */
27 #define DEBUG 1
28 /** still noisy, but won't fill your disk */
29 #define INFO 2
30 /** normal, but significant event */
31 #define NOTICE 3
32 /** unexpected event that can be handled */
33 #define WARNING 4
34 /** unhandled error condition */
35 #define ERROR 5
36 /** system might be unreliable */
37 #define CRIT 6
38 /** last message before exit */
39 #define EMERG 7
40
41 /** Log messages with lower priority than that will not be compiled in. */
42 #define COMPILE_TIME_LOGLEVEL 0
43
44 /** \cond */
45 #if DEBUG > COMPILE_TIME_LOGLEVEL
46 #define DEBUG_LOG(f,...) __log(DEBUG, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
47 #else
48 #define DEBUG_LOG(...) do {;} while (0)
49 #endif
50
51 #if INFO > COMPILE_TIME_LOGLEVEL
52 #define INFO_LOG(f,...) __log(INFO, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
53 #else
54 #define INFO_LOG(...) do {;} while (0)
55 #endif
56
57 #if NOTICE > COMPILE_TIME_LOGLEVEL
58 #define NOTICE_LOG(f,...) __log(NOTICE, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
59 #else
60 #define NOTICE_LOG(...) do {;} while (0)
61 #endif
62
63 #if WARNING > COMPILE_TIME_LOGLEVEL
64 #define WARNING_LOG(f,...) __log(WARNING, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
65 #else
66 #define WARNING_LOG(...) do {;} while (0)
67 #endif
68
69 #if ERROR > COMPILE_TIME_LOGLEVEL
70 #define ERROR_LOG(f,...) __log(ERROR, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
71 #else
72 #define ERROR_LOG(...) do {;} while (0)
73 #endif
74
75 #if CRIT > COMPILE_TIME_LOGLEVEL
76 #define CRIT_LOG(f,...) __log(CRIT, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
77 #else
78 #define CRIT_LOG(...) do {;} while (0)
79 #endif
80
81 #if EMERG > COMPILE_TIME_LOGLEVEL
82 #define EMERG_LOG(f,...) __log(EMERG, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
83 #else
84 #define EMERG_LOG(...)
85 #endif
86 /** \endcond */
87
88 __printf_2_3 void __log(int, const char*, ...);