libyui
 
Loading...
Searching...
No Matches
YUILog.h
1/*
2 Copyright (C) 2000-2012 Novell, Inc
3 This library is free software; you can redistribute it and/or modify
4 it under the terms of the GNU Lesser General Public License as
5 published by the Free Software Foundation; either version 2.1 of the
6 License, or (at your option) version 3.0 of the License. This library
7 is distributed in the hope that it will be useful, but WITHOUT ANY
8 WARRANTY; without even the implied warranty of MERCHANTABILITY or
9 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10 License for more details. You should have received a copy of the GNU
11 Lesser General Public License along with this library; if not, write
12 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13 Floor, Boston, MA 02110-1301 USA
14*/
15
16
17/*-/
18
19 File: YUILog.h
20
21 Author: Stefan Hundhammer <shundhammer@suse.de>
22
23/-*/
24
25#ifndef YUILog_h
26
27#ifndef YUILogComponent
28#error Missing #define YUILogComponent "myComponent" before #include "YUILog.h"
29#endif
30
31#include <iostream>
32#include <string>
33
34#include "ImplPtr.h"
35
36using std::endl;
37
38
39//
40// UI Logging: Macros for Application use.
41//
42// They all return a std::ostream & for use with operator<<().
43// #define YUILogComponent before including this header file
44// to identify what subsystem ("my-ui" etc.) this log line belongs to.
45//
46// #define YUILogComponent "myComponent"
47// #include <YUILog.h>
48//
49// ...
50// yuiDebug() << "Creating widget" << widget << endl;
51// yuiError() << "No widget with ID " << id << endl;
52//
53// Unless the underlying logger function handles this differently,
54// Milestone, Warning and Error are always logged, Debug only when enabled.
55//
56
57#define yuiDebug() YUILog::debug ( YUILogComponent, __FILE__, __LINE__, __FUNCTION__ )
58#define yuiMilestone() YUILog::milestone( YUILogComponent, __FILE__, __LINE__, __FUNCTION__ )
59#define yuiWarning() YUILog::warning ( YUILogComponent, __FILE__, __LINE__, __FUNCTION__ )
60#define yuiError() YUILog::error ( YUILogComponent, __FILE__, __LINE__, __FUNCTION__ )
61
62
63//
64// ------ End of user relevant part ------
65//
66
67
68
69class YUILogPrivate;
70
71enum YUILogLevel_t
72{
73 YUI_LOG_DEBUG = 0,
74 YUI_LOG_MILESTONE,
75 YUI_LOG_WARNING,
76 YUI_LOG_ERROR
77};
78
79
85typedef void (*YUILoggerFunction)( YUILogLevel_t, // logLevel
86 const char *, // logComponent
87 const char *, // sourceFileName
88 int, // sourceLineNo
89 const char *, // sourceFunctionName
90 const char * ); // message
91
92typedef void (*YUIEnableDebugLoggingFunction)( bool );
93typedef bool (*YUIDebugLoggingEnabledFunction)();
94
95
99class YUILog
100{
101public:
102
107 static std::ostream & debug ( const char * logComponent, const char * sourceFileName, int lineNo, const char * functionName );
108 static std::ostream & milestone( const char * logComponent, const char * sourceFileName, int lineNo, const char * functionName );
109 static std::ostream & warning ( const char * logComponent, const char * sourceFileName, int lineNo, const char * functionName );
110 static std::ostream & error ( const char * logComponent, const char * sourceFileName, int lineNo, const char * functionName );
111
115 std::ostream & log( YUILogLevel_t logLevel,
116 const char * logComponent,
117 const char * sourceFileName,
118 int lineNo,
119 const char * functionName );
120
125 static YUILog * instance();
126
130 static void enableDebugLogging( bool debugLogging = true );
131
135 static bool debugLoggingEnabled();
136
159 static bool setLogFileName( const std::string & logFileName );
160
166 static std::string logFileName();
167
176 static void setLoggerFunction( YUILoggerFunction loggerFunction );
177
185 static YUILoggerFunction loggerFunction( bool returnStdLogger = false );
186
197 static void setEnableDebugLoggingHooks( YUIEnableDebugLoggingFunction enableFunction,
198 YUIDebugLoggingEnabledFunction isEnabledFunction );
199
204 static YUIEnableDebugLoggingFunction enableDebugLoggingHook();
205
210 static YUIDebugLoggingEnabledFunction debugLoggingEnabledHook();
211
215 static std::string basename( const std::string & fileNameWithPath );
216
217
218private:
225 YUILog();
226
230 ~YUILog();
231
232 //
233 // Data
234 //
235
237};
238
239
240#define YUILog_h
241
242#endif // YUILog_h
Definition ImplPtr.h:43
static std::ostream & debug(const char *logComponent, const char *sourceFileName, int lineNo, const char *functionName)
Definition YUILog.cc:487
static bool debugLoggingEnabled()
Definition YUILog.cc:401
static YUIEnableDebugLoggingFunction enableDebugLoggingHook()
Definition YUILog.cc:442
static std::string basename(const std::string &fileNameWithPath)
Definition YUILog.cc:516
std::ostream & log(YUILogLevel_t logLevel, const char *logComponent, const char *sourceFileName, int lineNo, const char *functionName)
Definition YUILog.cc:456
static void setLoggerFunction(YUILoggerFunction loggerFunction)
Definition YUILog.cc:411
static YUIDebugLoggingEnabledFunction debugLoggingEnabledHook()
Definition YUILog.cc:449
static void setEnableDebugLoggingHooks(YUIEnableDebugLoggingFunction enableFunction, YUIDebugLoggingEnabledFunction isEnabledFunction)
Definition YUILog.cc:433
static void enableDebugLogging(bool debugLogging=true)
Definition YUILog.cc:391
static std::string logFileName()
Definition YUILog.cc:384
static YUILoggerFunction loggerFunction(bool returnStdLogger=false)
Definition YUILog.cc:421
static bool setLogFileName(const std::string &logFileName)
Definition YUILog.cc:348
static YUILog * instance()
Definition YUILog.cc:333
Definition YUILog.cc:255