netatalk: logger.h Source File

netatalk 4.5.1
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
logger.h
Go to the documentation of this file.
1#ifndef _ATALK_LOGGER_H
2#define _ATALK_LOGGER_H 1
3
4#ifdef HAVE_CONFIG_H
5#include "config.h"
6#endif
7
8#include <limits.h>
9#include <stdbool.h>
10#include <stdio.h>
11
12/* logger is used by pam modules */
13#ifndef UAM_MODULE_EXPORT
14#define UAM_MODULE_EXPORT
15#endif
16
17 enum loglevels {
18 log_none,
19 log_severe,
20 log_error,
21 log_warning,
22 log_note,
23 log_info,
24 log_debug,
25 log_debug6,
26 log_debug7,
27 log_debug8,
28 log_debug9,
29 log_maxdebug
30};
31
33 enum logtypes {
34 logtype_default,
35 logtype_logger,
36 logtype_cnid,
37 logtype_afpd,
38 logtype_dsi,
39 logtype_atalkd,
40 logtype_papd,
41 logtype_uams,
42 logtype_fce,
43 logtype_ad,
44 logtype_sl,
45 logtype_end_of_list_marker
46};
47
48
49/* Display Option flags
50 * Redefine these so they don't interfere with syslog
51 * These can be used in standard logging too */
52#define logoption_nsrcinfo 0x04
53/* the following do not work anymore, they're only provided in order to not
54 * break existing source code */
55#define logoption_pid 0x01
56#define logoption_cons 0x02
57#define logoption_ndelay 0x08
58#define logoption_perror 0x20
59#define logoption_nfile 0x40
60#define logoption_nline 0x80
61
62/* Facility codes
63 * Redefine these so they don't interfere with syslog */
64#define logfacility_user (1<<3)
65#define logfacility_mail (2<<3)
66#define logfacility_daemon (3<<3)
67#define logfacility_auth (4<<3)
68#define logfacility_syslog (5<<3)
69#define logfacility_lpr (6<<3)
70#define logfacility_authpriv (10<<3)
71#define logfacility_ftp (11<<3)
72
73/* =========================================================================
74 Structure definitions
75 */
76
77/* Main log config */
78 typedef struct {
79 bool inited;
80 bool syslog_opened;
81 bool console;
82 char processname[16];
83 int syslog_facility;
84 int syslog_display_options;
85} log_config_t;
86
87/* This stores the config and options for one filelog type (e.g. logger, afpd etc.) */
88 typedef struct {
89 bool set;
91 bool syslog;
92 int fd;
93 enum loglevels level;
94 int display_options;
95 bool timestamp_us;
96} logtype_conf_t;
97
98
99/* =========================================================================
100 Global variables
101 */
102
103/* Make config accessible for LOG macro */
104extern log_config_t log_config;
105
106extern UAM_MODULE_EXPORT logtype_conf_t
107 type_configs[logtype_end_of_list_marker];
108
109/* =========================================================================
110 Global function decarations
111 */
112
113void setuplog(const char *loglevel, const char *logfile,
114 const bool log_us_timestamp);
115void set_processname(const char *processname);
116
118void syslog_setup(int loglevel, enum logtypes logtype, int display_options,
119 int facility);
120
122 UAM_MODULE_EXPORT void make_log_entry(enum loglevels loglevel,
123 enum logtypes logtype, const char *file, const bool log_us_timestamp, int line,
124 char *message, ...);
125
126/*
127 * How to write a LOG macro:
128 * http://c-faq.com/cpp/debugmacs.html
129 *
130 * We choose the verbose form in favor of the obfuscated ones, its easier
131 * to parse for human beings and facilitates expanding the macro for
132 * inline checks for debug levels.
133 */
134
135#define LOG_MAX log_info
136
137#ifdef NO_DEBUG
138
139#define LOG(log_level, type, ...) \
140 do { \
141 if (log_level <= LOG_MAX) \
142 if (log_level <= type_configs[type].level) \
143 make_log_entry((log_level), (type), __FILE__, type_configs[type].timestamp_us, __LINE__, __VA_ARGS__); \
144 } while(0)
145
146#else /* ! NO_DEBUG */
147
148#define LOG(log_level, type, ...) \
149 do { \
150 if (log_level <= type_configs[type].level) \
151 make_log_entry((log_level), (type), __FILE__, type_configs[type].timestamp_us, __LINE__, __VA_ARGS__); \
152 } while(0)
153
154#endif /* NO_DEBUG */
155
156#endif /* _ATALK_LOGGER_H */
logtype
logtype
Definition cmd_dbd.h:9
config.h
set_processname
void set_processname(const char *processname)
Definition logger.c:453
type_configs
UAM_MODULE_EXPORT logtype_conf_t type_configs[logtype_end_of_list_marker]
Definition logger.c:90
log_config
log_config_t log_config
Definition logger.c:76
UAM_MODULE_EXPORT
#define UAM_MODULE_EXPORT
Definition logger.h:14
syslog_setup
void syslog_setup(int loglevel, enum logtypes logtype, int display_options, int facility)
Definition logger.c:356
logtypes
logtypes
Definition logger.h:33
logtype_atalkd
@ logtype_atalkd
Definition logger.h:39
logtype_uams
@ logtype_uams
Definition logger.h:41
logtype_cnid
@ logtype_cnid
Definition logger.h:36
logtype_default
@ logtype_default
Definition logger.h:34
logtype_ad
@ logtype_ad
Definition logger.h:43
logtype_end_of_list_marker
@ logtype_end_of_list_marker
Definition logger.h:45
logtype_dsi
@ logtype_dsi
Definition logger.h:38
logtype_logger
@ logtype_logger
Definition logger.h:35
logtype_papd
@ logtype_papd
Definition logger.h:40
logtype_sl
@ logtype_sl
Definition logger.h:44
logtype_fce
@ logtype_fce
Definition logger.h:42
logtype_afpd
@ logtype_afpd
Definition logger.h:37
setuplog
void setuplog(const char *loglevel, const char *logfile, const bool log_us_timestamp)
Definition logger.c:558
make_log_entry
UAM_MODULE_EXPORT void make_log_entry(enum loglevels loglevel, enum logtypes logtype, const char *file, const bool log_us_timestamp, int line, char *message,...)
Definition logger.c:464
loglevels
loglevels
Definition logger.h:17
log_none
@ log_none
Definition logger.h:18
log_maxdebug
@ log_maxdebug
Definition logger.h:29
log_debug9
@ log_debug9
Definition logger.h:28
log_debug7
@ log_debug7
Definition logger.h:26
log_debug8
@ log_debug8
Definition logger.h:27
log_warning
@ log_warning
Definition logger.h:21
log_error
@ log_error
Definition logger.h:20
log_debug6
@ log_debug6
Definition logger.h:25
log_info
@ log_info
Definition logger.h:23
log_severe
@ log_severe
Definition logger.h:19
log_debug
@ log_debug
Definition logger.h:24
log_note
@ log_note
Definition logger.h:22
log_config_t
Definition logger.h:78
log_config_t::processname
char processname[16]
Definition logger.h:82
log_config_t::inited
bool inited
Definition logger.h:79
log_config_t::syslog_facility
int syslog_facility
Definition logger.h:83
log_config_t::console
bool console
Definition logger.h:81
log_config_t::syslog_display_options
int syslog_display_options
Definition logger.h:84
log_config_t::syslog_opened
bool syslog_opened
Definition logger.h:80
logtype_conf_t
Definition logger.h:88
logtype_conf_t::syslog
bool syslog
Definition logger.h:91
logtype_conf_t::level
enum loglevels level
Definition logger.h:93
logtype_conf_t::set
bool set
Definition logger.h:89
logtype_conf_t::fd
int fd
Definition logger.h:92
logtype_conf_t::timestamp_us
bool timestamp_us
Definition logger.h:95
logtype_conf_t::display_options
int display_options
Definition logger.h:94