Logging operations.
More...
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <time.h>
#include "args.h"
#include "defaults.h"
#include "log.h"
#include "peapod.h"
static void log_to_file |
( |
const char * |
msg, |
|
|
int |
level, |
|
|
FILE * |
out |
|
) |
| |
|
static |
Log a message to a file or to the console.
Messages are timestamped if logging to the console. Messages are additionally datestamped if logging to a file.
- Parameters
-
msg | A message to be logged |
level | The level of the message |
out | File stream of log file, or NULL to emit to the console |
- Note
level
may be the syslog
levels (LOG_EMERG
to LOG_DEBUG
, i.e. 0 to 7), or our own LOG_DEBUGLOW
(8).
Output to console emits to stderr
if level
is below LOG_WARNING
, and to stdout
otherwise.
Initialize logging.
- Returns
- 0 if successful, or -1 if unsuccessful
int log_daemonize |
( |
void |
| ) |
|
Prepare logging when daemonizing.
- Returns
- 0 if successful, or -1 if unsuccessful
void log_msg |
( |
int |
level, |
|
|
const char * |
file, |
|
|
int |
line, |
|
|
const char * |
fmt, |
|
|
|
... |
|
) |
| |
Log a message.
Depending on the program arguments and the value of level
, the same message is emitted to console (stdout
/stderr
), a log file, and/or syslog
.
- Parameters
-
level | The level of the message |
file | Ordinarily NULL |
line | Ordinarily 0 |
fmt,... | printf(3)-style format and variable arguments |
- Note
level
may be the syslog
levels (LOG_EMERG
to LOG_DEBUG
, i.e. 0 to 7), or our own LOG_DEBUGLOW
(8).
file
and line
are the __FILE__
and __LINE__
macros, i.e. the source file and the line in the source file of the call to log_msg()
. They were used during development only in the lfoo()
logging macros defined in log.h
.
Initial value:= {
"EMERG", "ALERT", "CRIT ",
"ERROR", "WARN ", "NOTE ",
"INFO ", "DEBUG", "DBGLO"
}
Five on-screen characters.
Used for emitting logs to syslog or to a log file.
Initial value:= {
"\x1b[1;4;91mEMERG\x1b[0m",
"\x1b[1;4;93mALERT\x1b[0m",
"\x1b[1;96mCRIT\x1b[0m ",
"\x1b[1;91mERROR\x1b[0m",
"\x1b[1;95mWARN\x1b[0m ",
"\x1b[1;94mNOTE\x1b[0m ",
"\x1b[1;92mINFO\x1b[0m ",
"DEBUG",
"DBGLO"
}
Five colorized on-screen characters.
Used for emitting logs to the console (stdout
/ stderr
).
char log_tm[TMSIZ] = { "" } |
|
static |
Program arguments data structure.
- Note
- Global