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 2 or 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 void log(
39  char const* component,
40  std::exception_ptr const& exception,
41  std::string const& message);
42 
43 #ifndef MIR_LOG_COMPONENT
44 #ifdef MIR_LOG_COMPONENT_FALLBACK
45 #define MIR_LOG_COMPONENT MIR_LOG_COMPONENT_FALLBACK
46 #endif
47 #endif
48 
49 #ifdef MIR_LOG_COMPONENT
50 namespace {
51 // Isolated namespace so that the component string is always correct for
52 // where it's used.
53 
54 inline void log_info(std::string const& message)
55 {
57  MIR_LOG_COMPONENT, message);
58 }
59 
60 template<typename... Args>
61 void log_info(char const* fmt, Args&&... args)
62 {
64  MIR_LOG_COMPONENT, fmt, std::forward<Args>(args)...);
65 }
66 
67 template<typename... Args>
68 void log_error(char const* fmt, Args&&... args)
69 {
71  MIR_LOG_COMPONENT, fmt, std::forward<Args>(args)...);
72 }
73 
74 template<typename... Args>
75 inline void log_debug(char const* fmt, Args&&... args)
76 {
78  MIR_LOG_COMPONENT, fmt, std::forward<Args>(args)...);
79 }
80 
81 inline void log_critical(std::string const& message)
82 {
84  MIR_LOG_COMPONENT, message);
85 }
86 
87 template<typename... Args>
88 void log_critical(char const* fmt, Args&&... args)
89 {
91  MIR_LOG_COMPONENT, fmt, std::forward<Args>(args)...);
92 }
93 
94 inline void log_error(std::string const& message)
95 {
97  MIR_LOG_COMPONENT, message);
98 }
99 
100 inline void log_warning(std::string const& message)
101 {
103  MIR_LOG_COMPONENT, message);
104 }
105 
106 template<typename... Args>
107 void log_warning(char const* fmt, Args&&... args)
108 {
110  MIR_LOG_COMPONENT, fmt, std::forward<Args>(args)...);
111 }
112 } // (nested anonymous) namespace
113 #endif
114 
115 } // namespace mir
116 
117 #endif // MIR_LOG_H_
AutoUnblockThread is a helper thread class that can gracefully shutdown at destruction time...
Definition: sw_splash.h:26
void log(logging::Severity sev, char const *component, std::exception_ptr const &exception, 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-2017 Canonical Ltd.
Generated on Mon Oct 30 19:44:55 UTC 2017