summaryrefslogtreecommitdiff
path: root/include/color_cout_g3_sink.hpp
blob: cd98fac05d5717d6666a8145039071376541f2d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#pragma once
namespace crow
{
  struct ColorCoutSink {

  // Linux xterm color
  // http://stackoverflow.com/questions/2616906/how-do-i-output-coloured-text-to-a-linux-terminal
    enum FG_Color {YELLOW = 33, RED = 31, GREEN=32, WHITE = 97};

    FG_Color GetColor(const LEVELS level) const {
      if (level.value == WARNING.value) { return YELLOW; }
      if (level.value == DEBUG.value) { return GREEN; }
      if (g3::internal::wasFatal(level)) { return RED; }

      return WHITE;
    }
    
    void ReceiveLogMessage(g3::LogMessageMover logEntry) {
      auto level = logEntry.get()._level;
      auto color = GetColor(level);

      std::cout << "\033[" << color << "m" 
        << logEntry.get().toString() << "\033[m";
    }
  };
}