1- /*
1+ /*
22 * File: log.h
33 * Author: doe300
44 *
1414
1515namespace CPPLOG_NAMESPACE
1616{
17-
18- /* !
19- * The log-level
20- */
21- enum class Level : unsigned char
22- {
23- DEBUG = ' D' ,
24- INFO = ' I' ,
25- // something is not as expected
26- WARNING = ' W' ,
27- // program-error
28- ERROR = ' E' ,
29- // critical software-error
30- SEVERE = ' S'
31- };
32-
33- std::wostream& log (Level level);
34- std::wostream& endl (std::wostream& stream);
35-
36- inline std::wostream& debug ()
37- {
38- return CPPLOG_NAMESPACE::log (Level::DEBUG);
39- }
40-
41- inline std::wostream& info ()
42- {
43- return CPPLOG_NAMESPACE::log (Level::INFO);
44- }
45-
46- inline std::wostream& warn ()
47- {
48- return CPPLOG_NAMESPACE::log (Level::WARNING);
49- }
50-
51- inline std::wostream& error ()
52- {
53- return CPPLOG_NAMESPACE::log (Level::ERROR);
54- }
55-
56- inline std::wostream& severe ()
57- {
58- return CPPLOG_NAMESPACE::log (Level::SEVERE);
59- }
60-
61- void logf (Level level, const wchar_t * format, ...);
62-
63- /* !
64- * Wrapper around a logging statement to only execute it if the level of logging
65- * will be written to the output.
66- * This can be used to skip complex logging statements when not required.
67- */
68- void logLazy (Level level, std::function<void (std::wostream&)>&& statement);
69-
70- /* !
71- * Wrapper around several logging statements to only execute them if the level of
72- * logging will be written to the output.
73- * This can be used to skip complex logging statements when not required.
74- */
75- void logLazy (Level level, std::function<void ()>&& statement);
76-
77- // Forward-declaration for the logger-instance
78- class Logger ;
79- /* !
80- * This is the Logger-instance being used to write the logs.
81- *
82- * Use this variable to set a custom Logger-instance.
83- * To disable logging (or stopping running logging), set this LOGGER to nullptr
84- */
85- extern std::unique_ptr<Logger> LOGGER;
86- }
17+ /* !
18+ * The log-level
19+ */
20+ enum class Level : unsigned char
21+ {
22+ DEBUG = ' D' ,
23+ INFO = ' I' ,
24+ // something is not as expected
25+ WARNING = ' W' ,
26+ // program-error
27+ ERROR = ' E' ,
28+ // critical software-error
29+ SEVERE = ' S'
30+ };
31+
32+ std::wostream& log (Level level);
33+ std::wostream& endl (std::wostream& stream);
34+
35+ inline std::wostream& debug ()
36+ {
37+ return CPPLOG_NAMESPACE::log (Level::DEBUG);
38+ }
39+
40+ inline std::wostream& info ()
41+ {
42+ return CPPLOG_NAMESPACE::log (Level::INFO);
43+ }
44+
45+ inline std::wostream& warn ()
46+ {
47+ return CPPLOG_NAMESPACE::log (Level::WARNING);
48+ }
49+
50+ inline std::wostream& error ()
51+ {
52+ return CPPLOG_NAMESPACE::log (Level::ERROR);
53+ }
54+
55+ inline std::wostream& severe ()
56+ {
57+ return CPPLOG_NAMESPACE::log (Level::SEVERE);
58+ }
59+
60+ void logf (Level level, const wchar_t * format, ...);
61+
62+ /* !
63+ * Wrapper around a logging statement to only execute it if the level of logging
64+ * will be written to the output.
65+ * This can be used to skip complex logging statements when not required.
66+ */
67+ void logLazy (Level level, std::function<void (std::wostream&)>&& statement);
68+
69+ /* !
70+ * Wrapper around several logging statements to only execute them if the level of
71+ * logging will be written to the output.
72+ * This can be used to skip complex logging statements when not required.
73+ */
74+ void logLazy (Level level, std::function<void ()>&& statement);
75+
76+ // Forward-declaration for the logger-instance
77+ class Logger ;
78+ /* !
79+ * This is the Logger-instance being used to write the logs.
80+ *
81+ * Use this variable to set a custom Logger-instance.
82+ * To disable logging (or stopping running logging), set this LOGGER to nullptr
83+ */
84+ extern std::unique_ptr<Logger> LOGGER;
85+ } // namespace CPPLOG_NAMESPACE
8786
8887/* !
8988 * Convenience-wrapper to allow writing std::string into std::wostream
9089 */
91- std::wostream& operator <<(std::wostream& stream, const std::string& string);
90+ std::wostream& operator <<(std::wostream& stream, const std::string& string);
9291
9392/* !
9493 * Convenience macro for lazy logging.
@@ -97,21 +96,14 @@ std::wostream& operator <<(std::wostream& stream, const std::string& string);
9796 * Example usage:
9897 * CPPLOG_LAZY(Level::DEBUG, log << "Hello World! << endl);
9998 */
100- #define CPPLOG_LAZY (level, content ) \
101- CPPLOG_NAMESPACE::logLazy (level, [&](std::wostream& log){ \
102- content; \
103- })\
99+ #define CPPLOG_LAZY (level, content ) CPPLOG_NAMESPACE::logLazy(level, [&](std::wostream& log) { content; })
104100
105101/* !
106102 * Convenience macro for lazy logging.
107103 *
108104 * Example usage:
109105 * CPPLOG_LAZY(Level::DEBUG, debug() << "Hello World! << endl; debug() << "Second statement!" << endl);
110106 */
111- #define CPPLOG_LAZY_BLOCK (level, content ) \
112- CPPLOG_NAMESPACE::logLazy (level, [&](){ \
113- content; \
114- })\
107+ #define CPPLOG_LAZY_BLOCK (level, content ) CPPLOG_NAMESPACE::logLazy(level, [&]() { content; })
115108
116109#endif /* LOG_H */
117-
0 commit comments