src/log.h
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--
implement logwatch_filter::format using str_format
21
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
#ifndef LOG_H
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     2
#define LOG_H
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     4
/** @file log.h
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     5
 *
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     6
 * Local logging functions
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     7
 */
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     8
#include "error.h"
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     9
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    10
/**
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    11
 * Log level definitions
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    12
 *
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    13
 * XXX: these names conflict with <syslog.h>
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    14
 */
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    15
enum log_level {
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    16
    LOG_DEBUG,
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    17
    LOG_INFO,
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    18
    LOG_WARN,
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    19
    LOG_ERROR,
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    20
    LOG_FATAL,
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    21
};
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    22
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    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
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    34
 * Log a message with the given level
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    35
 */
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    36
void log_msg (enum log_level level, const char *func, const char *format, ...)
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    37
    __attribute__ ((format (printf, 3, 4)));
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    38
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    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
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    45
 * Shorthand for log_msg
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    46
 */
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    47
#define log_debug(...) log_msg(LOG_DEBUG, __func__, __VA_ARGS__)
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    48
#define log_info(...)  log_msg(LOG_INFO,  __func__, __VA_ARGS__)
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    49
#define log_warn(...)  log_msg(LOG_WARN,  __func__, __VA_ARGS__)
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    50
#define log_error(...) log_msg(LOG_ERROR, __func__, __VA_ARGS__)
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    51
#define log_fatal(...) log_msg(LOG_FATAL, __func__, __VA_ARGS__)
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    52
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    53
/**
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    54
 * Log a message with LOG_ERROR, appending the formatted error code
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    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
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    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
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    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
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    70
118
05b8d5150313 implement fifo (sock_fifo.c) and test_fifo
Tero Marttila <terom@fixme.fi>
parents: 104
diff changeset
    71
/**
21
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    72
 * log_fatal + exit failure
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    73
 */
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    74
#define FATAL(...) do { log_fatal(__VA_ARGS__); exit(EXIT_FAILURE); } while (0)
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    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
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    82
 * log_err_info + exit failure
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    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
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    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
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    91
#endif /* LOG_H */