Simply use the major version of the lib also on MacOS.
[osl.git] / log.h
1 /*
2  * Copyright (C) 1997-2008 Andre Noll <maan@systemlinux.org>
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 /** compute the maximum of \a a and \a b */
27 #define MAX(a,b) ((a) > (b) ? (a) : (b))
28
29 /** debug loglevel, gets really noisy */
30 #define DEBUG 1
31 /** still noisy, but won't fill your disk */
32 #define INFO  2
33 /** normal, but significant event */
34 #define NOTICE 3
35 /** unexpected event that can be handled */
36 #define WARNING 4
37 /** unhandled error condition */
38 #define ERROR 5
39 /** system might be unreliable */
40 #define CRIT 6
41 /** last message before exit */
42 #define EMERG 7
43
44 /** Log messages with lower priority than that will not be compiled in. */
45 #define COMPILE_TIME_LOGLEVEL 0
46
47 /** \cond */
48 #if DEBUG > COMPILE_TIME_LOGLEVEL
49 #define DEBUG_LOG(f,...) __log(DEBUG, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
50 #else
51 #define DEBUG_LOG(...) do {;} while (0)
52 #endif
53
54 #if INFO > COMPILE_TIME_LOGLEVEL
55 #define INFO_LOG(f,...) __log(INFO, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
56 #else
57 #define INFO_LOG(...) do {;} while (0)
58 #endif
59
60 #if NOTICE > COMPILE_TIME_LOGLEVEL
61 #define NOTICE_LOG(f,...) __log(NOTICE, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
62 #else
63 #define NOTICE_LOG(...) do {;} while (0)
64 #endif
65
66 #if WARNING > COMPILE_TIME_LOGLEVEL
67 #define WARNING_LOG(f,...) __log(WARNING, "%s: " f, __FUNCTION__, ##  __VA_ARGS__)
68 #else
69 #define WARNING_LOG(...) do {;} while (0)
70 #endif
71
72 #if ERROR > COMPILE_TIME_LOGLEVEL
73 #define ERROR_LOG(f,...) __log(ERROR, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
74 #else
75 #define ERROR_LOG(...) do {;} while (0)
76 #endif
77
78 #if CRIT > COMPILE_TIME_LOGLEVEL
79 #define CRIT_LOG(f,...) __log(CRIT, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
80 #else
81 #define CRIT_LOG(...) do {;} while (0)
82 #endif
83
84 #if EMERG > COMPILE_TIME_LOGLEVEL
85 #define EMERG_LOG(f,...) __log(EMERG, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
86 #else
87 #define EMERG_LOG(...)
88 #endif
89 /** \endcond */
90
91 __printf_2_3 void __log(int, const char*, ...);