]>
Dogcows Code - chaz/yoink/blob - src/Moof/Log.hh
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
10 **************************************************************************/
17 * Functions related to logging the process.
18 * The logging functions are logError(), logWarning(), and logInfo(),
19 * listed from most critical to least critical.
22 #include <cstdlib> // exit
27 * Macro which tests an assertion and issues a logError() and exits if the
29 * \param X test to perform
37 #define ASSERT(X) if (!(X)) Mf::logError \
38 << "false assertion at " << __FILE__ << ":" << __LINE__ << ", " \
47 * A class for handling a log priority. There are two ways to log
48 * messages: by treating a log object as a function whose parameters are
49 * printed with default spacing, or by treating a log object as an output
50 * stream. Either way, any object can be printed to the log as long as
51 * there is an override for the ostream insertion operator.
58 * A type for the level or priority of a log message.
62 NONE
= 0, ///< Disable all logging.
63 ERRORR
= 1, ///< Log only errors.
64 WARNING
= 2, ///< Log warnings and errors.
65 INFO
= 3, ///< Log everything.
70 * Set the lowest-priority log message that will be outputted to the
71 * log. Any logging with a lower priority will be ignored.
72 * \param level The log level.
74 static void setLevel(Level level
);
77 * Get the current lowest-priority log level. If unchanged, the
78 * default level is INFO.
79 * \return The log level.
85 * Construct a log with a certain priority and prefix string.
86 * \param level The log level.
87 * \param prefix The string printed before each log message.
89 Log(Level level
, const char* prefix
) :
91 mPrefix(prefix
) /* only pass literal strings */ {}
95 void operator () (const A
& a
)
97 *this << a
<< std::endl
;
100 template <class A
, class B
>
101 void operator () (const A
& a
, const B
& b
)
103 *this << a
<< " " << b
<< std::endl
;
106 template <class A
, class B
, class C
>
107 void operator () (const A
& a
, const B
& b
, const C
& c
)
109 *this << a
<< " " << b
<< " " << c
<< std::endl
;
112 template <class A
, class B
, class C
, class D
>
113 void operator () (const A
& a
, const B
& b
, const C
& c
, const D
& d
)
115 *this << a
<< " " << b
<< " " << c
<< " " << d
<< std::endl
;
118 template <class A
, class B
, class C
, class D
, class E
>
119 void operator () (const A
& a
,
135 template <class T
> friend std::ostream
& operator << (Log
&, const T
&);
144 extern std::ostream
& log
;
145 extern std::ostream
& nullLog
;
148 extern Log logWarning
;
153 inline std::ostream
& operator << (Log
& logObj
, const T
& item
)
155 if (Log::gLevel
< logObj
.mLevel
) return nullLog
;
156 return log
<< logObj
.mPrefix
<< item
;
161 void importLogFunctions(Script
& script
);
166 #endif // _MOOF_LOG_H_
This page took 0.036451 seconds and 4 git commands to generate.