/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2010 University of Bonn. All rights reserved. * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. */ /* * errorLogger.cpp * * Created on: Oct 19, 2009 * Author: metzler */ // include config.h #ifdef HAVE_CONFIG_H #include #endif //#include "CodePatterns/MemDebug.hpp" #include #include #include "CodePatterns/errorlogger.hpp" #include "CodePatterns/Verbose.hpp" #include "CodePatterns/Singleton_impl.hpp" int errorLogger::verbosity = 2; ostream* errorLogger::nix = NULL; ostream* errorLogger::defaultout = NULL; ostream* errorLogger::out = NULL; /** * Constructor. Do not use this function. Use getInstance() instead. * * \return errorLogger instance */ errorLogger::errorLogger() { nix = new ofstream("/dev/null"); defaultout = &cerr; out = defaultout; }; /** * Destructor. Better use purgeInstance(). */ errorLogger::~errorLogger() { delete nix; out = NULL; // we are not responsible if out got changed defaultout = NULL; // do not delete cerr } CONSTRUCT_SINGLETON(errorLogger) /** * Sets the verbosity. * * \param verbosityLevel verbosity */ void errorLogger::setVerbosity(int verbosityLevel) { verbosity = verbosityLevel; } /** * Gets the verbosity. * * \return verbosity level */ int errorLogger::getVerbosity() { return verbosity; } /** Sets a new output stream. * * \param _newout new output stream, if NULL we set to defaultout */ void errorLogger::setOutputStream(ostream *_newout) { if(_newout != NULL) out = _newout; else out = defaultout; } /** * Operator for the Binary(arg) call. * Constructs temporary a Verbose class object, wherein the Binary is stored. * Then << is called, which calls Binary's print which adds the tabs and logs * the stream. * \param &ost stream to extend * \param &m pointer to created Binary object * \return &ost */ ostream& operator<<(class errorLogger& l, const Verbose& v) { int verbosityLevel = l.verbosity; l.nix->clear(); if (v.DoErrorOutput(verbosityLevel)) { switch(v.Verbosity) { case 0: cerr << "CRITICAL: "; break; case 1: cerr << "ERROR: "; break; case 2: cerr << "WARNING: "; break; default: break; } v.print(*errorLogger::out); return *errorLogger::out; } else return *l.nix; }; ostream& operator<<(class errorLogger* l, const Verbose& v) { int verbosityLevel = l->verbosity; l->nix->clear(); if (v.DoErrorOutput(verbosityLevel)) { switch(v.Verbosity) { case 0: cerr << "CRITICAL: "; break; case 1: cerr << "ERROR: "; break; case 2: default: cerr << "WARNING: "; break; } v.print(*errorLogger::out); return *errorLogger::out; } else return *l->nix; };