libzypp  17.35.16
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 
18 #include <zypp/Globals.h>
19 
21 #ifndef ZYPP_NDEBUG
22 namespace zypp
23 {
24  namespace debug
25  { // impl in LogControl.cc
26 
27  // Log code loacaton and block leave
28  // Indent if nested
30  {
31  TraceLeave( const TraceLeave & ) =delete;
32  TraceLeave & operator=( const TraceLeave & ) =delete;
33  TraceLeave( const char * file_r, const char * fnc_r, int line_r, std::string msg_r=std::string() );
34  ~TraceLeave();
35  private:
36  static unsigned _depth;
37  const char * _file;
38  const char * _fnc;
39  int _line;
40  std::string _msg;
41  };
42 #define TRACE(M) ::zypp::debug::TraceLeave _TraceLeave( __FILE__, __FUNCTION__, __LINE__, M );
43 #define XTRACE ::zypp::debug::TraceLeave _TraceLeave( __FILE__, __FUNCTION__, __LINE__ );
44 
45  // OnScreenDebug messages colored to stderr
46  struct ZYPP_API Osd
47  {
48  Osd( std::ostream &, int = 0 );
49  ~Osd();
50 
51  template<class Tp>
52  Osd & operator<<( Tp && val )
53  {
54  _strout << std::forward<Tp>(val);
55  _strlog << std::forward<Tp>(val);
56  return *this;
57  }
58 
59  Osd & operator<<( std::ostream& (*iomanip)( std::ostream& ) );
60 
61  private:
62  std::ostream & _strout;
63  std::ostream & _strlog;
64  };
65 #define OSD ::zypp::debug::Osd(L_USR("OSD"))
66  }
67 }
68 #endif // ZYPP_NDEBUG
69 
92 
93 #ifndef ZYPP_BASE_LOGGER_LOGGROUP
94 
95 #define ZYPP_BASE_LOGGER_LOGGROUP "DEFINE_LOGGROUP"
96 #endif
97 
98 #define XXX L_XXX( ZYPP_BASE_LOGGER_LOGGROUP )
99 #define DBG L_DBG( ZYPP_BASE_LOGGER_LOGGROUP )
100 #define MIL L_MIL( ZYPP_BASE_LOGGER_LOGGROUP )
101 #define WAR L_WAR( ZYPP_BASE_LOGGER_LOGGROUP )
102 #define ERR L_ERR( ZYPP_BASE_LOGGER_LOGGROUP )
103 #define SEC L_SEC( ZYPP_BASE_LOGGER_LOGGROUP )
104 #define INT L_INT( ZYPP_BASE_LOGGER_LOGGROUP )
105 #define USR L_USR( ZYPP_BASE_LOGGER_LOGGROUP )
106 
107 #define L_XXX(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_XXX )
108 #define L_DBG(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP"++", zypp::base::logger::E_MIL )
109 #define L_MIL(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_MIL )
110 #define L_WAR(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_WAR )
111 #define L_ERR(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_ERR )
112 #define L_SEC(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_SEC )
113 #define L_INT(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_INT )
114 #define L_USR(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_USR )
115 
116 
117 #define L_ENV_CONSTR_DEFINE_FUNC(ENV) \
118  namespace zypp::log { \
119  bool has_env_constr_##ENV () \
120  { \
121  static bool has_##ENV = (::getenv(#ENV) != NULL); \
122  return has_##ENV; \
123  } \
124  const char *empty_or_group_if_##ENV ( const char *group ) \
125  { \
126  return has_env_constr_##ENV() ? group : nullptr; \
127  } \
128  }
129 
130 #define L_ENV_CONSTR_FWD_DECLARE_FUNC(ENV) namespace zypp::log { bool has_env_constr_##ENV (); const char *empty_or_group_if_##ENV ( const char *group ); }
131 #define L_ENV_CONSTR(ENV,GROUP,LEVEL) ZYPP_BASE_LOGGER_LOG( zypp::log::empty_or_group_if_##ENV( GROUP ), LEVEL )
132 
133 #define L_BASEFILE ( *__FILE__ == '/' ? strrchr( __FILE__, '/' ) + 1 : __FILE__ )
134 
136 #define ZYPP_BASE_LOGGER_LOG(GROUP,LEVEL) \
137  zypp::base::logger::getStream( GROUP, LEVEL, L_BASEFILE, __FUNCTION__, __LINE__ )
138 
141 namespace zypp
143 {
144  namespace base
146  {
147 
149  namespace logger
150  {
151 
156  enum LogLevel {
157  E_XXX = 999,
158  E_DBG = 0,
165  };
166 
177  extern std::ostream & getStream( const char * group_r,
178  LogLevel level_r,
179  const char * file_r,
180  const char * func_r,
181  const int line_r ) ZYPP_API;
182  extern bool isExcessive() ZYPP_API;
183 
185  } // namespace logger
187 
189  } // namespace base
192 } // namespace zypp
194 #endif // ZYPP_BASE_LOGGER_H
Internal error.
Definition: Logger.h:163
Osd & operator<<(Tp &&val)
Definition: Logger.h:52
LogLevel
Definition of log levels.
Definition: Logger.h:156
std::ostream & _strlog
Definition: Logger.h:63
Debug or verbose.
Definition: Logger.h:158
std::ostream & _strout
Definition: Logger.h:62
Secutrity related.
Definition: Logger.h:162
const char * _fnc
Definition: Logger.h:38
std::string _msg
Definition: Logger.h:40
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition: ResTraits.h:93
std::ostream & operator<<(std::ostream &str, const Tm &obj)
Tm Stream output.
Definition: Measure.cc:128
static unsigned _depth
Definition: Logger.h:36
const char * _file
Definition: Logger.h:37
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:768
Excessive logging.
Definition: Logger.h:157
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19