Mir
log.h
Go to the documentation of this file.
1 /*
2  * Convenience functions to make logging in Mir easy
3  * ~~~
4  * Copyright © 2014 Canonical Ltd.
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License version 3,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * Author: Daniel van Vugt <daniel.van.vugt@canonical.com>
19  */
20 
21 #ifndef MIR_LOG_H_
22 #define MIR_LOG_H_
23 
24 #include "mir/logging/logger.h" // for Severity
25 #include <string>
26 #include <cstdarg>
27 
28 namespace mir
29 {
30 
31 void logv(logging::Severity sev, const char *component,
32  char const* fmt, va_list va);
33 void log(logging::Severity sev, const char *component,
34  char const* fmt, ...);
35 void log(logging::Severity sev, const char *component,
36  std::string const& message);
37 
38 #ifndef MIR_LOG_COMPONENT
39 #ifdef MIR_LOG_COMPONENT_FALLBACK
40 #define MIR_LOG_COMPONENT MIR_LOG_COMPONENT_FALLBACK
41 #endif
42 #endif
43 
44 #ifdef MIR_LOG_COMPONENT
45 namespace {
46 // Isolated namespace so that the component string is always correct for
47 // where it's used.
48 
49 inline void log_info(std::string const& message)
50 {
52  MIR_LOG_COMPONENT, message);
53 }
54 
55 // TODO later as required: error, critical, warning, debug
56 
57 template<typename... Args>
58 void log_info(char const* fmt, Args... args)
59 {
61  MIR_LOG_COMPONENT, fmt, args...);
62 }
63 
64 template<typename... Args>
65 void log_error(char const* fmt, Args... args)
66 {
68  MIR_LOG_COMPONENT, fmt, args...);
69 }
70 
71 inline void log_critical(std::string const& message)
72 {
74  MIR_LOG_COMPONENT, message);
75 }
76 
77 
78 inline void log_error(std::string const& message)
79 {
81  MIR_LOG_COMPONENT, message);
82 }
83 
84 } // (nested anonymous) namespace
85 #endif
86 
87 } // namespace mir
88 
89 #endif // MIR_LOG_H_
All things Mir.
Definition: buffer_stream.h:37
void log(logging::Severity sev, char const *component, char const *fmt,...)
Definition: log.cpp:39
#define MIR_LOG_COMPONENT
Definition: buffer_stream.cpp:19
void logv(logging::Severity sev, char const *component, char const *fmt, va_list va)
Definition: log.cpp:25
Severity
Definition: logger.h:30

Copyright © 2012,2013 Canonical Ltd.
Generated on Tue Mar 24 16:15:19 UTC 2015