libzypp: zypp-core/base/Logger.h Source File

libzypp 17.38.6

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-core/Globals.h>
19
21#ifndef ZYPP_NDEBUG
22namespace zypp
23{
24 namespace debug
25 { // impl in LogControl.cc
26
27 // Log code loacaton and block leave
28 // Indent if nested
29 struct ZYPP_API TraceLeave
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
66 Osd & getOSD();
67
68#define OSD ::zypp::debug::getOSD()
69 }
70}
71#endif // ZYPP_NDEBUG
73
95
96#ifndef ZYPP_BASE_LOGGER_LOGGROUP
98#define ZYPP_BASE_LOGGER_LOGGROUP "DEFINE_LOGGROUP"
99#endif
100
101#define XXX L_XXX( ZYPP_BASE_LOGGER_LOGGROUP )
102#define DBG L_DBG( ZYPP_BASE_LOGGER_LOGGROUP )
103#define MIL L_MIL( ZYPP_BASE_LOGGER_LOGGROUP )
104#define WAR L_WAR( ZYPP_BASE_LOGGER_LOGGROUP )
105#define ERR L_ERR( ZYPP_BASE_LOGGER_LOGGROUP )
106#define SEC L_SEC( ZYPP_BASE_LOGGER_LOGGROUP )
107#define INT L_INT( ZYPP_BASE_LOGGER_LOGGROUP )
108#define USR L_USR( ZYPP_BASE_LOGGER_LOGGROUP )
109
110#define L_XXX(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_XXX )
111#define L_DBG(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP"++", zypp::base::logger::E_MIL )
112#define L_MIL(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_MIL )
113#define L_WAR(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_WAR )
114#define L_ERR(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_ERR )
115#define L_SEC(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_SEC )
116#define L_INT(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_INT )
117#define L_USR(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_USR )
118
119
120#define L_ENV_CONSTR_DEFINE_FUNC(ENV) \
121 namespace zypp::log { \
122 bool has_env_constr_##ENV () \
123 { \
124 static bool has_##ENV = (::getenv(#ENV) != NULL); \
125 return has_##ENV; \
126 } \
127 const char *empty_or_group_if_##ENV ( const char *group ) \
128 { \
129 return has_env_constr_##ENV() ? group : nullptr; \
130 } \
131 }
132
133#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 ); }
134#define L_ENV_CONSTR(ENV,GROUP,LEVEL) ZYPP_BASE_LOGGER_LOG( zypp::log::empty_or_group_if_##ENV( GROUP ), LEVEL )
135
136#define L_BASEFILE ( *__FILE__ == '/' ? strrchr( __FILE__, '/' ) + 1 : __FILE__ )
137
139#define ZYPP_BASE_LOGGER_LOG(GROUP,LEVEL) \
140 zypp::base::logger::getStream( GROUP, LEVEL, L_BASEFILE, __FUNCTION__, __LINE__ )
141
143
145namespace zypp
146{
148 namespace base
149 {
150
152 namespace logger
153 {
154
159 enum LogLevel {
160 E_XXX = 999,
161 E_DBG = 0,
162 E_MIL,
163 E_WAR,
164 E_ERR,
165 E_SEC,
166 E_INT,
167 E_USR
168 };
169
180 extern std::ostream & getStream( const char * group_r,
181 LogLevel level_r,
182 const char * file_r,
183 const char * func_r,
184 const int line_r ) ZYPP_API;
185 extern bool isExcessive() ZYPP_API;
186
188 } // namespace logger
190
192 } // namespace base
195} // namespace zypp
197#endif // ZYPP_BASE_LOGGER_H
Globals.h
Provides API related macros.
operator<<
std::ostream & operator<<(std::ostream &str, const zypp::sat::detail::CDataiterator *obj)
relates: zypp::sat::LookupAttr::iterator Stream output of the underlying iterator for debug.
Definition LookupAttr.cc:808
zypp::base::logger::LogLevel
LogLevel
Definition of log levels.
Definition Logger.h:159
zypp::base::logger::E_SEC
@ E_SEC
Secutrity related.
Definition Logger.h:165
zypp::base::logger::E_ERR
@ E_ERR
Error.
Definition Logger.h:164
zypp::base::logger::E_XXX
@ E_XXX
Excessive logging.
Definition Logger.h:160
zypp::base::logger::E_DBG
@ E_DBG
Debug or verbose.
Definition Logger.h:161
zypp::base::logger::E_USR
@ E_USR
User log.
Definition Logger.h:167
zypp::base::logger::E_WAR
@ E_WAR
Warning.
Definition Logger.h:163
zypp::base::logger::E_MIL
@ E_MIL
Milestone.
Definition Logger.h:162
zypp::base::logger::E_INT
@ E_INT
Internal error.
Definition Logger.h:166
zypp::base::logger::isExcessive
bool isExcessive()
Definition LogControl.cc:810
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:775
zypp::debug
Definition Debug.h:31
zypp::debug::getOSD
Osd & getOSD()
Definition LogControl.cc:358
zypp::iomanip
Definition LogTools.h:443
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::ZYPP_API
const Arch Arch_empty ZYPP_API
relates: Arch This is an empty Arch represented by an empty string.
Definition Arch.h:173
zypp::debug::Osd
Definition Logger.h:47
zypp::debug::Osd::_strlog
std::ostream & _strlog
Definition Logger.h:63
zypp::debug::Osd::Osd
Osd(std::ostream &, int=0)
Definition LogControl.cc:343
zypp::debug::Osd::_strout
std::ostream & _strout
Definition Logger.h:62
zypp::debug::Osd::operator<<
Osd & operator<<(Tp &&val)
Definition Logger.h:52
zypp::debug::TraceLeave::TraceLeave
TraceLeave(const TraceLeave &)=delete
zypp::debug::TraceLeave::_depth
static unsigned _depth
Definition Logger.h:36
zypp::debug::TraceLeave::_line
int _line
Definition Logger.h:39
zypp::debug::TraceLeave::_msg
std::string _msg
Definition Logger.h:40
zypp::debug::TraceLeave::operator=
TraceLeave & operator=(const TraceLeave &)=delete
zypp::debug::TraceLeave::_fnc
const char * _fnc
Definition Logger.h:38
zypp::debug::TraceLeave::_file
const char * _file
Definition Logger.h:37