20 std::ofstream _outputFile;
29 void _WriteLine(
const std::string& logLevel,
const std::string& msg)
31 if (_outputFile.is_open())
34 _outputFile << output << std::endl;
43 FileLoggerImpl(
const std::string& filename)
45 if (!filename.empty())
47 _outputFile.open(filename.c_str(), std::ofstream::out);
48 if (!_outputFile.is_open())
57 void LogTrace(
const std::string& msg)
62 void LogInfo(
const std::string& msg)
67 void LogError(
const std::string& msg)
84 return std::make_unique<FileLoggerImpl>(filename);
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(const std::string &filename)
Create an instance of a file logger, which writes to a file.
Declaration of the FileLogger 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.