comparison Core/Logging.h @ 1489:1389834e130f

basic logger
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 04 Aug 2015 12:22:08 +0200
parents c8763b603b0e
children e460341872dc
comparison
equal deleted inserted replaced
1488:c8763b603b0e 1489:1389834e130f
33 #pragma once 33 #pragma once
34 34
35 #if ORTHANC_ENABLE_LOGGING == 1 35 #if ORTHANC_ENABLE_LOGGING == 1
36 36
37 #if ORTHANC_ENABLE_GOOGLE_LOG == 1 37 #if ORTHANC_ENABLE_GOOGLE_LOG == 1
38 #include <stdlib.h> // This fixes a problem in glog for recent releases of MinGW 38 # include <stdlib.h> // This fixes a problem in glog for recent releases of MinGW
39 #include <glog/logging.h> 39 # include <glog/logging.h>
40 #else
41 # include <iostream>
42 # include <boost/thread/mutex.hpp>
43 # define LOG(level) ::Orthanc::Logging::InternalLogger(#level, __FILE__, __LINE__)
44 # define VLOG(level) ::Orthanc::Logging::InternalLogger("TRACE", __FILE__, __LINE__)
40 #endif 45 #endif
46
41 47
42 namespace Orthanc 48 namespace Orthanc
43 { 49 {
44 namespace Logging 50 namespace Logging
45 { 51 {
48 void Finalize(); 54 void Finalize();
49 55
50 void EnableInfoLevel(bool enabled); 56 void EnableInfoLevel(bool enabled);
51 57
52 void EnableTraceLevel(bool enabled); 58 void EnableTraceLevel(bool enabled);
59
60 void SetTargetFolder(const std::string& path);
61
62
63 #if ORTHANC_ENABLE_GOOGLE_LOG != 1
64 class InternalLogger
65 {
66 private:
67 boost::mutex::scoped_lock lock_;
68 std::ostream* stream_;
69
70 public:
71 InternalLogger(const char* level,
72 const char* file,
73 int line);
74
75 ~InternalLogger()
76 {
77 #if defined(_WIN32)
78 *stream_ << "\r\n";
79 #else
80 *stream_ << "\n";
81 #endif
82 }
83
84 std::ostream& operator<< (const std::string& message)
85 {
86 return (*stream_) << message;
87 }
88 };
89 #endif
53 } 90 }
54 } 91 }
55 92
56 #endif 93 #endif