Design Pattern Examples
Overview of object-oriented design patterns
Bridge_NullLogger.c
Go to the documentation of this file.
1
6
7#include <stdlib.h>
8
9#include "Bridge_NullLogger.h"
10
11
17static void _Null_LogTrace(const char* message, void* data)
18{
19 (void)message; // unused
20 (void)data; // unused
21
22 // We don't do anything here, just reference the parameters to avoid a
23 // compiler warning.
24}
25
26
32static void _Null_LogInfo(const char* message, void* data)
33{
34 (void)message; // unused
35 (void)data; // unused
36
37 // We don't do anything here, just reference the parameters to avoid a
38 // compiler warning.
39}
40
41
47static void _Null_LogError(const char* message, void* data)
48{
49 (void)message; // unused
50 (void)data; // unused
51
52 // We don't do anything here, just reference the parameters to avoid a
53 // compiler warning.
54}
55
56
58// CreateNullLogger()
61{
62 ILogger* logger = calloc(1, sizeof(ILogger));
63 if (logger != NULL)
64 {
65 logger->LogTrace = _Null_LogTrace;
66 logger->LogInfo = _Null_LogInfo;
67 logger->LogError = _Null_LogError;
68 logger->data = NULL;
69 }
70
71 return logger;
72}
73
75// DestroyNullLogger()
78{
79 free(logger);
80}
void DestroyNullLogger(ILogger *logger)
Destroy the given instance of an ILogger for outputting to a console.
static void _Null_LogError(const char *message, void *data)
Write an error message to a null logger (basically, discard the log message).
static void _Null_LogTrace(const char *message, void *data)
Write a trace message to a null logger (basically, discard the log message).
ILogger * CreateNullLogger(void)
Create an instance of an ILogger that outputs to a console.
static void _Null_LogInfo(const char *message, void *data)
Write an informational message to a null logger (basically, discard the log message).
Declaration of the NullLogger 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)