21static void _WriteLine(
const char* loglevel,
const char* message, FILE* fp)
23 char buffer[512] = { 0 };
29 size_t numElementsToWrite = strlen(buffer);
30 size_t numElementsWritten = fwrite(buffer,
sizeof(
char), numElementsToWrite, fp);
31 if (numElementsWritten != numElementsToWrite)
33 int errorcode = errno;
34 char *errmessage = strerror(errorcode);
35 printf(
" Error (%d) writing log file: %s\n", errorcode, errmessage);
99 if (logger != NULL && filename != NULL)
106 fp = fopen(filename,
"w");
113 int errorcode = errno;
114 char *errmessage = strerror(errorcode);
115 printf(
" Error (%d) opening log file '%s': %s\n", errorcode, filename, errmessage);
131 if (logger->
data != NULL)
133 FILE* fp = (FILE*)logger->
data;
static void _WriteLine(const char *loglevel, const char *message, FILE *fp)
Send a formatted line to a log file.
static void _File_LogError(const char *message, void *data)
Write an error message to a log file.
static void _File_LogInfo(const char *message, void *data)
Write an informational message to a log file.
static void _File_LogTrace(const char *message, void *data)
Write a trace message to a log file.
ILogger * CreateFileLogger(const char *filename)
Create an instance of an ILogger that outputs to a file.
void DestroyFileLogger(ILogger *logger)
Destroy the given instance of an ILogger for outputting to a file.
bool LogHelper_FormatLogLine(const char *loglevel, const char *message, char *output, size_t maxOutputSize)
Format a line for logging, including time stamp.
Declaration of the LogHelper_FormatLogLine() function, used in the Bridge Pattern.
Declaration of the FileLogger class used in the Bridge Pattern.
void(* LogError)(const char *message, void *data)
Log error messages to the configured output.
void * data
Data associated with a specific instance of a logger.
void(* LogInfo)(const char *message, void *data)
Log informational messages to the configured output.
void(* LogTrace)(const char *message, void *data)