Simple-Log  alpha-v0.7
ColorizedConsoleLogging/main.cpp
1 // Copyright Dominic Koepke 2021 - 2021.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // https://www.boost.org/LICENSE_1_0.txt)
5 
7 
8 // just pull everything into the current namespace
9 using namespace sl::log::preset;
10 using namespace sl::log;
11 
12 int main()
13 {
14  Core_t core;
15  auto log = makeLogger<Logger_t>(core, SevLvl::info);
16 
17  auto& gConsoleSink = core.makeSink<ConsoleSink_t>();
18 
19  using Color = ConsoleTextStyle::Color;
20  using Style = ConsoleTextStyle::Style;
21  gConsoleSink.setTextStylePolicy(
22  makeConsoleTextStyleTableFor<Record_t>(
23  &Record_t::severity, // use the severity property
24  {
25  // the desired SevLvl gets linked to a color and style setup
26  { SevLvl::debug, { .textColor = Color::yellow, .bgColor = Color::gray } },
27  { SevLvl::hint, { .bgColor = Color::green } },
28  { SevLvl::warning, { .bgColor = Color::yellow } },
29  { SevLvl::error, { .style = Style::bold, .textColor = Color::red, .bgColor = Color::yellow } },
30  { SevLvl::fatal, { .style = Style::crossed, .textColor = Color::gray, .bgColor = Color::red } }
31  }
32  )
33  );
34 
35  log() << "Hello, World!";
36  log() << SetSev(SevLvl::debug) << "Mighty debug message";
37  log() << "Print as hint!" << SetSev(SevLvl::hint);
38  log() << SetSev(SevLvl::warning) << "be warned...";
39  log() << "Print my important error!" << SetSev(SevLvl::error);
40  log() << "Print it fatal!" << SetSev(SevLvl::fatal);
41 }
42 // Above lines will be printed nicely colorful onto the console. Go, test it out ;)
const SeverityLevel_t & severity() const noexcept
Const access to the severity level.
Definition: Record.hpp:284
Sink class for directly logging onto std::cout.
Definition: ConsoleSink.hpp:239
The central point of the whole library. Needs to be instantiated at least once.
Definition: Core.hpp:51
requires std::constructible_from< TSink, TArgs... > TSink & makeSink(TArgs &&... args)
Creates Sink and registers it at this Core instance.
Definition: Core.hpp:130
Manipulates the channel of the current RecordBuilder object.
Definition: RecordBuilder.hpp:31
Definition: PresetTypes.hpp:14
auto & gConsoleSink
Definition: ReadyToGo.hpp:19
Definition: BasicSink.hpp:22
Style
Definition: ConsoleSink.hpp:67
Color
Definition: ConsoleSink.hpp:45