]>
Dogcows Code - chaz/yoink/blob - src/moof/log.hh
addf37c135f9066025c019aa7818ef16b93851d4
2 /*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
3 **] All rights reserved.
5 * Distributable under the terms and conditions of the 2-clause BSD license;
6 * see the file COPYING for a complete text of the license.
8 *****************************************************************************/
15 * Functions related to logging the process. The logging functions are
16 * log_error(), log_warning(), and log_info(), listed from most critical to
20 #include <cstdlib> // exit
28 // forward declarations
32 * A class for handling a log priority. There are two ways to log
33 * messages: by treating a log object as a function whose parameters are
34 * printed with default spacing, or by treating a log object as an output
35 * stream. Either way, any object can be printed to the log as long as
36 * there is an override for the ostream insertion operator.
43 * A type for the level or priority of a log message.
47 none
= 0, ///< Disable all logging.
48 error
= 1, ///< Log only errors.
49 warning
= 2, ///< Log warnings and errors.
50 info
= 3, ///< Log everything.
51 debug
= 4, ///< Log absolutely everything.
55 * Set the lowest-priority log message that will be outputted to the
56 * log. Any logging with a lower priority will be ignored.
57 * \param level The log level.
59 static void level(level level
);
62 * Get the current lowest-priority log level. If unchanged, the
63 * default level is info.
64 * \return The log level.
66 static enum level
level();
69 * Import log functions to a script.
72 static void import(script
& script
);
75 * Construct a log with a certain priority and prefix string.
76 * \param level The log level.
77 * \param prefix The string printed before each log message.
79 log(enum level level
);
82 * Output this to end a line. This is equivalent to std::endl except
83 * this will also reset terminal format attributes.
90 void operator () (const A
& a
)
95 template <class A
, class B
>
96 void operator () (const A
& a
, const B
& b
)
98 *this << a
<< " " << b
<< endl
;
101 template <class A
, class B
, class C
>
102 void operator () (const A
& a
, const B
& b
, const C
& c
)
104 *this << a
<< " " << b
<< " " << c
<< endl
;
107 template <class A
, class B
, class C
, class D
>
108 void operator () (const A
& a
, const B
& b
, const C
& c
, const D
& d
)
110 *this << a
<< " " << b
<< " " << c
<< " " << d
<< endl
;
113 template <class A
, class B
, class C
, class D
, class E
>
114 void operator () (const A
& a
,
120 *this << a
<< " " << b
<< " " << c
<< " " << d
<< " " << e
<<
126 template <class T
> friend std::ostream
& operator << (log
&, const T
&);
127 friend std::ostream
& operator << (log
&, endl_
);
129 static enum level global_level_
;
135 extern std::ostream
& log
;
136 extern std::ostream
& null_log
;
138 extern class log
& log_error
;
139 extern class log
& log_warning
;
140 extern class log
& log_info
;
141 extern class log
& log_debug
;
145 inline std::ostream
& operator << (class log
& log
, const T
& item
)
147 if (log::global_level_
< log
.level_
) return null_log
;
148 return moof::log
<< log
.prefix_
<< item
;
151 std::ostream
& operator << (class log
& log
, log::endl_ endl
);
152 std::ostream
& operator << (std::ostream
& stream
, log::endl_ endl
);
157 #endif // _MOOF_LOG_HH_
This page took 0.069113 seconds and 4 git commands to generate.