Evo C++ Library v0.5.1
logger_console.h
Go to the documentation of this file.
1 // Evo C++ Library
2 /* Copyright 2019 Justin Crowell
3 Distributed under the BSD 2-Clause License -- see included file LICENSE.txt for details.
4 */
6 
7 #pragma once
8 #ifndef INCL_evo_logger_console_h
9 #define INCL_evo_logger_console_h
10 
11 #include "logger.h"
12 #include "iothread.h"
13 
14 namespace evo {
17 
19 
26 class LoggerConsole : public LoggerBase {
27 public:
32  level_.store(level);
33  }
34 
35  void log_direct(LogLevel level, const SubString& msg) {
36  const char* LEVEL_STR[] = { "[ALRT]", "[ERRR]", "[WARN]", "[INFO]", "[dbug]", "[dbgl]" };
37  const StrSizeT LEVEL_LEN = 6;
38  const SubString level_str(LEVEL_STR[(int)level - 1], LEVEL_LEN);
39  EVO_IO_MT(c_.err, << level_str << ' ' << msg << NL);
40  }
41 
42 private:
43  ConsoleMT& c_;
44 };
45 
47 
48 }
49 #endif
LoggerConsole(LogLevel level=LOG_LEVEL_WARN)
Constructor.
Definition: logger_console.h:31
void store(T num, MemOrder mem_order=std::memory_order_seq_cst)
Store new value.
void log_direct(LogLevel level, const SubString &msg)
Log a message with given log level directly without checking the current log level.
Definition: logger_console.h:35
OutT err
Write to console, error output.
Definition: iothread.h:214
Logger that writes to console.
Definition: logger_console.h:26
Multithreaded console I/O.
Definition: iothread.h:206
Evo Input/Output streams with multithreading.
ConsoleMT & con_mt()
Shortcut for ConsoleMT::get().
Definition: iothread.h:233
uint32 StrSizeT
Default Evo string size type.
Definition: sys.h:734
static const NewlineDefault & NL
Default newline type.
Definition: sys.h:785
Evo C++ Library namespace.
Definition: alg.h:11
Warning message that can indicate a potential issue, this may lead to an error or alert (WARN) ...
Definition: logger.h:134
Evo logging.
#define EVO_IO_MT(STREAM, CODE)
Lock mutex and run stream operation code.
Definition: iothread.h:70
LogLevel
Log severity level used with Logger.
Definition: logger.h:130
Reference and access existing string data.
Definition: substring.h:229
Base class for Logger.
Definition: logger.h:273
AtomicInt level_
Log level, messages less severe than this are ignored (not logged)
Definition: logger.h:363