CppLogging  1.0.4.0
C++ Logging Library
console_appender.cpp
Go to the documentation of this file.
1 
10 
11 #include "system/console.h"
12 
13 #include <cstdio>
14 
15 namespace CppLogging {
16 
18 {
19  // Skip logging records without layout
20  if (record.raw.empty())
21  return;
22 
23  // Setup console color depends on the logging level
24  switch (record.level)
25  {
26  case Level::NONE:
27  CppCommon::Console::SetColor(CppCommon::Color::DARKGREY);
28  break;
29  case Level::FATAL:
30  CppCommon::Console::SetColor(CppCommon::Color::WHITE, CppCommon::Color::LIGHTRED);
31  break;
32  case Level::ERROR:
33  CppCommon::Console::SetColor(CppCommon::Color::LIGHTRED);
34  break;
35  case Level::WARN:
36  CppCommon::Console::SetColor(CppCommon::Color::YELLOW);
37  break;
38  case Level::INFO:
39  CppCommon::Console::SetColor(CppCommon::Color::WHITE);
40  break;
41  case Level::DEBUG:
42  CppCommon::Console::SetColor(CppCommon::Color::LIGHTMAGENTA);
43  break;
44  case Level::ALL:
45  CppCommon::Console::SetColor(CppCommon::Color::GREY);
46  break;
47  }
48 
49  // Append logging record content
50  std::fwrite(record.raw.data(), 1, record.raw.size() - 1, stdout);
51 
52  // Reset console color
53  CppCommon::Console::SetColor(CppCommon::Color::WHITE);
54 }
55 
57 {
58  // Flush stream
59  std::fflush(stdout);
60 }
61 
62 } // namespace CppLogging
void Flush() override
Flush the logging appender.
void AppendRecord(Record &record) override
Append the given logging record.
Logging record.
Definition: record.h:37
Level level
Level of the logging record.
Definition: record.h:44
std::vector< uint8_t > raw
Record content after layout.
Definition: record.h:53
Console (stdout) appender definition.
C++ Logging project definitions.
Definition: appender.h:15
@ FATAL
Log fatal errors.
@ WARN
Log warnings.
@ INFO
Log information.
@ ALL
Log everything.
@ NONE
Log nothing.
@ ERROR
Log errors.
@ DEBUG
Log debug.