NeoMutt  2021-10-22-8-g9cb437
Teaching an old dog new tricks
DOXYGEN
logging.h
Go to the documentation of this file.
1 
23 #ifndef MUTT_LIB_LOGGING_H
24 #define MUTT_LIB_LOGGING_H
25 
26 #include <stdbool.h>
27 #include <stdio.h>
28 #include <time.h>
29 #include "queue.h"
30 
35 {
36  LL_PERROR = -3,
37  LL_ERROR = -2,
38  LL_WARNING = -1,
39  LL_MESSAGE = 0,
40  LL_DEBUG1 = 1,
41  LL_DEBUG2 = 2,
42  LL_DEBUG3 = 3,
43  LL_DEBUG4 = 4,
44  LL_DEBUG5 = 5,
45  LL_NOTIFY = 6,
46 
48 };
49 
65 typedef int (*log_dispatcher_t)(time_t stamp, const char *file, int line, const char *function, enum LogLevel level, ...);
66 
68 
72 struct LogLine
73 {
74  time_t time;
75  const char *file;
76  int line;
77  const char *function;
78  enum LogLevel level;
79  char *message;
80  STAILQ_ENTRY(LogLine) entries;
81 };
82 STAILQ_HEAD(LogLineList, LogLine);
83 
84 #define mutt_debug(LEVEL, ...) MuttLogger(0, __FILE__, __LINE__, __func__, LEVEL, __VA_ARGS__)
85 #define mutt_warning(...) MuttLogger(0, __FILE__, __LINE__, __func__, LL_WARNING, __VA_ARGS__)
86 #define mutt_message(...) MuttLogger(0, __FILE__, __LINE__, __func__, LL_MESSAGE, __VA_ARGS__)
87 #define mutt_error(...) MuttLogger(0, __FILE__, __LINE__, __func__, LL_ERROR, __VA_ARGS__)
88 #define mutt_perror(...) MuttLogger(0, __FILE__, __LINE__, __func__, LL_PERROR, __VA_ARGS__)
89 
90 int log_disp_file (time_t stamp, const char *file, int line, const char *function, enum LogLevel level, ...);
91 int log_disp_null (time_t stamp, const char *file, int line, const char *function, enum LogLevel level, ...);
92 int log_disp_queue (time_t stamp, const char *file, int line, const char *function, enum LogLevel level, ...);
93 int log_disp_terminal(time_t stamp, const char *file, int line, const char *function, enum LogLevel level, ...);
94 
95 int log_queue_add(struct LogLine *ll);
96 void log_queue_empty(void);
98 int log_queue_save(FILE *fp);
99 void log_queue_set_max_size(int size);
100 
101 void log_file_close(bool verbose);
102 int log_file_open(bool verbose);
103 bool log_file_running(void);
104 int log_file_set_filename(const char *file, bool verbose);
105 int log_file_set_level(enum LogLevel level, bool verbose);
106 void log_file_set_version(const char *version);
107 
108 #endif /* MUTT_LIB_LOGGING_H */
int log_disp_file(time_t stamp, const char *file, int line, const char *function, enum LogLevel level,...)
Save a log line to a file - Implements log_dispatcher_t -.
Definition: logging.c:246
int log_disp_terminal(time_t stamp, const char *file, int line, const char *function, enum LogLevel level,...)
Save a log line to the terminal - Implements log_dispatcher_t -.
Definition: logging.c:441
log_dispatcher_t MuttLogger
The log dispatcher -.
Definition: logging.c:52
int log_disp_queue(time_t stamp, const char *file, int line, const char *function, enum LogLevel level,...)
Save a log line to an internal queue - Implements log_dispatcher_t -.
Definition: logging.c:400
int log_disp_null(time_t stamp, const char *file, int line, const char *function, enum LogLevel level,...)
Discard log lines - Implements log_dispatcher_t -.
Definition: logging.c:506
int log_file_open(bool verbose)
Start logging to a file.
Definition: logging.c:119
STAILQ_HEAD(LogLineList, LogLine)
void log_queue_empty(void)
Free the contents of the queue.
Definition: logging.c:326
void log_queue_set_max_size(int size)
Set a upper limit for the queue length.
Definition: logging.c:314
int log_file_set_level(enum LogLevel level, bool verbose)
Set the logging level.
Definition: logging.c:175
bool log_file_running(void)
Is the log file running?
Definition: logging.c:230
void log_queue_flush(log_dispatcher_t disp)
Replay the log queue.
Definition: logging.c:348
int(* log_dispatcher_t)(time_t stamp, const char *file, int line, const char *function, enum LogLevel level,...)
Definition: logging.h:65
LogLevel
Names for the Logging Levels.
Definition: logging.h:35
@ LL_DEBUG4
Log at debug level 4.
Definition: logging.h:43
@ LL_ERROR
Log error.
Definition: logging.h:37
@ LL_DEBUG3
Log at debug level 3.
Definition: logging.h:42
@ LL_PERROR
Log perror (using errno)
Definition: logging.h:36
@ LL_DEBUG5
Log at debug level 5.
Definition: logging.h:44
@ LL_WARNING
Log warning.
Definition: logging.h:38
@ LL_MESSAGE
Log informational message.
Definition: logging.h:39
@ LL_DEBUG2
Log at debug level 2.
Definition: logging.h:41
@ LL_DEBUG1
Log at debug level 1.
Definition: logging.h:40
@ LL_NOTIFY
Log of notifications.
Definition: logging.h:45
@ LL_MAX
Definition: logging.h:47
int log_queue_save(FILE *fp)
Save the contents of the queue to a temporary file.
Definition: logging.c:369
void log_file_close(bool verbose)
Close the log file.
Definition: logging.c:98
int log_file_set_filename(const char *file, bool verbose)
Set the filename for the log.
Definition: logging.c:149
int log_queue_add(struct LogLine *ll)
Add a LogLine to the queue.
Definition: logging.c:287
void log_file_set_version(const char *version)
Set the program's version number.
Definition: logging.c:221
A Log line.
Definition: logging.h:73
const char * file
Source file.
Definition: logging.h:75
char * message
Message to be logged.
Definition: logging.h:79
int line
Line number in source file.
Definition: logging.h:76
STAILQ_ENTRY(LogLine) entries
Linked list.
enum LogLevel level
Log level, e.g. LL_DEBUG1.
Definition: logging.h:78
time_t time
Timestamp of the message.
Definition: logging.h:74