RDKit: RDLog.h Source File

| RDKit Open-source cheminformatics and machine learning.

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

RDLog.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2005-2008 Greg Landrum and Rational Discovery LLC
3 //
4 // @@ All Rights Reserved @@
5 // This file is part of the RDKit.
6 // The contents are covered by the terms of the BSD license
7 // which is included in the file license.txt, found at the root
8 // of the RDKit source tree.
9 //
10
11 #ifndef _RDLOG_H_29JUNE2005_
12 #define _RDLOG_H_29JUNE2005_
13
14 #if 1
15 #include "BoostStartInclude.h"
16 #include <boost/iostreams/tee.hpp>
17 #include <boost/iostreams/stream.hpp>
18 #include "BoostEndInclude.h"
19 #include <iostream>
20 namespace boost {
21 namespace logging {
22
23 typedef boost::iostreams::tee_device<std::ostream, std::ostream> RDTee;
24 typedef boost::iostreams::stream<RDTee> RDTeeStream;
25
26 class rdLogger {
27 public:
28 std::ostream *dp_dest;
29 bool df_owner, df_enabled;
30
31 RDTee *tee;
32 RDTeeStream *teestream;
33
34 rdLogger(std::ostream *dest, bool owner = false)
35 : dp_dest(dest),
36 df_owner(owner),
37 df_enabled(true),
38 tee(NULL),
39 teestream(NULL){};
40
41 //! Sets a stream to tee the output to.
42 void SetTee(std::ostream &stream) {
43 if (dp_dest) {
44 delete teestream;
45 delete tee;
46 tee = new RDTee(*dp_dest, stream);
47 teestream = new RDTeeStream(*tee);
48 }
49 }
50 //! Remove our tee if it's set.
51 void ClearTee() {
52 if (dp_dest) {
53 delete teestream;
54 delete tee;
55 tee = NULL;
56 teestream = NULL;
57 }
58 }
59 ~rdLogger() {
60 if (dp_dest) {
61 dp_dest->flush();
62 if (df_owner) {
63 delete dp_dest;
64 }
65 dp_dest = NULL;
66 }
67 delete teestream;
68 teestream = NULL;
69 delete tee;
70 tee = NULL;
71 }
72
73 private:
74 // disable copy ctor and assignment
75 rdLogger(const rdLogger &);
76 rdLogger &operator=(const rdLogger &);
77 };
78 void enable_logs(const char *arg);
79 void enable_logs(const std::string &arg);
80 void disable_logs(const char *arg);
81 void disable_logs(const std::string &arg);
82 }
83 }
84 namespace RDLog {
85 std::ostream &toStream(std::ostream &);
86 }
87 #define BOOST_LOG(__arg__) \
88 if ((!__arg__) || (!__arg__->dp_dest) || !(__arg__->df_enabled)) \
89 ; \
90 else \
91 RDLog::toStream((__arg__->teestream) ? *(__arg__->teestream) \
92 : *(__arg__->dp_dest))
93
94 extern boost::logging::rdLogger *rdAppLog;
95 extern boost::logging::rdLogger *rdDebugLog;
96 extern boost::logging::rdLogger *rdInfoLog;
97 extern boost::logging::rdLogger *rdErrorLog;
98 extern boost::logging::rdLogger *rdWarningLog;
99 extern boost::logging::rdLogger *rdStatusLog;
100
101 #else
102 #define BOOST_LOG_NO_LIB
103 #include <boost/log/log.hpp>
104 BOOST_DECLARE_LOG(rdAppLog)
105 BOOST_DECLARE_LOG(rdDebugLog)
106 BOOST_DECLARE_LOG(rdInfoLog)
107 BOOST_DECLARE_LOG(rdErrorLog)
108 BOOST_DECLARE_LOG(rdWarningLog)
109 BOOST_DECLARE_LOG(rdStatusLog)
110 #endif
111 namespace RDLog {
112 void InitLogs();
113 }
114 #endif
boost::logging::rdLogger::SetTee
void SetTee(std::ostream &stream)
Sets a stream to tee the output to.
Definition: RDLog.h:42
BoostStartInclude.h
boost
Definition: RDLog.h:20
boost::logging::rdLogger::~rdLogger
~rdLogger()
Definition: RDLog.h:59
RDLog
Definition: RDLog.h:84
boost::logging::rdLogger::rdLogger
rdLogger(std::ostream *dest, bool owner=false)
Definition: RDLog.h:34
boost::logging::rdLogger::dp_dest
std::ostream * dp_dest
Definition: RDLog.h:28
RDLog::InitLogs
void InitLogs()
rdWarningLog
boost::logging::rdLogger * rdWarningLog
rdAppLog
boost::logging::rdLogger * rdAppLog
boost::logging::RDTeeStream
boost::iostreams::stream< RDTee > RDTeeStream
Definition: RDLog.h:24
BoostEndInclude.h
boost::logging::RDTee
boost::iostreams::tee_device< std::ostream, std::ostream > RDTee
Definition: RDLog.h:23
boost::logging::rdLogger::tee
RDTee * tee
Definition: RDLog.h:31
boost::logging::rdLogger::teestream
RDTeeStream * teestream
Definition: RDLog.h:32
boost::logging::rdLogger::df_owner
bool df_owner
Definition: RDLog.h:29
rdStatusLog
boost::logging::rdLogger * rdStatusLog
rdDebugLog
boost::logging::rdLogger * rdDebugLog
boost::logging::rdLogger::df_enabled
bool df_enabled
Definition: RDLog.h:29
RDLog::toStream
std::ostream & toStream(std::ostream &)
rdInfoLog
boost::logging::rdLogger * rdInfoLog
boost::logging::rdLogger::ClearTee
void ClearTee()
Remove our tee if it&#39;s set.
Definition: RDLog.h:51
boost::logging::enable_logs
void enable_logs(const char *arg)
boost::logging::rdLogger
Definition: RDLog.h:26
rdErrorLog
boost::logging::rdLogger * rdErrorLog
boost::logging::disable_logs
void disable_logs(const char *arg)