NeoMutt  2018-07-16 +2481-68dcde
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 
43 typedef int (*log_dispatcher_t)(time_t stamp, const char *file, int line, const char *function, int level, ...);
44 
46 
51 {
52  LL_PERROR = -3,
53  LL_ERROR = -2,
54  LL_WARNING = -1,
55  LL_MESSAGE = 0,
56  LL_DEBUG1 = 1,
57  LL_DEBUG2 = 2,
58  LL_DEBUG3 = 3,
59  LL_DEBUG4 = 4,
60  LL_DEBUG5 = 5,
61  LL_NOTIFY = 6,
62 
64 };
65 
69 struct LogLine
70 {
71  time_t time;
72  const char *file;
73  int line;
74  const char *function;
75  int level;
76  char *message;
77  STAILQ_ENTRY(LogLine) entries;
78 };
79 STAILQ_HEAD(LogLineList, LogLine);
80 
81 #define mutt_debug(LEVEL, ...) MuttLogger(0, __FILE__, __LINE__, __func__, LEVEL, __VA_ARGS__)
82 #define mutt_warning(...) MuttLogger(0, __FILE__, __LINE__, __func__, LL_WARNING, __VA_ARGS__)
83 #define mutt_message(...) MuttLogger(0, __FILE__, __LINE__, __func__, LL_MESSAGE, __VA_ARGS__)
84 #define mutt_error(...) MuttLogger(0, __FILE__, __LINE__, __func__, LL_ERROR, __VA_ARGS__)
85 #define mutt_perror(...) MuttLogger(0, __FILE__, __LINE__, __func__, LL_PERROR, __VA_ARGS__)
86 
87 int log_disp_file (time_t stamp, const char *file, int line, const char *function, int level, ...);
88 int log_disp_null (time_t stamp, const char *file, int line, const char *function, int level, ...);
89 int log_disp_queue (time_t stamp, const char *file, int line, const char *function, int level, ...);
90 int log_disp_terminal(time_t stamp, const char *file, int line, const char *function, int level, ...);
91 
92 int log_queue_add(struct LogLine *ll);
93 void log_queue_empty(void);
95 int log_queue_save(FILE *fp);
96 void log_queue_set_max_size(int size);
97 
98 void log_file_close(bool verbose);
99 int log_file_open(bool verbose);
100 bool log_file_running(void);
101 int log_file_set_filename(const char *file, bool verbose);
102 int log_file_set_level(int level, bool verbose);
103 void log_file_set_version(const char *version);
104 
105 #endif /* MUTT_LIB_LOGGING_H */
Log at debug level 4.
Definition: logging.h:59
Log error.
Definition: logging.h:53
int level
Log level, e.g. LL_DEBUG1.
Definition: logging.h:75
void log_queue_flush(log_dispatcher_t disp)
Replay the log queue.
Definition: logging.c:356
void log_file_set_version(const char *version)
Set the program&#39;s version number.
Definition: logging.c:220
int log_file_set_level(int level, bool verbose)
Set the logging level.
Definition: logging.c:174
int log_file_set_filename(const char *file, bool verbose)
Set the filename for the log.
Definition: logging.c:148
Log of notifications.
Definition: logging.h:61
void log_queue_set_max_size(int size)
Set a upper limit for the queue length.
Definition: logging.c:322
char * message
Message to be logged.
Definition: logging.h:76
int log_queue_add(struct LogLine *ll)
Add a LogLine to the queue.
Definition: logging.c:295
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:377
Log perror (using errno)
Definition: logging.h:52
Definition: logging.h:63
Log informational message.
Definition: logging.h:55
int log_disp_terminal(time_t stamp, const char *file, int line, const char *function, int level,...)
Save a log line to the terminal - Implements log_dispatcher_t.
Definition: logging.c:449
int line
Line number in source file.
Definition: logging.h:73
STAILQ_HEAD(LogLineList, LogLine)
LogLevel
Names for the Logging Levels.
Definition: logging.h:50
Log at debug level 2.
Definition: logging.h:57
A Log line.
Definition: logging.h:69
log_dispatcher_t MuttLogger
The log dispatcher.
Definition: logging.c:52
const char * line
Definition: common.c:36
int(* log_dispatcher_t)(time_t stamp, const char *file, int line, const char *function, int level,...)
typedef log_dispatcher_t - Prototype for a logging function
Definition: logging.h:43
Log at debug level 1.
Definition: logging.h:56
bool log_file_running(void)
Is the log file running?
Definition: logging.c:229
int log_file_open(bool verbose)
Start logging to a file.
Definition: logging.c:118
void log_queue_empty(void)
Free the contents of the queue.
Definition: logging.c:334
void log_file_close(bool verbose)
Close the log file.
Definition: logging.c:98
time_t time
Timestamp of the message.
Definition: logging.h:71
int log_disp_queue(time_t stamp, const char *file, int line, const char *function, int level,...)
Save a log line to an internal queue - Implements log_dispatcher_t.
Definition: logging.c:408
Log at debug level 5.
Definition: logging.h:60
const char * file
Source file.
Definition: logging.h:72
Log at debug level 3.
Definition: logging.h:58
Log warning.
Definition: logging.h:54
int log_disp_file(time_t stamp, const char *file, int line, const char *function, int level,...)
Save a log line to a file.
Definition: logging.c:254
int log_disp_null(time_t stamp, const char *file, int line, const char *function, int level,...)
Discard log lines - Implements log_dispatcher_t.
Definition: logging.c:513