/* * logger.cpp * * Created on: Oct 19, 2009 * Author: metzler */ #include #include "logger.hpp" #include "verbose.hpp" #include "Patterns/Singleton_impl.hpp" ofstream nullStream("/dev/null"); int logger::verbosity = 2; ostream* logger::nix = &nullStream; /** * Constructor. Do not use this function. Use getInstance() instead. * * \return logger instance */ logger::logger() { verbosity = 2; }; /** * Destructor. Better use purgeInstance(). */ logger::~logger() { verbosity = 2; } CONSTRUCT_SINGLETON(logger) /** * Sets the verbosity. * * \param verbosityLevel verbosity */ void logger::setVerbosity(int verbosityLevel) { verbosity = verbosityLevel; } /** * 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 logger& l, const Verbose& v) { int verbosityLevel = l.verbosity; l.nix->clear(); if (v.DoOutput(verbosityLevel)) { v.print(cout); return cout; } else return *l.nix; }; ostream& operator<<(class logger* l, const Verbose& v) { int verbosityLevel = l->verbosity; l->nix->clear(); if (v.DoOutput(verbosityLevel)) { v.print(cout); return cout; } else return *l->nix; };