37 lines
1.2 KiB
C
37 lines
1.2 KiB
C
#ifndef LOG_H
|
|
#define LOG_H
|
|
|
|
#include <stdarg.h>
|
|
|
|
// ============================================================================
|
|
// Logging layer - writes to a log file
|
|
//
|
|
// Call logInit() with a filename to enable logging.
|
|
// ============================================================================
|
|
|
|
// Initialize logging. If filename is non-NULL, opens it for writing.
|
|
// Can be called before any other log function. If not called, output
|
|
// goes only to stdout/stderr.
|
|
void logInit(const char *filename);
|
|
|
|
// Shut down logging, flush and close the log file.
|
|
void logShutdown(void);
|
|
|
|
// Write to stdout and the log file (like printf).
|
|
void logMsg(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
|
|
|
|
// Write to stderr and the log file (like fprintf(stderr, ...)).
|
|
void logErr(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
|
|
|
|
// Varargs versions for use by other wrappers.
|
|
void logMsgV(const char *fmt, va_list ap);
|
|
void logErrV(const char *fmt, va_list ap);
|
|
|
|
// Get the underlying log file handle (or NULL if not initialized).
|
|
FILE *logGetFile(void);
|
|
|
|
// Register a pre-I/O hook called before every file write.
|
|
typedef void (*LogPreIoFuncT)(void);
|
|
void logSetPreIoHook(LogPreIoFuncT func);
|
|
|
|
#endif // LOG_H
|