OpcUaCanOpen
CANopen OPC-UA server
LogIt.h
Go to the documentation of this file.
1 /* © Copyright CERN, 2015. All rights not expressly granted are reserved.
2  * LogIt.h
3  *
4  * Created on: Aug 18, 2015
5  * Author: Benjamin Farnham <benjamin.farnham@cern.ch>
6  *
7  * This file is part of Quasar.
8  *
9  * Quasar is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Lesser General Public Licence as published by
11  * the Free Software Foundation, either version 3 of the Licence.
12  *
13  * Quasar is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Lesser General Public Licence for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with Quasar. If not, see <http://www.gnu.org/licenses/>.
20  */
21 #ifndef LOGIT_H_
22 #define LOGIT_H_
23 
24 #include <stdint.h>
25 #include <iostream>
26 #include <list>
27 
28 #include "LogItStaticDefinitions.h"
29 #include "LogRecord.h"
30 #include "LogLevels.h"
31 #include "LogItInstance.h"
32 
33 // internal macro - will be called by LOG(LOG_LEVEL)
34 #define LOG_WITHOUT_COMPONENT(level) \
35  if( !Log::isLoggable(level) ) (void)0; \
36  else LogRecord(__FILE__, __LINE__, level).getStream()
37 
38 // internal macro - will be called by LOG(LOG_LEVEL, USER_COMPONENT)
39 #define LOG_WITH_COMPONENT(level, component) \
40  if( !Log::isLoggable(level, component) ) (void)0; \
41  else LogRecord(__FILE__, __LINE__, level, component).getStream()
42 
52 #define GET_LOG_MACRO(_1, _2, LOG_MACRO_NAME, ...) LOG_MACRO_NAME
53 #define LOG(...) GET_LOG_MACRO(__VA_ARGS__, LOG_WITH_COMPONENT, LOG_WITHOUT_COMPONENT)(__VA_ARGS__)
54 
55 namespace Log
56 {
69  SHARED_LIB_EXPORT_DEFN bool initializeLogging(const Log::LOG_LEVEL& nonComponentLogLevel = Log::INF);
70 
80 
90  SHARED_LIB_EXPORT_DEFN LogComponentHandle registerLoggingComponent(const std::string& componentName, const Log::LOG_LEVEL& nonComponentLogLevel = Log::INF);
91 
100  SHARED_LIB_EXPORT_DEFN bool isLoggable(const Log::LOG_LEVEL& level, const LogComponentHandle& componentHandle);
101  SHARED_LIB_EXPORT_DEFN bool isLoggable(const Log::LOG_LEVEL& level, const std::string& componentName);
102 
109 
116  SHARED_LIB_EXPORT_DEFN const std::map<Log::LogComponentHandle, std::string> getComponentLogsList();
117  SHARED_LIB_EXPORT_DEFN bool setComponentLogLevel(const LogComponentHandle& componentHandle, const LOG_LEVEL& level);
118  SHARED_LIB_EXPORT_DEFN bool getComponentLogLevel(const LogComponentHandle& componentHandle, LOG_LEVEL& level);
119 
128 
136 }
137 
138 #endif /* LOGIT_H_ */