Design Pattern Examples
Overview of object-oriented design patterns
Bridge_FileLogger.c File Reference

Implementation of the file logger, along with the CreateFileLogger() and DestroyFileLogger() factory functions used in the Bridge Pattern. More...

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include "Bridge_LogHelper.h"
#include "Bridge_FileLogger.h"
Include dependency graph for Bridge_FileLogger.c:

Go to the source code of this file.

Functions

static void _WriteLine (const char *loglevel, const char *message, FILE *fp)
 Send a formatted line to a log file.
 
static void _File_LogTrace (const char *message, void *data)
 Write a trace 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_LogError (const char *message, void *data)
 Write an error message to a log file.
 
ILoggerCreateFileLogger (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.
 

Detailed Description

Implementation of the file logger, along with the CreateFileLogger() and DestroyFileLogger() factory functions used in the Bridge Pattern.

Definition in file Bridge_FileLogger.c.

Function Documentation

◆ _File_LogError()

static void _File_LogError ( const char *  message,
void *  data 
)
static

Write an error message to a log file.

Parameters
messageThe message to log.
dataThe data associated with an instance of an ILogger. In this case, the file handle to write to.

Definition at line 82 of file Bridge_FileLogger.c.

References _WriteLine().

Referenced by CreateFileLogger().

◆ _File_LogInfo()

static void _File_LogInfo ( const char *  message,
void *  data 
)
static

Write an informational message to a log file.

Parameters
messageThe message to log.
dataThe data associated with an instance of an ILogger. In this case, the file handle to write to.

Definition at line 65 of file Bridge_FileLogger.c.

References _WriteLine().

Referenced by CreateFileLogger().

◆ _File_LogTrace()

static void _File_LogTrace ( const char *  message,
void *  data 
)
static

Write a trace message to a log file.

Parameters
messageThe message to log.
dataThe data associated with an instance of an ILogger. In this case, the file handle to write to.

Definition at line 48 of file Bridge_FileLogger.c.

References _WriteLine().

Referenced by CreateFileLogger().

◆ _WriteLine()

static void _WriteLine ( const char *  loglevel,
const char *  message,
FILE *  fp 
)
static

Send a formatted line to a log file.

Parameters
loglevelThe level of the log detail.
messageThe message to log.
fpHandle to file to write to. If NULL, nothing is written.

Definition at line 21 of file Bridge_FileLogger.c.

References LogHelper_FormatLogLine().

Referenced by _File_LogError(), _File_LogInfo(), and _File_LogTrace().

◆ CreateFileLogger()

ILogger * CreateFileLogger ( const char *  filename)

Create an instance of an ILogger that outputs to a file.

Parameters
filenameName of the file to log to. The file will be overwritten.
Returns
Returns an ILogger instance to use for logging to a file; returns NULL if something went wrong in creating the logger.

Definition at line 96 of file Bridge_FileLogger.c.

References _File_LogError(), _File_LogInfo(), _File_LogTrace(), ILogger::data, ILogger::LogError, ILogger::LogInfo, and ILogger::LogTrace.

Referenced by CreateLogger().

◆ DestroyFileLogger()

void DestroyFileLogger ( ILogger logger)

Destroy the given instance of an ILogger for outputting to a file.

Parameters
loggerThe ILogger instance to destroy.

Definition at line 127 of file Bridge_FileLogger.c.

References ILogger::data.

Referenced by DestroyLogger().