GenApi 3.5.1
CLog.h
1//-----------------------------------------------------------------------------
2// (c) 2017 by STEMMER IMAGING GmbH
3// Author: Quang Nguyen
4//
5// License: This file is published under the license of the EMVA GenICam Standard Group.
6// A text file describing the legal terms is included in your installation as 'GenICam_license.pdf'.
7// If for some reason you are missing this file please contact the EMVA or visit the website
8// (http://www.genicam.org) for a full copy.
9//
10// THIS SOFTWARE IS PROVIDED BY THE EMVA GENICAM STANDARD GROUP "AS IS"
11// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
12// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
13// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE EMVA GENICAM STANDARD GROUP
14// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
15// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
16// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
17// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
18// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
19// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
20// POSSIBILITY OF SUCH DAMAGE.
21//
22//-----------------------------------------------------------------------------
23
24
25
26
27#ifndef LOG_CLOG_H_
28#define LOG_CLOG_H_
29
30#ifdef _MSC_VER
31# pragma warning (push, 3)
32# pragma warning(disable:4706) // assignment within conditional expression
33#endif
34//#pragma warning (push, 3)
35//#pragma warning(disable:4706) // assignment within conditional expression
36
37#include <stdio.h>
38#include <map>
39#include <Log/LogDll.h>
40
41#include <Base/GCBase.h>
42#include <Log/ILogger.h>
43#include <Log/ILoggerFactory.h>
44
45
46namespace GENICAM_NAMESPACE
47{
52 class LOG_DECL CLog
53 {
54 public:
58 static bool Exist(const gcstring &LoggerName);
59 static bool Exist(const char* LoggerName);
60
61
64 static ILogger& GetLogger(const gcstring &LoggerName);
65 static ILogger& GetLogger(const char* LoggerName);
66
67 static void PushIndent();
68 static void PopIndent();
69
70 // No logger is being used
71 static void OmitLogger();
72
73 // Will take ownership of the ILoggerFactory. ShutDown will delete that object
74 static void SetLoggerFactory(ILoggerFactory&);
75 static void SetLoggerFactory(ILoggerFactory* pLoggerFactory);
76 static ILoggerFactory* GetLoggerFactory();
77
79 static void ShutDown(void);
80
81 private:
82
84#if defined (_WIN32)
85 typedef HMODULE lib_handle_t;
86#else
87 typedef void * lib_handle_t;
88#endif
89
90 // Default initializer
91 static void DefaultInitializer();
92
94 static lib_handle_t OpenLibrary(const gcstring Name);
95
97 static void *FindSymbol(lib_handle_t Handle, const gcstring Name);
98
100 static void MakeSureLoggerHasBeenFound();
101
102 static bool ExistInMap(gcstring loggerName);
103 // Delete all available ILoggers
104 static void DeleteLoggerMap();
105
106 // Contains the logger factory unless it has not been loaded
107 static ILoggerFactory* m_LogFactory;
108
109
110
112 static lib_handle_t g_pLibHandle;
113
114 // True if logger has been found
115 static bool m_LoggerHasBeenFound;
116 static bool m_OmitLogger;
117
118 };
119
120}
121
122#if defined(__GNUC__)
123# pragma GCC diagnostic push
124# pragma GCC diagnostic ignored "-Wvariadic-macros"
125# if defined(__clang__)
126# pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
127# endif
128#endif
129
130// Logging macros
131#define GCLOGINFO( cat, ... ) if(cat && GENICAM_NAMESPACE::CLog::Exist("")) { (cat)->Log(GENICAM_NAMESPACE::ILogger::INFO, ##__VA_ARGS__ ); }
132#define GCLOGINFOPUSH( cat, ... ) if(cat && GENICAM_NAMESPACE::CLog::Exist("")) { (cat)->Log(GENICAM_NAMESPACE::ILogger::INFO, ##__VA_ARGS__ ); GENICAM_NAMESPACE::CLog::PushIndent();}
133#define GCLOGWARN( cat, ... ) if(cat && GENICAM_NAMESPACE::CLog::Exist("")) { (cat)->Log(GENICAM_NAMESPACE::ILogger::WARN, ##__VA_ARGS__ ); }
134#define GCLOGERROR( cat, ... ) if(cat && GENICAM_NAMESPACE::CLog::Exist("")) { (cat)->Log(GENICAM_NAMESPACE::ILogger::ERR, ##__VA_ARGS__ ); }
135#define GCLOGDEBUG( cat, ... ) if(cat && GENICAM_NAMESPACE::CLog::Exist("")) { (cat)->Log(GENICAM_NAMESPACE::ILogger::DEBUG, ##__VA_ARGS__ ); }
136#define GCLOGINFOPOP( cat, ... ) if(cat && GENICAM_NAMESPACE::CLog::Exist("")) { (cat)->Log(GENICAM_NAMESPACE::ILogger::INFO, ##__VA_ARGS__ ); GENICAM_NAMESPACE::CLog::PopIndent();}
137
138
139#if defined(__GNUC__)
140# pragma GCC diagnostic pop
141#endif
142
143#endif // LOG_CLOG_H_
Common GenICam base include file.
declspec's to be used for Log Windows dll
This logging class initializes the logger. By default that would be Log4cpp.
Definition CLog.h:53
static ILogger & GetLogger(const gcstring &LoggerName)
static bool Exist(const gcstring &LoggerName)
static void ShutDown(void)
de-initializes the logging framework
A string class which is a clone of std::string.
Definition GCString.h:51