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 <boost/iostreams/tee.hpp>
16 #include <boost/iostreams/stream.hpp>
17 #include <iostream>
18 namespace boost {
19 namespace logging {
20 
21 typedef boost::iostreams::tee_device<std::ostream, std::ostream> RDTee;
22 typedef boost::iostreams::stream<RDTee> RDTeeStream;
23 
24 class rdLogger {
25  public:
26  std::ostream *dp_dest;
28 
29  RDTee *tee;
30  RDTeeStream *teestream;
31 
32  rdLogger(std::ostream *dest, bool owner = false)
33  : dp_dest(dest), df_owner(owner), df_enabled(true),
34  tee(0), teestream(0){};
35 
36  void AddTee(std::ostream &stream) {
37  if (dp_dest) {
38  tee = new RDTee(*dp_dest, stream);
39  teestream = new RDTeeStream(*tee);
40  }
41  }
43  if (dp_dest) {
44  dp_dest->flush();
45  if (df_owner) {
46  delete dp_dest;
47  }
48  }
49  delete teestream;
50  delete tee;
51  }
52 };
53 void enable_logs(const char *arg);
54 void enable_logs(const std::string &arg);
55 void disable_logs(const char *arg);
56 void disable_logs(const std::string &arg);
57 }
58 }
59 namespace RDLog {
60 std::ostream &toStream(std::ostream &);
61 }
62 #define BOOST_LOG(__arg__) \
63  if ((!__arg__) || (!__arg__->dp_dest) || !(__arg__->df_enabled)) \
64  ; \
65  else \
66  RDLog::toStream((__arg__->teestream) ? *(__arg__->teestream) : *(__arg__->dp_dest))
67 
74 
75 #else
76 #define BOOST_LOG_NO_LIB
77 #include <boost/log/log.hpp>
78 BOOST_DECLARE_LOG(rdAppLog)
79 BOOST_DECLARE_LOG(rdDebugLog)
80 BOOST_DECLARE_LOG(rdInfoLog)
81 BOOST_DECLARE_LOG(rdErrorLog)
82 BOOST_DECLARE_LOG(rdWarningLog)
83 BOOST_DECLARE_LOG(rdStatusLog)
84 #endif
85 namespace RDLog {
86 void InitLogs();
87 }
88 #endif
Definition: RDLog.h:18
Definition: RDLog.h:59
rdLogger(std::ostream *dest, bool owner=false)
Definition: RDLog.h:32
std::ostream * dp_dest
Definition: RDLog.h:26
void InitLogs()
boost::logging::rdLogger * rdWarningLog
boost::logging::rdLogger * rdAppLog
void AddTee(std::ostream &stream)
Definition: RDLog.h:36
boost::iostreams::stream< RDTee > RDTeeStream
Definition: RDLog.h:22
boost::iostreams::tee_device< std::ostream, std::ostream > RDTee
Definition: RDLog.h:21
RDTeeStream * teestream
Definition: RDLog.h:30
boost::logging::rdLogger * rdStatusLog
boost::logging::rdLogger * rdDebugLog
std::ostream & toStream(std::ostream &)
boost::logging::rdLogger * rdInfoLog
void enable_logs(const char *arg)
boost::logging::rdLogger * rdErrorLog
void disable_logs(const char *arg)