LogFormat.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
17 #ifndef HH_SENF_Utils_Logger_LogFormat_
18 #define HH_SENF_Utils_Logger_LogFormat_ 1
19 
20 // Custom includes
21 #include <sstream>
22 #include "TimeSource.hh"
24 
25 //#include "LogFormat.mpp"
26 //-/////////////////////////////////////////////////////////////////////////////////////////////////
27 
28 namespace senf {
29 namespace log {
30 namespace detail {
31 
32  class LogFormat
33  {
34  public:
35  LogFormat();
36  explicit LogFormat(console::ScopedDirectory<> & dir);
37 
38  void showTime(bool flag = true);
39  void showStream(bool flag = true);
40  void showLevel(bool flag = true);
41  void showArea(bool flag = true);
42 
43  void timeFormat(std::string const & format);
45 
57  void tag(std::string const & tag);
58 
59  protected:
60  std::string prefix(time_type timestamp, std::string const & stream,
61  std::string const & area, unsigned level);
62  bool isPlainFormat() const;
63  void consoleFormat(std::ostream & os);
64 
65  private:
66  std::stringstream datestream_;
67  std::string tag_;
68  std::string timeFormat_;
69  time_type timeBase_;
70 
71  bool noformat_;
72  bool showTime_;
73  bool showStream_;
74  bool showLevel_;
75  bool showArea_;
76  };
77 
78  void quoteNonPrintable(std::string & s);
79  std::string getDefaultTag();
80 
81 }}}
82 
83 //-/////////////////////////////////////////////////////////////////////////////////////////////////
84 #include "LogFormat.cci"
85 //#include "LogFormat.ct"
86 //#include "LogFormat.cti"
87 #endif
88 
89 
90 // Local Variables:
91 // mode: c++
92 // fill-column: 100
93 // comment-column: 40
94 // c-file-style: "senf"
95 // indent-tabs-mode: nil
96 // ispell-local-dictionary: "american"
97 // compile-command: "scons -u test"
98 // End:
void showStream(bool flag=true)
Enable or disable output of stream field.
void showLevel(bool flag=true)
Enable or disable output of log level.
void quoteNonPrintable(std::string &s)
Definition: LogFormat.cc:140
void timeFormat(std::string const &format)
Set time format.
Definition: LogFormat.cc:94
void showTime(bool flag=true)
Enable or disable output of time field.
void showArea(bool flag=true)
Enable or disable output of log area.
TimeSource public header.
std::string prefix(time_type timestamp, std::string const &stream, std::string const &area, unsigned level)
Definition: LogFormat.cc:108
void consoleFormat(std::ostream &os)
Definition: LogFormat.cc:81
std::string getDefaultTag()
Definition: LogFormat.cc:147
config::time_type time_type
Definition: TimeSource.hh:31
void format(Type const &value, std::ostream &os)
void tag(std::string const &tag)
Set tag (log line prefix)