Euphoria
log.cc
Go to the documentation of this file.
1 #include "log/log.h"
2 
3 #include <iostream>
4 #include <cassert>
5 
6 
7 namespace
8 {
9  struct ConsoleLogger : eu::log::Logger
10  {
11  void info(const std::string& str) override
12  {
13  std::cout << str << "\n";
14  }
15 
16  void warn(const std::string & str) override
17  {
18  std::cerr << str << "\n";
19  }
20 
21  void error(const std::string & str) override
22  {
23  std::cerr << str << "\n";
24  }
25  };
26 
27  eu::log::Logger* global_logger = nullptr;
28 }
29 
30 
31 namespace eu::log
32 {
33  Logger*
35  {
36  static ConsoleLogger console_logger;
37  Logger* logger = global_logger;
38 
39  if (logger != nullptr) { return logger; }
40  else { return &console_logger; }
41  }
42 
43 
45  {
46  assert(global_logger);
47  global_logger = new_log;
48  }
49 
51  {
52  global_logger = nullptr;
53  }
54 }
Definition: log.cc:32
Logger * get_global_logger()
Definition: log.cc:34
virtual void warn(const std::string &str)=0
virtual void info(const std::string &str)=0
virtual void error(const std::string &str)=0
ScopedLogger(Logger *new_log)
Definition: log.cc:44