]> git.ipfire.org Git - thirdparty/chrony.git/blame - logging.h
conf: rework allow/deny parser
[thirdparty/chrony.git] / logging.h
CommitLineData
88840341 1/*
88840341
RC
2 chronyd/chronyc - Programs for keeping computer clocks accurate.
3
4 **********************************************************************
5 * Copyright (C) Richard P. Curnow 1997-2002
33967780 6 * Copyright (C) Miroslav Lichvar 2013-2015
88840341
RC
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
8e23110a 19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
88840341
RC
20 *
21 **********************************************************************
22
23 =======================================================================
24
25 Header file for diagnostic logging module
26
27 */
28
29#ifndef GOT_LOGGING_H
30#define GOT_LOGGING_H
31
584bf938
ML
32#include "sysincl.h"
33
cd7bfa25
ML
34/* Line logging macros. If the compiler is GNU C, we take advantage of
35 being able to get the function name also. */
36
37#ifdef __GNUC__
38#define FUNCTION_NAME __FUNCTION__
f88e9659 39#define FORMAT_ATTRIBUTE_PRINTF(str, first) __attribute__ ((format (printf, str, first)))
cd7bfa25
ML
40#else
41#define FUNCTION_NAME ""
f88e9659 42#define FORMAT_ATTRIBUTE_PRINTF(str, first)
cd7bfa25
ML
43#endif
44
7b2430fc 45#if DEBUG > 0
f282856c
ML
46#define LOG_MESSAGE(severity, ...) \
47 LOG_Message(severity, __LINE__, __FILE__, FUNCTION_NAME, __VA_ARGS__)
7b2430fc 48#else
f282856c 49#define LOG_MESSAGE(severity, ...) \
aeb57a36 50 LOG_Message(severity, __VA_ARGS__)
7b2430fc
ML
51#endif
52
f282856c 53#define DEBUG_LOG(...) \
4bbc5520 54 do { \
1227873b 55 if (DEBUG && log_min_severity == LOGS_DEBUG) \
f282856c 56 LOG_MESSAGE(LOGS_DEBUG, __VA_ARGS__); \
4bbc5520 57 } while (0)
7b2430fc 58
f282856c 59#define LOG_FATAL(...) \
51a2b436 60 do { \
f282856c 61 LOG_MESSAGE(LOGS_FATAL, __VA_ARGS__); \
51a2b436
ML
62 exit(1); \
63 } while (0)
cd7bfa25 64
f282856c 65#define LOG(severity, ...) LOG_MESSAGE(severity, __VA_ARGS__)
7b2430fc 66
88840341
RC
67/* Definition of severity */
68typedef enum {
1227873b
ML
69 LOGS_DEBUG = -1,
70 LOGS_INFO = 0,
88840341 71 LOGS_WARN,
cd7bfa25 72 LOGS_ERR,
4bbc5520 73 LOGS_FATAL,
88840341
RC
74} LOG_Severity;
75
1227873b
ML
76/* Minimum severity of messages to be logged */
77extern LOG_Severity log_min_severity;
78
88840341
RC
79/* Init function */
80extern void LOG_Initialise(void);
81
82/* Fini function */
83extern void LOG_Finalise(void);
84
85/* Line logging function */
7b2430fc 86#if DEBUG > 0
f282856c
ML
87FORMAT_ATTRIBUTE_PRINTF(5, 6)
88extern void LOG_Message(LOG_Severity severity, int line_number, const char *filename,
cd7bfa25 89 const char *function_name, const char *format, ...);
7b2430fc
ML
90#else
91FORMAT_ATTRIBUTE_PRINTF(2, 3)
92extern void LOG_Message(LOG_Severity severity, const char *format, ...);
93#endif
88840341 94
1227873b
ML
95/* Set the minimum severity of a message to be logged or printed to terminal.
96 If the severity is LOGS_DEBUG and DEBUG is enabled, all messages will be
97 prefixed with the filename, line number, and function name. */
98extern void LOG_SetMinSeverity(LOG_Severity severity);
4bbc5520 99
51d77d6c
ML
100/* Get the minimum severity */
101extern LOG_Severity LOG_GetMinSeverity(void);
102
103/* Set a prefix for debug messages */
104extern void LOG_SetDebugPrefix(const char *prefix);
105
eb8c9ad6 106/* Log messages to a file instead of stderr, or stderr again if NULL */
6cbeb107
ML
107extern void LOG_OpenFileLog(const char *log_file);
108
fe4b661f
ML
109/* Log messages to syslog instead of stderr */
110extern void LOG_OpenSystemLog(void);
88840341 111
7b98443a 112/* Stop using stderr and send fatal message to the foreground process */
1d2a0856
ML
113extern void LOG_SetParentFd(int fd);
114
115/* Close the pipe to the foreground process so it can exit */
116extern void LOG_CloseParentFd(void);
117
e78e65ef
ML
118/* File logging functions */
119
120typedef int LOG_FileID;
121
122extern LOG_FileID LOG_FileOpen(const char *name, const char *banner);
f88e9659
ML
123
124FORMAT_ATTRIBUTE_PRINTF(2, 3)
e78e65ef
ML
125extern void LOG_FileWrite(LOG_FileID id, const char *format, ...);
126
e78e65ef
ML
127extern void LOG_CycleLogFiles(void);
128
88840341 129#endif /* GOT_LOGGING_H */