Design Pattern Examples
Overview of object-oriented design patterns
Bridge_LoggerHelpers.cpp
Go to the documentation of this file.
1
5
6// Posix way of asking for bounds-checked versions of library functions.
7#define __STDC_WANT_LIB_EXT1__ 1
8#include <chrono>
9
10#include "helpers/DateTime.h"
11#include "helpers/formatstring.h"
12
15
16namespace // Anonymous
17{
18
24 std::string _GetTimeStamp()
25 {
26 return DateTime::Now().ToString();
27 }
28
29} // end anonymous
30
31
32
34{
35
36 namespace LoggerHelpers
37 {
44 std::string FormatLogLine(const std::string& logLevel, const std::string& msg)
45 {
46 std::string timestamp = _GetTimeStamp();
47 return Helpers::formatstring("%s [%s] %s", timestamp.c_str(), logLevel.c_str(), msg.c_str());
48 }
49
50 } // end namespace
51
52} // end namespace
static const char * _GetTimeStamp(void)
Return a regular time stamp of the current time in local time.
Declaration of the LoggerHelpers namespace functions used in the Bridge Pattern.
Represents a timestamp composed of a date and a time encoded in a time_t value. Provides ways of gett...
static DateTime Now()
Return the current date and time.
Definition: DateTime.cpp:35
std::string ToString()
Format the DateTime as a string. The format is "standard" (in this case, preset to 02/22/2023 10:26:1...
Definition: DateTime.cpp:17
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++.
std::string formatstring(const char *fmt,...)
Use the given string and arguments to return a buffer containing the formatted string....