libzypp 17.31.23
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
20namespace 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 );
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
66
88
89#ifndef ZYPP_BASE_LOGGER_LOGGROUP
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
113#define L_ENV_CONSTR_DEFINE_FUNC(ENV) \
114 namespace zypp::log { \
115 bool has_env_constr_##ENV () \
116 { \
117 static bool has_##ENV = (::getenv(#ENV) != NULL); \
118 return has_##ENV; \
119 } \
120 const char *empty_or_group_if_##ENV ( const char *group ) \
121 { \
122 return has_env_constr_##ENV() ? group : nullptr; \
123 } \
124 }
125
126#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 ); }
127#define L_ENV_CONSTR(ENV,GROUP,LEVEL) ZYPP_BASE_LOGGER_LOG( zypp::log::empty_or_group_if_##ENV( GROUP ), LEVEL )
128
129#define L_BASEFILE ( *__FILE__ == '/' ? strrchr( __FILE__, '/' ) + 1 : __FILE__ )
130
132#define ZYPP_BASE_LOGGER_LOG(GROUP,LEVEL) \
133 zypp::base::logger::getStream( GROUP, LEVEL, L_BASEFILE, __FUNCTION__, __LINE__ )
134
138namespace zypp
139{
141 namespace base
142 {
143
145 namespace logger
146 {
147
152 enum LogLevel {
153 E_XXX = 999,
154 E_DBG = 0,
155 E_MIL,
156 E_WAR,
157 E_ERR,
158 E_SEC,
159 E_INT,
160 E_USR
161 };
162
173 extern std::ostream & getStream( const char * group_r,
174 LogLevel level_r,
175 const char * file_r,
176 const char * func_r,
177 const int line_r );
178 extern bool isExcessive();
179
181 } // namespace logger
183
185 } // namespace base
188} // namespace zypp
190#endif // ZYPP_BASE_LOGGER_H
LogLevel
Definition of log levels.
Definition: Logger.h:152
@ E_SEC
Secutrity related.
Definition: Logger.h:158
@ E_ERR
Error.
Definition: Logger.h:157
@ E_XXX
Excessive logging.
Definition: Logger.h:153
@ E_DBG
Debug or verbose.
Definition: Logger.h:154
@ E_USR
User log.
Definition: Logger.h:160
@ E_WAR
Warning.
Definition: Logger.h:156
@ E_MIL
Milestone.
Definition: Logger.h:155
@ E_INT
Internal error.
Definition: Logger.h:159
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:745
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
std::ostream & _strlog
Definition: Logger.h:59
Osd(std::ostream &, int=0)
Definition: LogControl.cc:335
std::ostream & _strout
Definition: Logger.h:58
Osd & operator<<(Tp &&val)
Definition: Logger.h:48
TraceLeave(const TraceLeave &)=delete
static unsigned _depth
Definition: Logger.h:34
TraceLeave & operator=(const TraceLeave &)=delete
const char * _fnc
Definition: Logger.h:36
const char * _file
Definition: Logger.h:35