Logging Dispatcher. More...
#include "config.h"
#include <errno.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "date.h"
#include "file.h"
#include "logging2.h"
#include "memory.h"
#include "message.h"
#include "queue.h"
#include "string2.h"
Go to the source code of this file.
Functions | |
static const char * | timestamp (time_t stamp) |
Create a YYYY-MM-DD HH:MM:SS timestamp. | |
void | log_file_close (bool verbose) |
Close the log file. | |
int | log_file_open (bool verbose) |
Start logging to a file. | |
int | log_file_set_filename (const char *file, bool verbose) |
Set the filename for the log. | |
int | log_file_set_level (enum LogLevel level, bool verbose) |
Set the logging level. | |
void | log_file_set_version (const char *version) |
Set the program's version number. | |
bool | log_file_running (void) |
Is the log file running? | |
int | log_disp_file (time_t stamp, const char *file, int line, const char *function, enum LogLevel level, const char *format,...) |
Save a log line to a file - Implements log_dispatcher_t -. | |
int | log_queue_add (struct LogLine *ll) |
Add a LogLine to the queue. | |
void | log_queue_set_max_size (int size) |
Set a upper limit for the queue length. | |
void | log_queue_empty (void) |
Free the contents of the queue. | |
void | log_queue_flush (log_dispatcher_t disp) |
Replay the log queue. | |
const struct LogLineList | log_queue_get (void) |
Get the Log Queue. | |
int | log_disp_queue (time_t stamp, const char *file, int line, const char *function, enum LogLevel level, const char *format,...) |
Save a log line to an internal queue - Implements log_dispatcher_t -. | |
int | log_disp_terminal (time_t stamp, const char *file, int line, const char *function, enum LogLevel level, const char *format,...) |
Save a log line to the terminal - Implements log_dispatcher_t -. | |
void | log_multiline_full (enum LogLevel level, const char *str, const char *file, int line, const char *func) |
Helper to dump multiline text to the log. | |
Variables | |
const char * | LogLevelAbbr = "PEWM12345N" |
Abbreviations of logging level names. | |
log_dispatcher_t | MuttLogger = log_disp_terminal |
The log dispatcher -. | |
static FILE * | LogFileFP = NULL |
Log file handle. | |
static char * | LogFileName = NULL |
Log file name. | |
static int | LogFileLevel = 0 |
Log file level. | |
static char * | LogFileVersion = NULL |
Program version. | |
static struct LogLineList | LogQueue = STAILQ_HEAD_INITIALIZER(LogQueue) |
In-memory list of log lines. | |
static int | LogQueueCount = 0 |
Number of entries currently in the log queue. | |
static int | LogQueueMax = 0 |
Maximum number of entries in the log queue. | |
Logging Dispatcher.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Definition in file logging.c.
|
static |
Create a YYYY-MM-DD HH:MM:SS timestamp.
stamp | Unix time |
ptr | Timestamp string |
If stamp is 0, then the current time will be used.
Definition at line 78 of file logging.c.
void log_file_close | ( | bool | verbose | ) |
Close the log file.
verbose | If true, then log the event |
Definition at line 99 of file logging.c.
int log_file_open | ( | bool | verbose | ) |
Start logging to a file.
verbose | If true, then log the event |
0 | Success |
-1 | Error, see errno |
Before opening a log file, call log_file_set_version(), log_file_set_level() and log_file_set_filename().
Definition at line 120 of file logging.c.
int log_file_set_filename | ( | const char * | file, |
bool | verbose | ||
) |
Set the filename for the log.
file | Name to use |
verbose | If true, then log the event |
0 | Success, file opened |
-1 | Error, see errno |
Definition at line 150 of file logging.c.
int log_file_set_level | ( | enum LogLevel | level, |
bool | verbose | ||
) |
Set the logging level.
level | Logging level |
verbose | If true, then log the event |
0 | Success |
-1 | Error, level is out of range |
The level should be: LL_MESSAGE <= level < LL_MAX.
Definition at line 176 of file logging.c.
void log_file_set_version | ( | const char * | version | ) |
bool log_file_running | ( | void | ) |
int log_queue_add | ( | struct LogLine * | ll | ) |
Add a LogLine to the queue.
ll | LogLine to add |
num | Entries in the queue |
If LogQueueMax is non-zero, the queue will be limited to this many items.
Definition at line 286 of file logging.c.
void log_queue_set_max_size | ( | int | size | ) |
void log_queue_empty | ( | void | ) |
Free the contents of the queue.
Free any log lines in the queue.
Definition at line 325 of file logging.c.
void log_queue_flush | ( | log_dispatcher_t | disp | ) |
Replay the log queue.
disp | Log dispatcher - Implements log_dispatcher_t |
Pass all of the log entries in the queue to the log dispatcher provided. The queue will be emptied afterwards.
Definition at line 347 of file logging.c.
const struct LogLineList log_queue_get | ( | void | ) |
void log_multiline_full | ( | enum LogLevel | level, |
const char * | str, | ||
const char * | file, | ||
int | line, | ||
const char * | func | ||
) |
Helper to dump multiline text to the log.
level | Logging level, e.g. LL_DEBUG1 |
str | Text to save |
file | Source file |
line | Source line number |
func | Source function |
Definition at line 482 of file logging.c.
const char* LogLevelAbbr = "PEWM12345N" |
|
static |
|
static |