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 template<typename... Args>
56 void log_info(char const* fmt, Args&&... args)
57 {
59  MIR_LOG_COMPONENT, fmt, std::forward<Args>(args)...);
60 }
61 
62 template<typename... Args>
63 void log_error(char const* fmt, Args&&... args)
64 {
66  MIR_LOG_COMPONENT, fmt, std::forward<Args>(args)...);
67 }
68 
69 template<typename... Args>
70 inline void log_debug(char const* fmt, Args&&... args)
71 {
73  MIR_LOG_COMPONENT, fmt, std::forward<Args>(args)...);
74 }
75 
76 inline void log_critical(std::string const& message)
77 {
79  MIR_LOG_COMPONENT, message);
80 }
81 
82 inline void log_error(std::string const& message)
83 {
85  MIR_LOG_COMPONENT, message);
86 }
87 
88 inline void log_warning(std::string const& message)
89 {
91  MIR_LOG_COMPONENT, message);
92 }
93 
94 template<typename... Args>
95 void log_warning(char const* fmt, Args&&... args)
96 {
98  MIR_LOG_COMPONENT, fmt, std::forward<Args>(args)...);
99 }
100 
101 } // (nested anonymous) namespace
102 #endif
103 
104 } // namespace mir
105 
106 #endif // MIR_LOG_H_
Definition: as_render_target.h:27
void log(logging::Severity sev, const char *component, std::string const &message)
void logv(logging::Severity sev, const char *component, char const *fmt, va_list va)
void log(logging::Severity sev, const char *component, char const *fmt,...)
Severity
Definition: logger.h:30

Copyright © 2012-2016 Canonical Ltd.
Generated on Wed May 10 10:41:27 UTC 2017