Files
rdkit/Code/RDGeneral/RDLog.cpp
Ric a6b26253ff Fix (most of) mem problems (#2123)
* do not use new on loggers

* del pointers in testDistGeom

* Update Dict hasNonPOD status on bulk update

* delete new Dicts in memtest1.cpp

* fixes in MolSuppliers and testFMCS

* PeriodicTable singleton as unique_ptr

* fix EEM_arrays leak

* fix leaks in testPBF

* fix ParamCollection leak in test UFF

* fix leaks in MMFF

* clear prop dict before read in in pickler

* fix leaks in testFreeSASA

* fix leaks in test3D

* modernize Dict.h & SmilesParse.cpp

* fix leaks in testQuery

* fix leaks in testCrystalFF

* fix leaks in cxsmilesTest

* fix leaks in Catalog & mol cat test

* fix leaks in ShapeUtils & tests

* fix leaks in testSubgraphs1

* fix leaks testFingerprintGenerators

* fix leaks in Catalog/FilterCatalog

* fix leaks in graphmolqueryTest

* these changes reduce bison parse leaks

* fixed leaks in testChirality.cpp

* fix leaks + 2 tests in testMolWriter

* fix 4m leaks in substructLibraryTest

* small improvements to molTautomerTest; still leaks

* fix leaks in testRGroupDecomp

* fix leaks in test; parser still leaks

* fix leaks in itertest

* fix 4m leaks in testDepictor

* fixes in smatest; still leaking due to parser

* fixes in testSLNParse; still leaking due to parser

* flex/bison: always add atoms with ownership; smarts error cleanup

* fix leaks in testReaction

* fix leaks in testSubstructMatch

* fix leaks in resMolSupplierTest

* fix leaks in testChemTransforms + bug in ChemTransforms

* fix leaks in testPickler

* fix leaks in testMolTransform

* fix leaks in testFragCatalog

* fix leak in testSLNParse. Still leaks due to Smiles

* fixed most leaks in testMolSupplier

* pre bison fix

* fix some atom & bond parse problems; others still fail

* bison smiles & smarts, atoms & bonds more or less fixed

* fix leaks in molopstest.cpp

* fix leaks in testFingerprints, MACCS.cpp & AtomPairs.cpp

* fix leaks in moldraw2Dtest1

* fix leaks in testDescriptors

* fix leaks in testInchi

* fix leaks in testUFFForceFieldHelpers

* fix leaks in hanoiTest & new_canon.h

* fix leaks in testMMFFForceField

* fix leaks in graphmolTest1

* fix leaks in testMMFFForceFieldHelpers

* fix leaks in testDistGeomHelpers

* fix leaks in testMolAlign

* initialize occupancy & temp facto with default values

* fix leak in TautomerTransform

* updated suppressions

* fix testStructChecker

* fix logging & py tests

* fix TautomerTransform class/struct issue

* remove misplaced delete in testSLNParse

* deinit in testAvalonLib1

* fix Avalon-triggered(?) bug in StructChecker/Pattern.cpp

* fix random testMolWriter/Supplier fails

- diversify output file names to avoid clashing.
- unify Writers close/destruct behavior.
- flushing/closing in tests.

* use reset in FFs Params.cpp

* comments on testMMFFForceField

* unrequired 'if's added to mol suppliers

* correct cast in FilterCatalog.h

* use unique_ptr in MACCS Patterns

* remove unrequred if in new_canon

* update & move suppressions
2018-10-29 14:33:26 +00:00

144 lines
4.9 KiB
C++

// $Id$
//
// Copyright (C) 2005-2010 Greg Landrum and Rational Discovery LLC
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
// The contents are covered by the terms of the BSD license
// which is included in the file license.txt, found at the root
// of the RDKit source tree.
//
#include "RDLog.h"
#if 1
#include <iomanip>
#include <string>
#include <time.h>
std::shared_ptr<boost::logging::rdLogger> rdAppLog = nullptr;
std::shared_ptr<boost::logging::rdLogger> rdDebugLog = nullptr;
std::shared_ptr<boost::logging::rdLogger> rdInfoLog = nullptr;
std::shared_ptr<boost::logging::rdLogger> rdErrorLog = nullptr;
std::shared_ptr<boost::logging::rdLogger> rdWarningLog = nullptr;
std::shared_ptr<boost::logging::rdLogger> rdStatusLog = nullptr;
namespace boost {
namespace logging {
void enable_logs(const char *arg) { enable_logs(std::string(arg)); };
void enable_logs(const std::string &arg) {
// Yes... this is extremely crude
if (arg == "rdApp.debug" || arg == "rdApp.*") {
if (rdDebugLog) rdDebugLog->df_enabled = true;
}
if (arg == "rdApp.info" || arg == "rdApp.*") {
if (rdInfoLog) rdInfoLog->df_enabled = true;
}
if (arg == "rdApp.warning" || arg == "rdApp.*") {
if (rdWarningLog) rdWarningLog->df_enabled = true;
}
if (arg == "rdApp.error" || arg == "rdApp.*") {
if (rdErrorLog) rdErrorLog->df_enabled = true;
}
};
void disable_logs(const char *arg) { disable_logs(std::string(arg)); };
void disable_logs(const std::string &arg) {
// Yes... this is extremely crude
if (arg == "rdApp.debug" || arg == "rdApp.*") {
if (rdDebugLog) rdDebugLog->df_enabled = false;
}
if (arg == "rdApp.info" || arg == "rdApp.*") {
if (rdInfoLog) rdInfoLog->df_enabled = false;
}
if (arg == "rdApp.warning" || arg == "rdApp.*") {
if (rdWarningLog) rdWarningLog->df_enabled = false;
}
if (arg == "rdApp.error" || arg == "rdApp.*") {
if (rdErrorLog) rdErrorLog->df_enabled = false;
}
};
} // namespace logging
} // namespace boost
namespace RDLog {
void InitLogs() {
rdDebugLog = std::make_shared<boost::logging::rdLogger>(&std::cerr);
rdInfoLog = std::make_shared<boost::logging::rdLogger>(&std::cout);
rdWarningLog = std::make_shared<boost::logging::rdLogger>(&std::cerr);
rdErrorLog = std::make_shared<boost::logging::rdLogger>(&std::cerr);
}
std::ostream &toStream(std::ostream &logstrm) {
time_t t = time(nullptr);
tm details = *localtime(&t);
logstrm << "[" << std::setw(2) << std::setfill('0') << details.tm_hour << ":"
<< std::setw(2) << std::setfill('0') << details.tm_min << ":"
<< std::setw(2) << std::setfill('0') << int(details.tm_sec) << "] ";
return logstrm;
}
} // namespace RDLog
#else
#include <boost/log/functions.hpp>
#if defined(BOOST_HAS_THREADS2)
#include <boost/log/extra/functions_ts.hpp>
#endif
#include <iostream>
namespace logging = boost::logging;
BOOST_DEFINE_LOG(rdAppLog, "rdApp")
BOOST_DEFINE_LOG(rdDebugLog, "rdApp.debug")
BOOST_DEFINE_LOG(rdInfoLog, "rdApp.info")
BOOST_DEFINE_LOG(rdErrorLog, "rdApp.error")
BOOST_DEFINE_LOG(rdWarningLog, "rdApp.warning")
BOOST_DEFINE_LOG(rdStatusLog, "rdApp.status")
namespace RDLog {
void write_to_cout(const std::string &, const std::string &msg) {
std::cout << msg;
std::cout.flush();
}
void write_to_cerr(const std::string &, const std::string &msg) {
std::cerr << msg;
std::cerr.flush();
}
void InitLogs() {
static bool callOnce = true;
if (!callOnce) return;
callOnce = false;
// turn off caching:
logging::set_log_caching(false);
logging::manipulate_logs("rdApp.*").add_modifier(
logging::prepend_time("[$hh:$mm:$ss] "), logging::DEFAULT_INDEX - 10);
logging::manipulate_logs("rdApp.info")
.add_appender(write_to_cout, logging::DEFAULT_INDEX + 1);
#if defined(BOOST_HAS_THREADS2)
logging::manipulate_logs("rdApp.error")
.add_appender(logging::ts_appender(write_to_cerr, 100),
logging::DEFAULT_INDEX + 1);
logging::manipulate_logs("rdApp.warning")
.add_appender(logging::ts_appender(write_to_cerr, 100),
logging::DEFAULT_INDEX + 1);
logging::manipulate_logs("rdApp.status")
.add_appender(logging::ts_appender(write_to_cerr, 100),
logging::DEFAULT_INDEX + 1);
logging::manipulate_logs("rdApp.debug")
.add_appender(logging::ts_appender(write_to_cerr, 100),
logging::DEFAULT_INDEX + 1);
#else
logging::manipulate_logs("rdApp.error")
.add_appender(write_to_cerr, logging::DEFAULT_INDEX + 1);
logging::manipulate_logs("rdApp.warning")
.add_appender(write_to_cerr, logging::DEFAULT_INDEX + 1);
logging::manipulate_logs("rdApp.status")
.add_appender(write_to_cerr, logging::DEFAULT_INDEX + 1);
logging::manipulate_logs("rdApp.debug")
.add_appender(write_to_cerr, logging::DEFAULT_INDEX + 1);
#endif
// start with the debug log disabled:
logging::disable_logs("rdApp.debug");
};
} // namespace RDLog
#endif