retdec
logger.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_UTILS_IO_LOGGER_H
8 #define RETDEC_UTILS_IO_LOGGER_H
9 
10 #include <fstream>
11 #include <iostream>
12 #include <sstream>
13 #include <memory>
14 
15 namespace retdec {
16 namespace utils {
17 namespace io {
18 
22 class Logger {
23 public:
24  using Ptr = std::unique_ptr<Logger>;
25 
26 public:
27  enum Action: int {
34  NoAction
35  };
36 
37  enum class Color: int {
38  Red,
39  Green,
40  Blue,
41  Yellow,
42  DarkCyan,
43  Default
44  };
45 
46 protected:
47  typedef std::ostream& (*StreamManipulator) (std::ostream&);
48 
49 public:
50  Logger(std::ostream& stream, bool verbose = true);
51  Logger(const Logger& logger);
52  ~Logger();
53 
54  template <typename T>
55  Logger& operator << (const T& p);
56 
57  Logger& operator << (const StreamManipulator& manip);
58  Logger& operator << (const Action& ia);
59  Logger& operator << (const Color& lc);
60 
61 private:
62  bool isRedirected(const std::ostream& stream) const;
63 
64 protected:
65  std::ostream& _out;
66 
67  bool _verbose = true;
69 
71  bool _terminalNotSupported = false;
72 };
73 
74 class FileLogger : public Logger {
75 public:
76  FileLogger(const std::string& file, bool verbose = true);
77 
78 private:
79  std::ofstream _file;
80 };
81 
82 template<typename T>
83 inline Logger& Logger::operator << (const T& p)
84 {
85  if (!_verbose)
86  return *this;
87 
88  _out << p;
89 
90  return *this;
91 }
92 
94 {
95  if (!_verbose)
96  return *this;
97 
98  _out << p;
99 
100  return *this;
101 }
102 
103 }
104 }
105 }
106 
107 #endif
Definition: logger.h:74
FileLogger(const std::string &file, bool verbose=true)
Definition: logger.cpp:150
std::ofstream _file
Definition: logger.h:79
Provides Logger inteface that is used for logging events during decompilation.
Definition: logger.h:22
bool isRedirected(const std::ostream &stream) const
Definition: logger.cpp:122
std::ostream & _out
Definition: logger.h:65
Color
Definition: logger.h:37
Logger(std::ostream &stream, bool verbose=true)
Definition: logger.cpp:35
bool _modifiedTerminalProperty
Definition: logger.h:70
std::ostream &(* StreamManipulator)(std::ostream &)
Definition: logger.h:47
Color _currentBrush
Definition: logger.h:68
std::unique_ptr< Logger > Ptr
Definition: logger.h:24
bool _verbose
Definition: logger.h:67
bool _terminalNotSupported
Definition: logger.h:71
~Logger()
Definition: logger.cpp:69
Action
Definition: logger.h:27
@ ElapsedTime
Definition: logger.h:31
@ SubSubPhase
Definition: logger.h:30
@ SubPhase
Definition: logger.h:29
@ NoAction
Definition: logger.h:34
@ Warning
Definition: logger.h:33
@ Phase
Definition: logger.h:28
@ Error
Definition: logger.h:32
Logger & operator<<(const T &p)
Definition: logger.h:83
Definition: archive_wrapper.h:19