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 #include <RDGeneral/export.h>
12 #ifndef _RDLOG_H_29JUNE2005_
13 #define _RDLOG_H_29JUNE2005_
14 
15 #if 1
16 #include "BoostStartInclude.h"
17 #include <boost/iostreams/tee.hpp>
18 #include <boost/iostreams/stream.hpp>
19 #include "BoostEndInclude.h"
20 #include <iostream>
21 namespace boost {
22 namespace logging {
23 
24 typedef boost::iostreams::tee_device<std::ostream, std::ostream> RDTee;
25 typedef boost::iostreams::stream<RDTee> RDTeeStream;
26 
28  public:
29  std::ostream *dp_dest;
30  bool df_owner, df_enabled;
31 
32  RDTee *tee;
33  RDTeeStream *teestream;
34 
35  rdLogger(std::ostream *dest, bool owner = false)
36  : dp_dest(dest),
37  df_owner(owner),
38  df_enabled(true),
39  tee(NULL),
40  teestream(NULL){};
41 
42  //! Sets a stream to tee the output to.
43  void SetTee(std::ostream &stream) {
44  if (dp_dest) {
45  delete teestream;
46  delete tee;
47  tee = new RDTee(*dp_dest, stream);
48  teestream = new RDTeeStream(*tee);
49  }
50  }
51  //! Remove our tee if it's set.
52  void ClearTee() {
53  if (dp_dest) {
54  delete teestream;
55  delete tee;
56  tee = NULL;
57  teestream = NULL;
58  }
59  }
61  if (dp_dest) {
62  dp_dest->flush();
63  if (df_owner) {
64  delete dp_dest;
65  }
66  dp_dest = NULL;
67  }
68  delete teestream;
69  teestream = NULL;
70  delete tee;
71  tee = NULL;
72  }
73 
74  private:
75  // disable copy ctor and assignment
76  rdLogger(const rdLogger &);
77  rdLogger &operator=(const rdLogger &);
78 };
79 RDKIT_RDGENERAL_EXPORT void enable_logs(const char *arg);
80 RDKIT_RDGENERAL_EXPORT void enable_logs(const std::string &arg);
81 RDKIT_RDGENERAL_EXPORT void disable_logs(const char *arg);
82 RDKIT_RDGENERAL_EXPORT void disable_logs(const std::string &arg);
83 }
84 }
85 namespace RDLog {
86 RDKIT_RDGENERAL_EXPORT std::ostream &toStream(std::ostream &);
87 }
88 #define BOOST_LOG(__arg__) \
89  if ((__arg__) && (__arg__->dp_dest) && (__arg__->df_enabled)) \
90  RDLog::toStream((__arg__->teestream) ? *(__arg__->teestream) \
91  : *(__arg__->dp_dest))
92 
99 
100 #else
101 #define BOOST_LOG_NO_LIB
102 #include <boost/log/log.hpp>
103 BOOST_DECLARE_LOG(rdAppLog)
104 BOOST_DECLARE_LOG(rdDebugLog)
105 BOOST_DECLARE_LOG(rdInfoLog)
106 BOOST_DECLARE_LOG(rdErrorLog)
107 BOOST_DECLARE_LOG(rdWarningLog)
108 BOOST_DECLARE_LOG(rdStatusLog)
109 #endif
110 namespace RDLog {
112 }
113 #endif
RDKIT_RDGENERAL_EXPORT boost::logging::rdLogger * rdErrorLog
void SetTee(std::ostream &stream)
Sets a stream to tee the output to.
Definition: RDLog.h:43
Definition: RDLog.h:21
#define RDKIT_RDGENERAL_EXPORT
Definition: export.h:489
RDKIT_RDGENERAL_EXPORT boost::logging::rdLogger * rdDebugLog
Definition: RDLog.h:85
RDKIT_RDGENERAL_EXPORT boost::logging::rdLogger * rdAppLog
rdLogger(std::ostream *dest, bool owner=false)
Definition: RDLog.h:35
std::ostream * dp_dest
Definition: RDLog.h:29
boost::iostreams::stream< RDTee > RDTeeStream
Definition: RDLog.h:25
boost::iostreams::tee_device< std::ostream, std::ostream > RDTee
Definition: RDLog.h:24
RDTeeStream * teestream
Definition: RDLog.h:33
RDKIT_RDGENERAL_EXPORT void disable_logs(const char *arg)
RDKIT_RDGENERAL_EXPORT std::ostream & toStream(std::ostream &)
RDKIT_RDGENERAL_EXPORT void InitLogs()
RDKIT_RDGENERAL_EXPORT boost::logging::rdLogger * rdStatusLog
RDKIT_RDGENERAL_EXPORT void enable_logs(const char *arg)
RDKIT_RDGENERAL_EXPORT boost::logging::rdLogger * rdWarningLog
void ClearTee()
Remove our tee if it&#39;s set.
Definition: RDLog.h:52
RDKIT_RDGENERAL_EXPORT boost::logging::rdLogger * rdInfoLog