yast2-core
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
liby2util-r
src
include
y2util
liby2util-r/src/include/y2util/y2log.h
Go to the documentation of this file.
1
/* y2log.h
2
*
3
* YaST2: Core system
4
*
5
* YaST2 logging implementation
6
*
7
* Authors: Mathias Kettner <kettner@suse.de>
8
* Michal Svec <msvec@suse.cz>
9
*
10
* $Id$
11
*/
12
13
#ifndef _y2log_h
14
#define _y2log_h
15
16
#include <string>
17
#include <stdio.h>
18
19
using
std::string;
20
21
/* Logging levels */
22
23
enum
loglevel_t
{
24
LOG_DEBUG
= 0,
// debug message
25
LOG_MILESTONE
= 1,
// log great events, big steps
26
LOG_WARNING
= 2,
// warning in application level
27
LOG_ERROR
= 3,
// error in application level
28
LOG_SECURITY
= 4,
// security relevant problem or incident
29
LOG_INTERNAL
= 5
// internal bug. Please report to...
30
};
31
32
/* Logging functions */
33
34
// Implements y2_logger
35
void
y2_logger_function
(
loglevel_t
level,
const
string
& component,
const
char
*file,
36
const
int
line,
const
char
*func,
const
char
*format, ...)
37
__attribute__ ((format (printf, 6, 7)));
38
// The knights of Blanik only show up when nothing else can help, and so will
39
// the messages logged here. fate#302166
40
void
y2_logger_blanik
(
loglevel_t
level, const
string
& component, const
char
*file,
41
const
int
line, const
char
*func, const
char
*format, ...)
42
__attribute__ ((format (printf, 6, 7)));
43
44
// Same as above, but with va_list
45
void
y2_vlogger_function
(
loglevel_t
level, const
string
& component, const
char
*file,
46
const
int
line, const
char
*func, const
char
*format, va_list ap);
47
void
y2_vlogger_blanik
(
loglevel_t
level, const
string
& component, const
char
*file,
48
const
int
line, const
char
*func, const
char
*format, va_list ap);
49
50
void
y2_logger_raw
( const
char
* message );
51
52
/* Logging defines */
53
54
#ifdef y2log_subcomponent
55
# define y2log_suffix "-" y2log_subcomponent
56
#else
57
# define y2log_suffix
58
#endif
59
60
#ifdef y2log_component
61
# define y2log_prefix y2log_component y2log_suffix
62
#else
63
# ifdef Y2LOG
64
# define y2log_prefix Y2LOG y2log_suffix
65
# else
66
# error neither y2log_component nor Y2LOG defined
67
# define y2log_prefix ""
68
# endif
69
#endif
70
71
#define y2_logger(level,comp,file,line,function,format,args...) \
72
do { \
73
if (should_be_logged (level, comp)) \
74
y2_logger_function (level,comp,file,line,function,format,##args);\
75
else if (should_be_buffered ()) \
76
y2_logger_blanik (level,comp,file,line,function,format,##args); \
77
} while (0)
78
79
#define y2_vlogger(level,comp,file,line,function,format,args) \
80
do { \
81
if (should_be_logged (level, comp)) \
82
y2_vlogger_function (level,comp,file,line,function,format,args);\
83
else if (should_be_buffered ()) \
84
y2_vlogger_blanik (level,comp,file,line,function,format,args); \
85
} while (0)
86
87
/*
88
* Caution: Don't use
89
* if (shouldbelogged(...) y2_logger(...)
90
* above - this clashes with any
91
* if (...)
92
* y2error(...)
93
* else
94
* since the "else" branch always refers to the inner (!) "if"
95
* - in this case, the "if" of this macro :-((
96
*/
97
98
#define y2logger(level, format, args...) \
99
y2_logger(level,y2log_prefix,__FILE__,__LINE__,__FUNCTION__,format,##args)
100
101
#define y2vlogger(level, format, ap) \
102
y2_vlogger(level,y2log_prefix,__FILE__,__LINE__,__FUNCTION__,format,ap)
103
104
#ifdef WITHOUT_Y2DEBUG
105
# define y2debug(format, args...)
106
#else
107
# define y2debug(format, args...) y2logger(LOG_DEBUG,format,##args)
108
#endif
109
110
#define y2milestone(format, args...) y2logger(LOG_MILESTONE,format,##args)
111
#define y2warning(format, args...) y2logger(LOG_WARNING,format,##args)
112
#define y2error(format, args...) y2logger(LOG_ERROR,format,##args)
113
#define y2security(format, args...) y2logger(LOG_SECURITY,format,##args)
114
#define y2internal(format, args...) y2logger(LOG_INTERNAL,format,##args)
115
116
#define y2lograw(message) y2_logger_raw(message)
117
121
bool
should_be_logged
(
int
loglevel,
const
string
& componentname);
122
126
bool
should_be_buffered
();
127
136
void
set_log_filename
(
string
filename);
137
string
get_log_filename
();
138
145
void
set_log_conf
(
string
confname);
146
150
void
set_log_simple_mode
(
bool
simple);
151
156
void
set_log_debug
(
bool
on =
true
);
157
161
bool
get_log_debug
();
162
163
// stores a few strings. can append one. can return all. old are forgotten.
164
class
LogTail
{
165
public
:
166
typedef
string
Data
;
167
LogTail
(
size_t
max_size = 42);
168
~LogTail
();
169
void
push_back
(
const
Data
&);
170
171
// consumer returns true to continue iterating
172
typedef
bool (*
Consumer
) (
const
Data
&);
173
void
for_each
(
Consumer
c);
174
private
:
175
class
Impl
;
176
Impl
*
m_impl
;
177
};
178
179
// the instance used for last resort logging
180
extern
LogTail
blanik
;
181
182
#endif
/* _y2log_h */
Generated on a sunny day for yast2-core by
1.8.2