libzypp 17.38.14
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
21namespace zypp::debug {
22 // impl in LogControl.cc, but not in ZYPP_NDEBUG; BLOCKTRACE logs MIL
24 {
25 BlockTraceBase( const BlockTraceBase & ) =delete;
27 BlockTraceBase( const char * file_r, const char * fnc_r, int line_r, std::string msg_r=std::string() )
28 : _file { file_r }
29 , _fnc { fnc_r }
30 , _line { line_r }
31 , _msg { std::move(msg_r) }
32 {}
33 protected:
34 static unsigned _depth;
35 const char * _file;
36 const char * _fnc;
37 int _line;
38 std::string _msg;
39 };
40
41 // Log code location and block leave as MIL
42 struct BlockTrace : private BlockTraceBase
43 {
44 BlockTrace( const BlockTrace & ) =delete;
45 BlockTrace & operator=( const BlockTrace & ) =delete;
46 BlockTrace( const char * file_r, const char * fnc_r, int line_r, std::string msg_r=std::string() );
48 private:
49 static unsigned _depth;
50 };
51#define BLOCKTRACE(M) ::zypp::debug::BlockTrace _BlockTrace( L_BASEFILE, __FUNCTION__, __LINE__, M )
52} // namespace zypp::debug
53
55#ifndef ZYPP_NDEBUG
56namespace zypp::debug {
57 // impl in LogControl.cc, and in ZYPP_NDEBUG (due to OSD)
58
59 // Log code location and block leave as \ref Osd
60 // Indent if nested
62 {
63 TraceLeave( const TraceLeave & ) =delete;
64 TraceLeave & operator=( const TraceLeave & ) =delete;
65 TraceLeave( const char * file_r, const char * fnc_r, int line_r, std::string msg_r=std::string() );
67 private:
68 static unsigned _depth;
69 };
70#define TRACE(M) ::zypp::debug::TraceLeave _TraceLeave( __FILE__, __FUNCTION__, __LINE__, M );
71#define XTRACE ::zypp::debug::TraceLeave _TraceLeave( __FILE__, __FUNCTION__, __LINE__ );
72
73 // OnScreenDebug messages colored to stderr
75 {
76 Osd( std::ostream &, int = 0 );
77 ~Osd();
78
79 template<class Tp>
80 Osd & operator<<( Tp && val )
81 {
82 _strout << std::forward<Tp>(val);
83 _strlog << std::forward<Tp>(val);
84 return *this;
85 }
86
87 Osd & operator<<( std::ostream& (*iomanip)( std::ostream& ) );
88
89 private:
90 std::ostream & _strout;
91 std::ostream & _strlog;
92 };
93
95#define OSD ::zypp::debug::getOSD()
96} // namespace zypp::debug
97#endif // ZYPP_NDEBUG
98
100
122
123#ifndef ZYPP_BASE_LOGGER_LOGGROUP
125#define ZYPP_BASE_LOGGER_LOGGROUP "DEFINE_LOGGROUP"
126#endif
127
128#define XXX L_XXX( ZYPP_BASE_LOGGER_LOGGROUP )
129#define DBG L_DBG( ZYPP_BASE_LOGGER_LOGGROUP )
130#define MIL L_MIL( ZYPP_BASE_LOGGER_LOGGROUP )
131#define WAR L_WAR( ZYPP_BASE_LOGGER_LOGGROUP )
132#define ERR L_ERR( ZYPP_BASE_LOGGER_LOGGROUP )
133#define SEC L_SEC( ZYPP_BASE_LOGGER_LOGGROUP )
134#define INT L_INT( ZYPP_BASE_LOGGER_LOGGROUP )
135#define USR L_USR( ZYPP_BASE_LOGGER_LOGGROUP )
136
137#define L_XXX(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_XXX )
138#define L_DBG(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP"++", zypp::base::logger::E_MIL )
139#define L_MIL(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_MIL )
140#define L_WAR(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_WAR )
141#define L_ERR(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_ERR )
142#define L_SEC(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_SEC )
143#define L_INT(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_INT )
144#define L_USR(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_USR )
145
146
147#define L_ENV_CONSTR_DEFINE_FUNC(ENV) \
148 namespace zypp::log { \
149 bool has_env_constr_##ENV () \
150 { \
151 static bool has_##ENV = (::getenv(#ENV) != NULL); \
152 return has_##ENV; \
153 } \
154 const char *empty_or_group_if_##ENV ( const char *group ) \
155 { \
156 return has_env_constr_##ENV() ? group : nullptr; \
157 } \
158 }
159
160#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 ); }
161#define L_ENV_CONSTR(ENV,GROUP,LEVEL) ZYPP_BASE_LOGGER_LOG( zypp::log::empty_or_group_if_##ENV( GROUP ), LEVEL )
162
163#define L_BASEFILE ( *__FILE__ == '/' ? strrchr( __FILE__, '/' ) + 1 : __FILE__ )
164
166#define ZYPP_BASE_LOGGER_LOG(GROUP,LEVEL) \
167 zypp::base::logger::getStream( GROUP, LEVEL, L_BASEFILE, __FUNCTION__, __LINE__ )
168
170
172namespace zypp
173{
175 namespace base
176 {
177
179 namespace logger
180 {
181
196
207 extern std::ostream & getStream( const char * group_r,
208 LogLevel level_r,
209 const char * file_r,
210 const char * func_r,
211 const int line_r ) ZYPP_API;
212 extern bool isExcessive() ZYPP_API;
213
215 } // namespace logger
217
219 } // namespace base
222} // namespace zypp
224#endif // ZYPP_BASE_LOGGER_H
Provides API related macros.
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 ansi.h:855
LogLevel
Definition of log levels.
Definition Logger.h:186
@ E_SEC
Secutrity related.
Definition Logger.h:192
@ E_XXX
Excessive logging.
Definition Logger.h:187
@ E_DBG
Debug or verbose.
Definition Logger.h:188
@ E_USR
User log.
Definition Logger.h:194
@ E_WAR
Warning.
Definition Logger.h:190
@ E_MIL
Milestone.
Definition Logger.h:189
@ E_INT
Internal error.
Definition Logger.h:193
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.
Osd & getOSD()
Easy-to use interface to the ZYPP dependency resolver.
const Arch Arch_empty ZYPP_API
relates: Arch This is an empty Arch represented by an empty string.
Definition Arch.h:173
BlockTraceBase(const BlockTraceBase &)=delete
BlockTraceBase(const char *file_r, const char *fnc_r, int line_r, std::string msg_r=std::string())
Definition Logger.h:27
BlockTraceBase & operator=(const BlockTraceBase &)=delete
static unsigned _depth
Definition Logger.h:34
BlockTrace(const BlockTrace &)=delete
BlockTrace & operator=(const BlockTrace &)=delete
static unsigned _depth
Definition Logger.h:49
std::ostream & _strlog
Definition Logger.h:91
Osd(std::ostream &, int=0)
std::ostream & _strout
Definition Logger.h:90
Osd & operator<<(Tp &&val)
Definition Logger.h:80
TraceLeave(const TraceLeave &)=delete
static unsigned _depth
Definition Logger.h:68
TraceLeave & operator=(const TraceLeave &)=delete