karazeh
A cross-platform software updating library.
logger.hpp
Go to the documentation of this file.
1 
21 #ifndef H_KARAZEH_LOGGER_H
22 #define H_KARAZEH_LOGGER_H
23 
24 #include <sstream>
25 #include <fstream>
26 #include <iostream>
27 #include "karazeh_export.h"
28 #include "karazeh/karazeh.hpp"
29 
30 namespace kzh {
31  using std::ostream;
32  using std::ostringstream;
33 
34  struct logstream;
36  public:
37 
47  logger(string_t context);
48  virtual ~logger();
49 
58  static void set_threshold(char level);
59 
63  static void set_stream(std::ostream*);
64 
69  static void enable_timestamps(bool on_or_off);
70 
72  static void set_app_name(string_t const& app_name);
73 
74  static void indent();
75  static void deindent();
76 
77  static void mute();
78  static void unmute();
79 
81  logstream debug() const;
83  logstream info() const;
85  logstream notice() const;
87  logstream warn() const;
89  logstream error() const;
91  logstream alert() const;
93  logstream crit() const;
94 
95  logstream plain() const;
96 
101  void set_uuid_prefix(string_t const&);
102 
104  string_t const& uuid_prefix() const;
105 
106  protected:
107  void rename_context(string_t const&);
108 
109  private:
110  ostream& log(char lvl) const;
111  string_t context_;
112 
113  static ostringstream sink;
114  static ostream* out;
115  static bool with_timestamps;
116  static bool with_app_name;
117  static bool silenced;
118  static string_t app_name;
119  static int indent_level;
120 
121  string_t uuid_prefix_;
122  }; // end of logger class
123 
125  logstream(std::ostream&);
126  ~logstream();
127 
128  std::ostream &s;
129 
130  template<typename T>
131  inline logstream& operator<<(T const& data) {
132  s << data;
133  return *this;
134  }
135  };
136 
137 } // end of namespace kzh
138 
139 #endif
std::string string_t
Definition: karazeh.hpp:55
Definition: config.hpp:32
std::ostream & s
Definition: logger.hpp:128
Definition: logger.hpp:35
Definition: config.hpp:27
Definition: logger.hpp:124
logstream & operator<<(T const &data)
Definition: logger.hpp:131