Design Pattern Examples
Overview of object-oriented design patterns
Bridge_ConsoleLogger.cpp
Go to the documentation of this file.
1
5
6#include <iostream>
9
10namespace // Anonymous
11{
15 class ConsoleLoggerImpl : public DesignPatternExamples_cpp::ILogger
16 {
17 private:
18
24 void _WriteLine(const std::string& logLevel, const std::string& msg)
25 {
26 std::string output = DesignPatternExamples_cpp::LoggerHelpers::FormatLogLine(logLevel, msg);
27 std::cout << output << std::endl;
28 }
29
30 public:
34 ConsoleLoggerImpl()
35 {
36 }
37
38 // ILogger Members
39
40 void LogTrace(const std::string& msg)
41 {
42 _WriteLine("TRACE", msg);
43 }
44
45 void LogInfo(const std::string& msg)
46 {
47 _WriteLine("INFO ", msg);
48 }
49
50 void LogError(const std::string& msg)
51 {
52 _WriteLine("ERROR", msg);
53 }
54 };
55
56} // end anonymous namespace
57
58
60{
66 std::unique_ptr<ILogger> ConsoleLogger::CreateLogger()
67 {
68 return std::make_unique<ConsoleLoggerImpl>();
69 }
70
71} // end namespace
static void _WriteLine(const char *loglevel, const char *message)
Send a formatted line to the console.
Declaration of the LoggerHelpers namespace functions used in the Bridge Pattern.
static std::unique_ptr< ILogger > CreateLogger()
Create an instance of a console logger, which writes to the standard output.
Declaration of the ConsoleLogger class used in the Bridge Pattern.
std::string FormatLogLine(const std::string &logLevel, const std::string &msg)
Format a line for logging, including time stamp.
The namespace containing all Design Pattern Examples implemented in C++.
Represents an implementation of a logger object as call from the Logger class.
virtual void LogInfo(const std::string &msg)=0
Log informational messages to the configured output.
virtual void LogTrace(const std::string &msg)=0
Log trace messages to the configured output.
virtual void LogError(const std::string &msg)=0
Log error messages to the configured output.