author | Tero Marttila <terom@fixme.fi> |
Sun, 03 May 2009 17:14:09 +0300 | |
branch | new-transport |
changeset 162 | fa8dc83739e2 |
parent 156 | 6534a4ac957b |
child 172 | ea4972e51fa3 |
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 |
/** |
137
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
34 |
* Maximum length of a log message, including terminating NUL |
21 | 35 |
*/ |
137
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
36 |
#define LOG_MSG_MAX 1024 |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
37 |
|
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
38 |
/** |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
39 |
* Log output function, for displaying a line of text, without any trailing newline. |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
40 |
*/ |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
41 |
typedef void (*log_output_func) (const char *line, void *arg); |
21 | 42 |
|
43 |
/** |
|
73
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
44 |
* 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
|
45 |
*/ |
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
46 |
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
|
47 |
|
2780a73c71f3
add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
48 |
/** |
137
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
49 |
* Set the current log output function, replacing any default or previous value. |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
50 |
* |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
51 |
* Pass in func as NULL to revert to the default handler. |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
52 |
*/ |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
53 |
void log_set_func (log_output_func func, void *arg); |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
54 |
|
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
55 |
/** |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
56 |
* Log a message with the given level |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
57 |
*/ |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
58 |
void log_msg (enum log_level level, const char *func, const char *format, ...) |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
59 |
__attribute__ ((format (printf, 3, 4))); |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
60 |
|
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
61 |
/** |
21 | 62 |
* Shorthand for log_msg |
63 |
*/ |
|
64 |
#define log_debug(...) log_msg(LOG_DEBUG, __func__, __VA_ARGS__) |
|
65 |
#define log_info(...) log_msg(LOG_INFO, __func__, __VA_ARGS__) |
|
66 |
#define log_warn(...) log_msg(LOG_WARN, __func__, __VA_ARGS__) |
|
67 |
#define log_error(...) log_msg(LOG_ERROR, __func__, __VA_ARGS__) |
|
68 |
#define log_fatal(...) log_msg(LOG_FATAL, __func__, __VA_ARGS__) |
|
69 |
||
70 |
/** |
|
137
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
71 |
* Log a message with the given level, appending the formatted error code name |
21 | 72 |
*/ |
139
55b9dcc2b73a
implement sock_ssl_connect_async (the old sock_ssl_connect exists no more)
Tero Marttila <terom@fixme.fi>
parents:
137
diff
changeset
|
73 |
void _log_err_code (enum log_level level, err_t err, const char *func, const char *format, ...) |
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
|
74 |
__attribute__ ((format (printf, 4, 5))); |
21 | 75 |
|
137
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
76 |
/** |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
77 |
* Log a message with the given level, appending the formatted error message |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
78 |
*/ |
156
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
139
diff
changeset
|
79 |
void _log_err (enum log_level level, const error_t *err, const char *func, const char *format, ...) |
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
|
80 |
__attribute__ ((format (printf, 4, 5))); |
21 | 81 |
|
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
104
diff
changeset
|
82 |
/** |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
104
diff
changeset
|
83 |
* Log using errno. |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
104
diff
changeset
|
84 |
*/ |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
104
diff
changeset
|
85 |
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
|
86 |
__attribute__ ((format (printf, 3, 4))); |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
104
diff
changeset
|
87 |
|
137
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
88 |
/** |
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
89 |
* Shorthand for _log_* |
139
55b9dcc2b73a
implement sock_ssl_connect_async (the old sock_ssl_connect exists no more)
Tero Marttila <terom@fixme.fi>
parents:
137
diff
changeset
|
90 |
* |
55b9dcc2b73a
implement sock_ssl_connect_async (the old sock_ssl_connect exists no more)
Tero Marttila <terom@fixme.fi>
parents:
137
diff
changeset
|
91 |
* XXX: kill log_err_info, add log_err_code |
137
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
92 |
*/ |
139
55b9dcc2b73a
implement sock_ssl_connect_async (the old sock_ssl_connect exists no more)
Tero Marttila <terom@fixme.fi>
parents:
137
diff
changeset
|
93 |
#define log_err(err_code, ...) _log_err_code(LOG_ERROR, err_code, __func__, __VA_ARGS__) |
55b9dcc2b73a
implement sock_ssl_connect_async (the old sock_ssl_connect exists no more)
Tero Marttila <terom@fixme.fi>
parents:
137
diff
changeset
|
94 |
#define log_err_info(err_info, ...) _log_err(LOG_ERROR, err_info, __func__, __VA_ARGS__) |
137
c607c357c486
implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents:
118
diff
changeset
|
95 |
#define log_perr(...) _log_perr(LOG_ERROR, __func__, __VA_ARGS__) |
21 | 96 |
|
139
55b9dcc2b73a
implement sock_ssl_connect_async (the old sock_ssl_connect exists no more)
Tero Marttila <terom@fixme.fi>
parents:
137
diff
changeset
|
97 |
#define log_warn_err_code(err_code, ...) _log_err_code(LOG_WARN, err_code, __func__, __VA_ARGS__) |
55b9dcc2b73a
implement sock_ssl_connect_async (the old sock_ssl_connect exists no more)
Tero Marttila <terom@fixme.fi>
parents:
137
diff
changeset
|
98 |
#define log_warn_err(err_info, ...) _log_err(LOG_WARN, err_info, __func__, __VA_ARGS__) |
55b9dcc2b73a
implement sock_ssl_connect_async (the old sock_ssl_connect exists no more)
Tero Marttila <terom@fixme.fi>
parents:
137
diff
changeset
|
99 |
|
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
104
diff
changeset
|
100 |
/** |
21 | 101 |
* log_fatal + exit failure |
102 |
*/ |
|
162
fa8dc83739e2
replace exit(EXIT_FAILURE) with abort() in FATAL_*
Tero Marttila <terom@fixme.fi>
parents:
156
diff
changeset
|
103 |
#define FATAL(...) do { log_fatal(__VA_ARGS__); abort(); } while (0) |
21 | 104 |
|
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
104
diff
changeset
|
105 |
/** |
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
|
106 |
* 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
|
107 |
*/ |
162
fa8dc83739e2
replace exit(EXIT_FAILURE) with abort() in FATAL_*
Tero Marttila <terom@fixme.fi>
parents:
156
diff
changeset
|
108 |
#define FATAL_ERR(err_code, ...) do { _log_err_code(LOG_FATAL, err_code, __func__, __VA_ARGS__); abort(); } while (0) |
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
|
109 |
|
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
104
diff
changeset
|
110 |
/** |
21 | 111 |
* log_err_info + exit failure |
112 |
*/ |
|
162
fa8dc83739e2
replace exit(EXIT_FAILURE) with abort() in FATAL_*
Tero Marttila <terom@fixme.fi>
parents:
156
diff
changeset
|
113 |
#define FATAL_ERROR(err_info, ...) do { _log_err(LOG_FATAL, err_info, __func__, __VA_ARGS__); abort(); } while (0) |
21 | 114 |
|
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
104
diff
changeset
|
115 |
/** |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
104
diff
changeset
|
116 |
* log_perr + exit failure |
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
104
diff
changeset
|
117 |
*/ |
162
fa8dc83739e2
replace exit(EXIT_FAILURE) with abort() in FATAL_*
Tero Marttila <terom@fixme.fi>
parents:
156
diff
changeset
|
118 |
#define FATAL_PERROR(...) do { _log_perr(LOG_FATAL, __func__, __VA_ARGS__); abort(); } while (0) |
118
05b8d5150313
implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents:
104
diff
changeset
|
119 |
|
21 | 120 |
#endif /* LOG_H */ |