libzypp  17.26.0
Logger.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_BASE_LOGGER_H
13 #define ZYPP_BASE_LOGGER_H
14 #include <cstring>
15 #include <iosfwd>
16 #include <string>
17 
19 #ifndef ZYPP_NDEBUG
20 namespace zypp
21 {
22  namespace debug
23  { // impl in LogControl.cc
24 
25  // Log code loacaton and block leave
26  // Indent if nested
27  struct TraceLeave
28  {
29  TraceLeave( const TraceLeave & ) =delete;
30  TraceLeave & operator=( const TraceLeave & ) =delete;
31  TraceLeave( const char * file_r, const char * fnc_r, int line_r );
32  ~TraceLeave();
33  private:
34  static unsigned _depth;
35  const char * _file;
36  const char * _fnc;
37  int _line;
38  };
39 #define TRACE ::zypp::debug::TraceLeave _TraceLeave( __FILE__, __FUNCTION__, __LINE__ )
40 
41  // OnScreenDebug messages colored to stderr
42  struct Osd
43  {
44  Osd( std::ostream &, int = 0 );
45  ~Osd();
46 
47  template<class Tp>
48  Osd & operator<<( Tp && val )
49  {
50  _strout << std::forward<Tp>(val);
51  _strlog << std::forward<Tp>(val);
52  return *this;
53  }
54 
55  Osd & operator<<( std::ostream& (*iomanip)( std::ostream& ) );
56 
57  private:
58  std::ostream & _strout;
59  std::ostream & _strlog;
60  };
61 #define OSD ::zypp::debug::Osd(L_USR("OSD"))
62  }
63 }
64 #endif // ZYPP_NDEBUG
65 
88 
89 #ifndef ZYPP_BASE_LOGGER_LOGGROUP
90 
91 #define ZYPP_BASE_LOGGER_LOGGROUP "DEFINE_LOGGROUP"
92 #endif
93 
94 #define XXX L_XXX( ZYPP_BASE_LOGGER_LOGGROUP )
95 #define DBG L_DBG( ZYPP_BASE_LOGGER_LOGGROUP )
96 #define MIL L_MIL( ZYPP_BASE_LOGGER_LOGGROUP )
97 #define WAR L_WAR( ZYPP_BASE_LOGGER_LOGGROUP )
98 #define ERR L_ERR( ZYPP_BASE_LOGGER_LOGGROUP )
99 #define SEC L_SEC( ZYPP_BASE_LOGGER_LOGGROUP )
100 #define INT L_INT( ZYPP_BASE_LOGGER_LOGGROUP )
101 #define USR L_USR( ZYPP_BASE_LOGGER_LOGGROUP )
102 
103 #define L_XXX(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_XXX )
104 #define L_DBG(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP"++", zypp::base::logger::E_MIL )
105 #define L_MIL(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_MIL )
106 #define L_WAR(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_WAR )
107 #define L_ERR(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_ERR )
108 #define L_SEC(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_SEC )
109 #define L_INT(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_INT )
110 #define L_USR(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_USR )
111 
112 #define L_BASEFILE ( *__FILE__ == '/' ? strrchr( __FILE__, '/' ) + 1 : __FILE__ )
113 
115 #define ZYPP_BASE_LOGGER_LOG(GROUP,LEVEL) \
116  zypp::base::logger::getStream( GROUP, LEVEL, L_BASEFILE, __FUNCTION__, __LINE__ )
117 
120 namespace zypp
122 {
123  namespace base
125  {
126 
128  namespace logger
129  {
130 
135  enum LogLevel {
136  E_XXX = 999,
137  E_DBG = 0,
144  };
145 
156  extern std::ostream & getStream( const char * group_r,
157  LogLevel level_r,
158  const char * file_r,
159  const char * func_r,
160  const int line_r );
161  extern bool isExcessive();
162 
164  } // namespace logger
166 
168  } // namespace base
171 } // namespace zypp
173 #endif // ZYPP_BASE_LOGGER_H
Internal error.
Definition: Logger.h:142
Osd & operator<<(Tp &&val)
Definition: Logger.h:48
LogLevel
Definition of log levels.
Definition: Logger.h:135
std::ostream & _strlog
Definition: Logger.h:59
Debug or verbose.
Definition: Logger.h:137
std::ostream & _strout
Definition: Logger.h:58
TraceLeave & operator=(const TraceLeave &)=delete
Osd(std::ostream &, int=0)
Definition: LogControl.cc:75
Secutrity related.
Definition: Logger.h:141
const char * _fnc
Definition: Logger.h:36
TraceLeave(const TraceLeave &)=delete
static unsigned _depth
Definition: Logger.h:34
const char * _file
Definition: Logger.h:35
Excessive logging.
Definition: Logger.h:136
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
std::ostream & getStream(const char *group_r, LogLevel level_r, const char *file_r, const char *func_r, const int line_r)
Return a log stream to write on.
Definition: LogControl.cc:434