comparison Resources/Orthanc/Core/Logging.h @ 40:7207a407bcd8

shared copyright with osimis
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 04 Jan 2017 16:37:42 +0100
parents ff1e935768e7
children
comparison
equal deleted inserted replaced
39:9ee7e2f5f1a3 40:7207a407bcd8
1 /** 1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store 2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium 4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017 Osimis, Belgium
5 * 6 *
6 * This program is free software: you can redistribute it and/or 7 * This program is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as 8 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, either version 3 of the 9 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version. 10 * License, or (at your option) any later version.
36 37
37 #if !defined(ORTHANC_ENABLE_LOGGING) 38 #if !defined(ORTHANC_ENABLE_LOGGING)
38 # error The macro ORTHANC_ENABLE_LOGGING must be defined 39 # error The macro ORTHANC_ENABLE_LOGGING must be defined
39 #endif 40 #endif
40 41
42 #if !defined(ORTHANC_ENABLE_LOGGING_PLUGIN)
43 # if ORTHANC_ENABLE_LOGGING == 1
44 # error The macro ORTHANC_ENABLE_LOGGING_PLUGIN must be defined
45 # else
46 # define ORTHANC_ENABLE_LOGGING_PLUGIN 0
47 # endif
48 #endif
49
50 #if ORTHANC_ENABLE_LOGGING_PLUGIN == 1
51 # include <orthanc/OrthancCPlugin.h>
52 #endif
53
41 namespace Orthanc 54 namespace Orthanc
42 { 55 {
43 namespace Logging 56 namespace Logging
44 { 57 {
58 #if ORTHANC_ENABLE_LOGGING_PLUGIN == 1
59 void Initialize(OrthancPluginContext* context);
60 #else
45 void Initialize(); 61 void Initialize();
62 #endif
46 63
47 void Finalize(); 64 void Finalize();
48 65
49 void Reset(); 66 void Reset();
50 67
84 #if ORTHANC_ENABLE_LOGGING != 1 101 #if ORTHANC_ENABLE_LOGGING != 1
85 102
86 # define LOG(level) ::Orthanc::Logging::NullStream() 103 # define LOG(level) ::Orthanc::Logging::NullStream()
87 # define VLOG(level) ::Orthanc::Logging::NullStream() 104 # define VLOG(level) ::Orthanc::Logging::NullStream()
88 105
89 #else /* ORTHANC_ENABLE_LOGGING == 1 */ 106
107 #elif ORTHANC_ENABLE_LOGGING_PLUGIN == 1
108
109 # include <boost/noncopyable.hpp>
110 # define LOG(level) ::Orthanc::Logging::InternalLogger(#level, __FILE__, __LINE__)
111 # define VLOG(level) ::Orthanc::Logging::InternalLogger("TRACE", __FILE__, __LINE__)
112
113 namespace Orthanc
114 {
115 namespace Logging
116 {
117 class InternalLogger : public boost::noncopyable
118 {
119 private:
120 std::string level_;
121 std::string message_;
122
123 public:
124 InternalLogger(const char* level,
125 const char* file,
126 int line);
127
128 ~InternalLogger();
129
130 InternalLogger& operator<< (const std::string& message);
131
132 InternalLogger& operator<< (const char* message);
133
134 InternalLogger& operator<< (int message);
135 };
136 }
137 }
138
139
140 #else /* ORTHANC_ENABLE_LOGGING_PLUGIN == 0 && ORTHANC_ENABLE_LOGGING == 1 */
90 141
91 # include <boost/thread/mutex.hpp> 142 # include <boost/thread/mutex.hpp>
92 # define LOG(level) ::Orthanc::Logging::InternalLogger(#level, __FILE__, __LINE__) 143 # define LOG(level) ::Orthanc::Logging::InternalLogger(#level, __FILE__, __LINE__)
93 # define VLOG(level) ::Orthanc::Logging::InternalLogger("TRACE", __FILE__, __LINE__) 144 # define VLOG(level) ::Orthanc::Logging::InternalLogger("TRACE", __FILE__, __LINE__)
94 145