client-cpp  0.10.0
Log.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014-2016 CyberVision, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef LOG_HPP_
18 #define LOG_HPP_
19 
20 #include "kaa/KaaDefaults.hpp"
21 
22 #if KAA_LOG_LEVEL > KAA_LOG_LEVEL_NONE
23 #include "kaa/logging/ILogger.hpp"
24 
25 #include <string.h>
26 #include <boost/format.hpp>
27 
28 
29 #ifdef _WIN32
30 #define PATH_SEPARATOR '\\'
31 #else
32 #define PATH_SEPARATOR '/'
33 #endif
34 
35 #define __LOGFILE (strrchr(__FILE__, PATH_SEPARATOR) ? strrchr(__FILE__, PATH_SEPARATOR) + 1 : __FILE__)
36 
37 #endif
38 
39 namespace kaa {
40 
41 #if KAA_LOG_LEVEL > KAA_LOG_LEVEL_NONE
42 void kaa_log_message(const ILogger & logger, LogLevel level, const char *message, const char *file, size_t lineno);
43 void kaa_log_message(const ILogger & logger, LogLevel level, const std::string &message, const char *file, size_t lineno);
44 void kaa_log_message(const ILogger & logger, LogLevel level, const boost::format& message, const char *file, size_t lineno);
45 
46 #endif
47 
48 #if KAA_LOG_LEVEL >= KAA_LOG_LEVEL_FINE_TRACE
49  #define KAA_LOG_FTRACE(message) kaa_log_message(context_.getLogger(), LogLevel::KAA_TRACE, (message), __LOGFILE, __LINE__);
50 #else
51  #define KAA_LOG_FTRACE(message)
52 #endif
53 #if KAA_LOG_LEVEL >= KAA_LOG_LEVEL_TRACE
54  #define KAA_LOG_TRACE(message) kaa_log_message(context_.getLogger(), LogLevel::KAA_TRACE, (message), __LOGFILE, __LINE__);
55 #else
56  #define KAA_LOG_TRACE(message)
57 #endif
58 #if KAA_LOG_LEVEL >= KAA_LOG_LEVEL_DEBUG
59  #define KAA_LOG_DEBUG(message) kaa_log_message(context_.getLogger(), LogLevel::KAA_DEBUG, (message), __LOGFILE, __LINE__);
60 #else
61  #define KAA_LOG_DEBUG(message)
62 #endif
63 #if KAA_LOG_LEVEL >= KAA_LOG_LEVEL_INFO
64  #define KAA_LOG_INFO(message) kaa_log_message(context_.getLogger(), LogLevel::KAA_INFO, (message), __LOGFILE, __LINE__);
65 #else
66  #define KAA_LOG_INFO(message)
67 #endif
68 #if KAA_LOG_LEVEL >= KAA_LOG_LEVEL_WARNING
69  #define KAA_LOG_WARN(message) kaa_log_message(context_.getLogger(), LogLevel::KAA_WARNING, (message), __LOGFILE, __LINE__);
70 #else
71  #define KAA_LOG_WARN(message)
72 #endif
73 #if KAA_LOG_LEVEL >= KAA_LOG_LEVEL_ERROR
74  #define KAA_LOG_ERROR(message) kaa_log_message(context_.getLogger(), LogLevel::KAA_ERROR, (message), __LOGFILE, __LINE__);
75 #else
76  #define KAA_LOG_ERROR(message)
77 #endif
78 #if KAA_LOG_LEVEL >= KAA_LOG_LEVEL_FATAL
79  #define KAA_LOG_FATAL(message) kaa_log_message(context_.getLogger(), LogLevel::KAA_FATAL, (message), __LOGFILE, __LINE__);
80 #else
81  #define KAA_LOG_FATAL(message)
82 #endif
83 
84 #if defined(KAA_THREADSAFE) && defined(KAA_MUTEX_LOGGING_ENABLED) && KAA_LOG_LEVEL > 4
85  #define KAA_MUTEX_LOCKING(mutex_name) KAA_LOG_DEBUG("Locking " mutex_name " mutex");
86  #define KAA_MUTEX_LOCKED(mutex_name) KAA_LOG_DEBUG("Locked " mutex_name " mutex");
87  #define KAA_MUTEX_UNLOCKING(mutex_name) KAA_LOG_DEBUG("Unlocking " mutex_name " mutex");
88  #define KAA_MUTEX_UNLOCKED(mutex_name) KAA_LOG_DEBUG("Unlocked " mutex_name " mutex");
89 #else
90  #define KAA_MUTEX_LOCKING(mutex_name)
91  #define KAA_MUTEX_LOCKED(mutex_name)
92  #define KAA_MUTEX_UNLOCKING(mutex_name)
93  #define KAA_MUTEX_UNLOCKED(mutex_name)
94 #endif
95 
96 } // namespace kaa
97 
98 #endif /* LOG_HPP_ */
LogLevel
Definition: ILogger.hpp:24