libzypp  17.25.8
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( int = 0 );
45  ~Osd();
46 
47  template<class Tp>
48  Osd & operator<<( Tp && val )
49  { _str << std::forward<Tp>(val); return *this; }
50 
51  Osd & operator<<( std::ostream& (*iomanip)( std::ostream& ) );
52 
53  private:
54  std::ostream & _str;
55  };
56 #define OSD ::zypp::debug::Osd()
57  }
58 }
59 #endif // ZYPP_NDEBUG
60 
83 
84 #ifndef ZYPP_BASE_LOGGER_LOGGROUP
85 
86 #define ZYPP_BASE_LOGGER_LOGGROUP "DEFINE_LOGGROUP"
87 #endif
88 
89 #define XXX L_XXX( ZYPP_BASE_LOGGER_LOGGROUP )
90 #define DBG L_DBG( ZYPP_BASE_LOGGER_LOGGROUP )
91 #define MIL L_MIL( ZYPP_BASE_LOGGER_LOGGROUP )
92 #define WAR L_WAR( ZYPP_BASE_LOGGER_LOGGROUP )
93 #define ERR L_ERR( ZYPP_BASE_LOGGER_LOGGROUP )
94 #define SEC L_SEC( ZYPP_BASE_LOGGER_LOGGROUP )
95 #define INT L_INT( ZYPP_BASE_LOGGER_LOGGROUP )
96 #define USR L_USR( ZYPP_BASE_LOGGER_LOGGROUP )
97 
98 #define L_XXX(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_XXX )
99 #define L_DBG(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP"++", zypp::base::logger::E_MIL )
100 #define L_MIL(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_MIL )
101 #define L_WAR(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_WAR )
102 #define L_ERR(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_ERR )
103 #define L_SEC(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_SEC )
104 #define L_INT(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_INT )
105 #define L_USR(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_USR )
106 
107 #define L_BASEFILE ( *__FILE__ == '/' ? strrchr( __FILE__, '/' ) + 1 : __FILE__ )
108 
110 #define ZYPP_BASE_LOGGER_LOG(GROUP,LEVEL) \
111  zypp::base::logger::getStream( GROUP, LEVEL, L_BASEFILE, __FUNCTION__, __LINE__ )
112 
115 namespace zypp
117 {
118  namespace base
120  {
121 
123  namespace logger
124  {
125 
130  enum LogLevel {
131  E_XXX = 999,
132  E_DBG = 0,
138  E_USR
139  };
140 
151  extern std::ostream & getStream( const char * group_r,
152  LogLevel level_r,
153  const char * file_r,
154  const char * func_r,
155  const int line_r );
156  extern bool isExcessive();
157 
159  } // namespace logger
161 
163  } // namespace base
166 } // namespace zypp
168 #endif // ZYPP_BASE_LOGGER_H
zypp::debug::Osd
Definition: Logger.h:43
zypp::debug::TraceLeave
Definition: Logger.h:28
zypp::debug::Osd::operator<<
Osd & operator<<(Tp &&val)
Definition: Logger.h:48
zypp::base::logger::E_DBG
@ E_DBG
Debug or verbose.
Definition: Logger.h:132
zypp::debug::TraceLeave::TraceLeave
TraceLeave(const TraceLeave &)=delete
zypp::debug::TraceLeave::operator=
TraceLeave & operator=(const TraceLeave &)=delete
zypp::base::logger::E_USR
@ E_USR
User log.
Definition: Logger.h:138
zypp::base::logger::E_WAR
@ E_WAR
Warning.
Definition: Logger.h:134
zypp::base::logger::getStream
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:429
zypp::debug::Osd::Osd
Osd(int=0)
Definition: LogControl.cc:75
zypp::debug::TraceLeave::_fnc
const char * _fnc
Definition: Logger.h:36
zypp::base::logger::E_SEC
@ E_SEC
Secutrity related.
Definition: Logger.h:136
zypp::base::logger::E_MIL
@ E_MIL
Milestone.
Definition: Logger.h:133
zypp::base::logger::LogLevel
LogLevel
Definition of log levels.
Definition: Logger.h:130
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
zypp::base::logger::E_ERR
@ E_ERR
Error.
Definition: Logger.h:135
zypp::base::logger::isExcessive
bool isExcessive()
Definition: LogControl.cc:452
zypp::debug::Osd::_str
std::ostream & _str
Definition: Logger.h:54
zypp::debug::TraceLeave::_depth
static unsigned _depth
Definition: Logger.h:34
zypp::debug::TraceLeave::_line
int _line
Definition: Logger.h:37
zypp::base::logger::E_XXX
@ E_XXX
Excessive logging.
Definition: Logger.h:131
zypp::debug::TraceLeave::_file
const char * _file
Definition: Logger.h:35
zypp::debug::TraceLeave::~TraceLeave
~TraceLeave()
Definition: LogControl.cc:68
zypp::debug::Osd::~Osd
~Osd()
Definition: LogControl.cc:79
zypp::base::logger::E_INT
@ E_INT
Internal error.
Definition: Logger.h:137