Crinit -- Configurable Rootfs Init
|
Implementation of debug/log output. More...
#include "logio.h"
#include <locale.h>
#include <pthread.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include "globopt.h"
Macros | |
#define | CRINIT_ERROR_WITH_FFL_FMT "(%s:%s:%d) Error: " |
Format string error prefix with function, file and line. More... | |
#define | CRINIT_ERRNO_FMT " Errno: %s" |
Format string errno suffix, to use with strerror(). More... | |
#define | CRINIT_SYSLOG_IDENT "crinit" |
Identification string for crinit logging to syslog. More... | |
Functions | |
static char * | crinitThreadSafeStrerror (int errnum) |
void | crinitSetPrintPrefix (const char *prefix) |
void | crinitSetInfoStream (FILE *stream) |
void | crinitSetErrStream (FILE *stream) |
void | crinitSetUseSyslog (bool sl) |
void | crinitDbgInfoPrint (const char *format,...) |
void | crinitInfoPrint (const char *format,...) |
void | crinitErrPrintFFL (const char *file, const char *func, int line, const char *format,...) |
void | crinitErrnoPrintFFL (const char *file, const char *func, int line, const char *format,...) |
Variables | |
static char | crinitPrintPrefix [CRINIT_PRINT_PREFIX_MAX_LEN] = CRINIT_PRINT_PREFIX |
static FILE * | crinitInfoStream = NULL |
holds the stream to use for info messages. More... | |
static FILE * | crinitErrStream = NULL |
holds the stream to use for error messages. More... | |
static bool | crinitUseSyslog = false |
specifies if we should use syslog calls instead of FILE streams. More... | |
static pthread_mutex_t | crinitLogLock = PTHREAD_MUTEX_INITIALIZER |
Implementation of debug/log output.
#define CRINIT_ERRNO_FMT " Errno: %s" |
Format string errno suffix, to use with strerror().
#define CRINIT_ERROR_WITH_FFL_FMT "(%s:%s:%d) Error: " |
Format string error prefix with function, file and line.
#define CRINIT_SYSLOG_IDENT "crinit" |
Identification string for crinit logging to syslog.
void crinitDbgInfoPrint | ( | const char * | format, |
... | |||
) |
void crinitErrnoPrintFFL | ( | const char * | file, |
const char * | func, | ||
int | line, | ||
const char * | format, | ||
... | |||
) |
void crinitErrPrintFFL | ( | const char * | file, |
const char * | func, | ||
int | line, | ||
const char * | format, | ||
... | |||
) |
void crinitInfoPrint | ( | const char * | format, |
... | |||
) |
void crinitSetErrStream | ( | FILE * | stream | ) |
Set FILE stream to use for error messages.
Defaults to stderr. This can be used to divert the error messages into a log file. The stream can be the same as the one used for crinitSetInfoStream() if the log should contain both types of messages. The function uses mutexes internally and is thread-safe.
Currently, the config file option to make use of this functionality is not yet implemented.
stream | The FILE* stream to use. If NULL, stream is set to stderr. |
void crinitSetInfoStream | ( | FILE * | stream | ) |
Set FILE stream to use for info messages.
Defaults to stdout. This can be used to divert the info messages into a log file. The stream can be the same as the one used for crinitSetErrStream() if the log should contain both types of messages. The function uses mutexes internally and is thread-safe.
Currently, the config file option to make use of this functionality is not yet implemented.
stream | The FILE* stream to use. If NULL, stream is set to stdout. |
void crinitSetPrintPrefix | ( | const char * | prefix | ) |
Set prefix to put in front of error and info message lines.
prefix | The prefix to use. |
void crinitSetUseSyslog | ( | bool | sl | ) |
Specify if syslog should be used..
By default, Crinit will always use the specified FILE streams. If this is set to true
, however, Crinit will output to syslog instead. The log connection will be opened with LOG_CONS
, so if the connection fails, output will be sent to the system console instead.
sl | true if syslog should be used, false otherwise. |
|
static |
Thread-safe implementation of strerror() using strerror_l().
Always uses the POSIX/C locale to format the readable output.
errnum | The error number to explain. |
|
static |
holds the stream to use for error messages.
|
static |
holds the stream to use for info messages.
|
static |
Mutex synchronizing print output (so that print statements are atomic wrt. to each other).
|
static |
Holds the Prefix to put in front of every printed line, defaults to CRINIT_PRINT_PREFIX
|
static |
specifies if we should use syslog calls instead of FILE streams.