Log: Difference between revisions
Jump to navigation
Jump to search
(New page: == Overview == The libreciva log function provides a support function to store and output log messages. In order to use the library function, you must include the header file: <pre> #in...) |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
== Overview == | == Overview == | ||
The | The [[Libreciva]] log function provides a support function to store and output log messages. | ||
In order to use the library function, you must include the header file: | In order to use the library function, you must include the header file: | ||
< | <syntaxhighlight> | ||
#include "log.h" | #include "log.h" | ||
</ | </syntaxhighlight> | ||
=== void log_init(char *progname, enum log_to dest, enum log_level, int colour) === | === void log_init(char *progname, enum log_to dest, enum log_level, int colour) === | ||
Line 52: | Line 52: | ||
== Example == | == Example == | ||
< | <syntaxhighlight> | ||
#include "log.h" | #include "log.h" | ||
main() | main() { | ||
{ | |||
int x=2 ; | int x=2 ; | ||
log_init("testprog", LOG_TO_STDERR, LG_ERR, 0) ; | log_init("testprog", LOG_TO_STDERR, LG_ERR, 0); | ||
logf(LG_ERR, "This is an error message, x=%d", x) ; | logf(LG_ERR, "This is an error message, x=%d", x); | ||
logf(LG_WRN, "This will not be output as the log_init level is LG_ERR) ; | logf(LG_WRN, "This will not be output as the log_init level is LG_ERR"); | ||
logf(LG_FTL, "This log entry will cause a program exit") ; | logf(LG_FTL, "This log entry will cause a program exit"); | ||
} | } | ||
</ | </syntaxhighlight> |
Latest revision as of 10:01, 31 December 2011
Overview
The Libreciva log function provides a support function to store and output log messages.
In order to use the library function, you must include the header file:
<syntaxhighlight>
- include "log.h"
</syntaxhighlight>
void log_init(char *progname, enum log_to dest, enum log_level, int colour)
This function must be called to initialise the log system. The parameters are as follows:
char *progname
This is the name of the program.
enum log_to dest
This is the destination of the logger - it is either:
- LOG_TO_STDERR
- LOG_TO_SYSLOG
enum log_level
This is the level of logging to report, it is one of the following:
- LG_FTL
- LG_ERR
- LG_WRN
- LG_INF
- LG_DBG
void logf(enum log_level level, char *format, ...)
This function adds a log entry to the logfile. The level is one of:
- LG_FTL
- LG_ERR
- LG_WRN
- LG_INF
- LG_DBG
And the "format, ..." arguments are printf-compatible format string and arguments.
void log_hexdump(char *txt, char *data, int len)
This function dumps len bytes of data to the logfile, with a title of txt
Example
<syntaxhighlight>
- include "log.h"
main() {
int x=2 ; log_init("testprog", LOG_TO_STDERR, LG_ERR, 0); logf(LG_ERR, "This is an error message, x=%d", x); logf(LG_WRN, "This will not be output as the log_init level is LG_ERR"); logf(LG_FTL, "This log entry will cause a program exit");
} </syntaxhighlight>