source: molecuilder/src/logger.cpp@ 447896

Last change on this file since 447896 was 548cbf, checked in by Frederik Heber <heber@…>, 16 years ago

BUGFIX: Output is again indented, errorLogger prefixes according to verbosity.

  • BUGFIX: as "(logger << verbose) = cout" was evaluated, this did not translate to (cout << verbose). Hence, the tabbing was lost. This is fixed.
  • errorLogger::operator << : 0 - CRITICL, 1 - ERROR, 2, ... - WARNING
  • in class Verbose the logger::operator functions are declared friend to allow access to Verbose::verbosity
  • Property mode set to 100644
File size: 1.7 KB
Line 
1/*
2 * logger.cpp
3 *
4 * Created on: Oct 19, 2009
5 * Author: metzler
6 */
7
8#include <fstream>
9#include "logger.hpp"
10#include "verbose.hpp"
11
12ofstream nullStream("/dev/null");
13
14logger* logger::instance = NULL;
15int logger::verbosity = 2;
16ostream* logger::nix = &nullStream;
17
18/**
19 * Constructor. Do not use this function. Use getInstance() instead.
20 *
21 * \return logger instance
22 */
23logger::logger()
24{
25 instance = NULL;
26 verbosity = 2;
27};
28
29/**
30 * Destructor. Better use purgeInstance().
31 */
32logger::~logger() {
33 verbosity = 2;
34}
35
36/**
37 * Returns the singleton logger instance.
38 *
39 * \return logger instance
40 */
41logger* logger::getInstance() {
42 if (instance == NULL) {
43 instance = new logger();
44 }
45
46 return instance;
47}
48
49
50/**
51 * Purges the current logger instance.
52 */
53void logger::purgeInstance() {
54 if (instance != NULL) {
55 delete instance;
56 }
57
58 instance = NULL;
59}
60
61/**
62 * Sets the verbosity.
63 *
64 * \param verbosityLevel verbosity
65 */
66void logger::setVerbosity(int verbosityLevel) {
67 verbosity = verbosityLevel;
68}
69
70/**
71 * Operator for the Binary(arg) call.
72 * Constructs temporary a Verbose class object, wherein the Binary is stored.
73 * Then << is called, which calls Binary's print which adds the tabs and logs
74 * the stream.
75 * \param &ost stream to extend
76 * \param &m pointer to created Binary object
77 * \return &ost
78 */
79ostream& operator<<(class logger& l, const Verbose& v)
80{
81 int verbosityLevel = l.verbosity;
82 l.nix->clear();
83 if (v.DoOutput(verbosityLevel)) {
84 v.print(cout);
85 return cout;
86 } else
87 return *l.nix;
88};
89ostream& operator<<(class logger* l, const Verbose& v)
90{
91 int verbosityLevel = l->verbosity;
92 l->nix->clear();
93 if (v.DoOutput(verbosityLevel)) {
94 v.print(cout);
95 return cout;
96 } else
97 return *l->nix;
98};
99
Note: See TracBrowser for help on using the repository browser.