NeoMutt  2021-02-05-666-ge300cd
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 
66 typedef int (*log_dispatcher_t)(time_t stamp, const char *file, int line, const char *function, enum LogLevel level, ...);
67 
69 
73 struct LogLine
74 {
75  time_t time;
76  const char *file;
77  int line;
78  const char *function;
79  enum LogLevel level;
80  char *message;
81  STAILQ_ENTRY(LogLine) entries;
82 };
83 STAILQ_HEAD(LogLineList, LogLine);
84 
85 #define mutt_debug(LEVEL, ...) MuttLogger(0, __FILE__, __LINE__, __func__, LEVEL, __VA_ARGS__)
86 #define mutt_warning(...) MuttLogger(0, __FILE__, __LINE__, __func__, LL_WARNING, __VA_ARGS__)
87 #define mutt_message(...) MuttLogger(0, __FILE__, __LINE__, __func__, LL_MESSAGE, __VA_ARGS__)
88 #define mutt_error(...) MuttLogger(0, __FILE__, __LINE__, __func__, LL_ERROR, __VA_ARGS__)
89 #define mutt_perror(...) MuttLogger(0, __FILE__, __LINE__, __func__, LL_PERROR, __VA_ARGS__)
90 
91 int log_disp_file (time_t stamp, const char *file, int line, const char *function, enum LogLevel level, ...);
92 int log_disp_null (time_t stamp, const char *file, int line, const char *function, enum LogLevel level, ...);
93 int log_disp_queue (time_t stamp, const char *file, int line, const char *function, enum LogLevel level, ...);
94 int log_disp_terminal(time_t stamp, const char *file, int line, const char *function, enum LogLevel level, ...);
95 
96 int log_queue_add(struct LogLine *ll);
97 void log_queue_empty(void);
99 int log_queue_save(FILE *fp);
100 void log_queue_set_max_size(int size);
101 
102 void log_file_close(bool verbose);
103 int log_file_open(bool verbose);
104 bool log_file_running(void);
105 int log_file_set_filename(const char *file, bool verbose);
106 int log_file_set_level(enum LogLevel level, bool verbose);
107 void log_file_set_version(const char *version);
108 
109 #endif /* MUTT_LIB_LOGGING_H */
Log at debug level 4.
Definition: logging.h:43
Log error.
Definition: logging.h:37
void log_queue_flush(log_dispatcher_t disp)
Replay the log queue.
Definition: logging.c:348
void log_file_set_version(const char *version)
Set the program&#39;s version number.
Definition: logging.c:221
int log_file_set_filename(const char *file, bool verbose)
Set the filename for the log.
Definition: logging.c:149
enum LogLevel level
Log level, e.g. LL_DEBUG1.
Definition: logging.h:79
Log of notifications.
Definition: logging.h:45
void log_queue_set_max_size(int size)
Set a upper limit for the queue length.
Definition: logging.c:314
char * message
Message to be logged.
Definition: logging.h:80
int log_queue_add(struct LogLine *ll)
Add a LogLine to the queue.
Definition: logging.c:287
STAILQ_ENTRY(LogLine) entries
Linked list.
int log_queue_save(FILE *fp)
Save the contents of the queue to a temporary file.
Definition: logging.c:369
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 -This log dispatcher saves a line ...
Definition: logging.c:400
Log perror (using errno)
Definition: logging.h:36
log_dispatcher_t MuttLogger
The log dispatcher -This function pointer controls where log messages are redirected.
Definition: logging.c:52
Definition: logging.h:47
Log informational message.
Definition: logging.h:39
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 line
Line number in source file.
Definition: logging.h:77
STAILQ_HEAD(LogLineList, LogLine)
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 -This log dispatcher saves a line of text to ...
Definition: logging.c:246
LogLevel
Names for the Logging Levels.
Definition: logging.h:34
Log at debug level 2.
Definition: logging.h:41
A Log line.
Definition: logging.h:73
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 -This log dispatcher saves a line of te...
Definition: logging.c:441
int log_file_set_level(enum LogLevel level, bool verbose)
Set the logging level.
Definition: logging.c:175
Log at debug level 1.
Definition: logging.h:40
int(* log_dispatcher_t)(time_t stamp, const char *file, int line, const char *function, enum LogLevel level,...)
Definition: logging.h:66
bool log_file_running(void)
Is the log file running?
Definition: logging.c:230
int log_file_open(bool verbose)
Start logging to a file.
Definition: logging.c:119
void log_queue_empty(void)
Free the contents of the queue.
Definition: logging.c:326
void log_file_close(bool verbose)
Close the log file.
Definition: logging.c:98
time_t time
Timestamp of the message.
Definition: logging.h:75
Log at debug level 5.
Definition: logging.h:44
const char * file
Source file.
Definition: logging.h:76
Log at debug level 3.
Definition: logging.h:42
Log warning.
Definition: logging.h:38