author | Tero Marttila <terom@fixme.fi> |
Sat, 11 Apr 2009 06:03:24 +0300 | |
changeset 130 | ffefb6d85ea6 |
parent 118 | 05b8d5150313 |
child 137 | c607c357c486 |
permissions | -rw-r--r-- |
21 | 1 |
#ifndef LOG_H |
2 |
#define LOG_H |
|
3 |
||
4 |
/** @file log.h |
|
5 |
* |
|
6 |
* Local logging functions |
|
7 |
*/ |
|
8 |
#include "error.h" |
|
9 |
||
10 |
/** |
|
11 |
* Log level definitions |
|
12 |
* |
|
13 |
* XXX: these names conflict with <syslog.h> |
|
14 |
*/ |
|
15 |
enum log_level { |
|
16 |
LOG_DEBUG, |
|
17 |
LOG_INFO, |
|
18 |
LOG_WARN, |
|
19 |
LOG_ERROR, |
|
20 |
LOG_FATAL, |
|
21 |
}; |
|
22 |
||
23 |
/** |
|
104
fc196bb4bcc2
implement lua_log and lua_log_level
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
24 |
* List of log_level values as strings, NULL-terminated |
fc196bb4bcc2
implement lua_log and lua_log_level
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
25 |
*/ |
fc196bb4bcc2
implement lua_log and lua_log_level
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
26 |
extern const char *log_level_names[]; |
fc196bb4bcc2
implement lua_log and lua_log_level
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
27 |
|
fc196bb4bcc2
implement lua_log and lua_log_level
Tero Marttila <terom@fixme.fi>
parents:
73
diff
changeset
|
28 |
/** |
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
29 |
* The default log level |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
30 |
*/ |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
31 |
#define LOG_LEVEL_DEFAULT LOG_INFO |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
32 |
|
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
33 |
/** |
21 | 34 |
* Log a message with the given level |
35 |
*/ |
|
36 |
void log_msg (enum log_level level, const char *func, const char *format, ...) |
|
37 |
__attribute__ ((format (printf, 3, 4))); |
|
38 |
||
39 |
/** |
|
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
40 |
* Set the current log level to filter out messages below the given level |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
41 |
*/ |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
42 |
void set_log_level (enum log_level level); |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
43 |
|
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
44 |
/** |
21 | 45 |
* Shorthand for log_msg |
46 |
*/ |
|
47 |
#define log_debug(...) log_msg(LOG_DEBUG, __func__, __VA_ARGS__) |
|
48 |
#define log_info(...) log_msg(LOG_INFO, __func__, __VA_ARGS__) |
|
49 |
#define log_warn(...) log_msg(LOG_WARN, __func__, __VA_ARGS__) |
|
50 |
#define log_error(...) log_msg(LOG_ERROR, __func__, __VA_ARGS__) |
|
51 |
#define log_fatal(...) log_msg(LOG_FATAL, __func__, __VA_ARGS__) |
|
52 |
||
53 |
/** |
|
54 |
* Log a message with LOG_ERROR, appending the formatted error code |
|
55 |
*/ |
|
22
c339c020fd33
add missing irc_cmd.h, and modify line_proto/irc_conn to use log
Tero Marttila <terom@fixme.fi>
parents:
21
diff
changeset
|
56 |
void _log_err (enum log_level level, err_t err, const char *func, const char *format, ...) |
c339c020fd33
add missing irc_cmd.h, and modify line_proto/irc_conn to use log
Tero Marttila <terom@fixme.fi>
parents:
21
diff
changeset
|
57 |
__attribute__ ((format (printf, 4, 5))); |
21 | 58 |
|
22
c339c020fd33
add missing irc_cmd.h, and modify line_proto/irc_conn to use log
Tero Marttila <terom@fixme.fi>
parents:
21
diff
changeset
|
59 |
void _log_err_info (enum log_level level, struct error_info *err, const char *func, const char *format, ...) |
c339c020fd33
add missing irc_cmd.h, and modify line_proto/irc_conn to use log
Tero Marttila <terom@fixme.fi>
parents:
21
diff
changeset
|
60 |
__attribute__ ((format (printf, 4, 5))); |
21 | 61 |
|
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
104
diff
changeset
|
62 |
/** |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
104
diff
changeset
|
63 |
* Log using errno. |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
104
diff
changeset
|
64 |
*/ |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
104
diff
changeset
|
65 |
void _log_perr (enum log_level level, const char *func, const char *format, ...) |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
104
diff
changeset
|
66 |
__attribute__ ((format (printf, 3, 4))); |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
104
diff
changeset
|
67 |
|
22
c339c020fd33
add missing irc_cmd.h, and modify line_proto/irc_conn to use log
Tero Marttila <terom@fixme.fi>
parents:
21
diff
changeset
|
68 |
#define log_err(err, ...) _log_err(LOG_ERROR, err, __func__, __VA_ARGS__) |
c339c020fd33
add missing irc_cmd.h, and modify line_proto/irc_conn to use log
Tero Marttila <terom@fixme.fi>
parents:
21
diff
changeset
|
69 |
#define log_err_info(err_info, ...) _log_err_info(LOG_ERROR, err_info, __func__, __VA_ARGS__) |
21 | 70 |
|
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
104
diff
changeset
|
71 |
/** |
21 | 72 |
* log_fatal + exit failure |
73 |
*/ |
|
74 |
#define FATAL(...) do { log_fatal(__VA_ARGS__); exit(EXIT_FAILURE); } while (0) |
|
75 |
||
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
104
diff
changeset
|
76 |
/** |
22
c339c020fd33
add missing irc_cmd.h, and modify line_proto/irc_conn to use log
Tero Marttila <terom@fixme.fi>
parents:
21
diff
changeset
|
77 |
* log_err + exit failure |
c339c020fd33
add missing irc_cmd.h, and modify line_proto/irc_conn to use log
Tero Marttila <terom@fixme.fi>
parents:
21
diff
changeset
|
78 |
*/ |
c339c020fd33
add missing irc_cmd.h, and modify line_proto/irc_conn to use log
Tero Marttila <terom@fixme.fi>
parents:
21
diff
changeset
|
79 |
#define FATAL_ERR(err_code, ...) do { _log_err(LOG_FATAL, err_code, __func__, __VA_ARGS__); exit(EXIT_FAILURE); } while (0) |
c339c020fd33
add missing irc_cmd.h, and modify line_proto/irc_conn to use log
Tero Marttila <terom@fixme.fi>
parents:
21
diff
changeset
|
80 |
|
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
104
diff
changeset
|
81 |
/** |
21 | 82 |
* log_err_info + exit failure |
83 |
*/ |
|
22
c339c020fd33
add missing irc_cmd.h, and modify line_proto/irc_conn to use log
Tero Marttila <terom@fixme.fi>
parents:
21
diff
changeset
|
84 |
#define FATAL_ERROR(err_info, ...) do { _log_err_info(LOG_FATAL, err_info, __func__, __VA_ARGS__); exit(EXIT_FAILURE); } while (0) |
21 | 85 |
|
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
104
diff
changeset
|
86 |
/** |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
104
diff
changeset
|
87 |
* log_perr + exit failure |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
104
diff
changeset
|
88 |
*/ |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
104
diff
changeset
|
89 |
#define FATAL_PERROR(...) do { _log_perr(LOG_FATAL, __func__, __VA_ARGS__); exit(EXIT_FAILURE); } while (0) |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
104
diff
changeset
|
90 |
|
21 | 91 |
#endif /* LOG_H */ |