RDKit
Open-source cheminformatics and machine learning.
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;
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  }
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 
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
void SetTee(std::ostream &stream)
Sets a stream to tee the output to.
Definition: RDLog.h:42
Definition: RDLog.h:20
Definition: RDLog.h:84
rdLogger(std::ostream *dest, bool owner=false)
Definition: RDLog.h:34
std::ostream * dp_dest
Definition: RDLog.h:28
void InitLogs()
boost::logging::rdLogger * rdWarningLog
boost::logging::rdLogger * rdAppLog
boost::iostreams::stream< RDTee > RDTeeStream
Definition: RDLog.h:24
boost::iostreams::tee_device< std::ostream, std::ostream > RDTee
Definition: RDLog.h:23
RDTeeStream * teestream
Definition: RDLog.h:32
boost::logging::rdLogger * rdStatusLog
boost::logging::rdLogger * rdDebugLog
std::ostream & toStream(std::ostream &)
boost::logging::rdLogger * rdInfoLog
void ClearTee()
Remove our tee if it&#39;s set.
Definition: RDLog.h:51
void enable_logs(const char *arg)
boost::logging::rdLogger * rdErrorLog
void disable_logs(const char *arg)