1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2010 University of Bonn. All rights reserved.
|
---|
5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * logger.cpp
|
---|
10 | *
|
---|
11 | * Created on: Oct 19, 2009
|
---|
12 | * Author: metzler
|
---|
13 | */
|
---|
14 |
|
---|
15 | // include config.h
|
---|
16 | #ifdef HAVE_CONFIG_H
|
---|
17 | #include <config.h>
|
---|
18 | #endif
|
---|
19 |
|
---|
20 | //#include "CodePatterns/MemDebug.hpp"
|
---|
21 |
|
---|
22 | #include <fstream>
|
---|
23 | #include <iostream>
|
---|
24 | #include "CodePatterns/logger.hpp"
|
---|
25 | #include "CodePatterns/Verbose.hpp"
|
---|
26 | #include "CodePatterns/Singleton_impl.hpp"
|
---|
27 |
|
---|
28 |
|
---|
29 | int logger::verbosity = 2;
|
---|
30 | ostream* logger::nix = NULL;
|
---|
31 | ostream* logger::defaultout = NULL;
|
---|
32 | ostream* logger::out = NULL;
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Constructor. Do not use this function. Use getInstance() instead.
|
---|
36 | *
|
---|
37 | * \return logger instance
|
---|
38 | */
|
---|
39 | logger::logger()
|
---|
40 | {
|
---|
41 | nix = new ofstream("/dev/null");
|
---|
42 | defaultout = &cout;
|
---|
43 | out = defaultout;
|
---|
44 | };
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Destructor. Better use purgeInstance().
|
---|
48 | */
|
---|
49 | logger::~logger()
|
---|
50 | {
|
---|
51 | delete nix;
|
---|
52 | out = NULL; // we are not responsible if out got changed
|
---|
53 | defaultout = NULL; // do not delete cout
|
---|
54 | }
|
---|
55 |
|
---|
56 | CONSTRUCT_SINGLETON(logger)
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * Sets the verbosity.
|
---|
60 | *
|
---|
61 | * \param verbosityLevel verbosity
|
---|
62 | */
|
---|
63 | void logger::setVerbosity(int verbosityLevel) {
|
---|
64 | verbosity = verbosityLevel;
|
---|
65 | }
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Gets the verbosity.
|
---|
69 | *
|
---|
70 | * \return verbosity level
|
---|
71 | */
|
---|
72 | int logger::getVerbosity()
|
---|
73 | {
|
---|
74 | return verbosity;
|
---|
75 | }
|
---|
76 |
|
---|
77 | /** Sets a new output stream.
|
---|
78 | *
|
---|
79 | * \param _newout new output stream, if NULL we set to defaultout
|
---|
80 | */
|
---|
81 | void logger::setOutputStream(ostream *_newout)
|
---|
82 | {
|
---|
83 | if(_newout != NULL)
|
---|
84 | out = _newout;
|
---|
85 | else
|
---|
86 | out = defaultout;
|
---|
87 | }
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * Operator for the Binary(arg) call.
|
---|
91 | * Constructs temporary a Verbose class object, wherein the Binary is stored.
|
---|
92 | * Then << is called, which calls Binary's print which adds the tabs and logs
|
---|
93 | * the stream.
|
---|
94 | * \param &ost stream to extend
|
---|
95 | * \param &m pointer to created Binary object
|
---|
96 | * \return &ost
|
---|
97 | */
|
---|
98 | ostream& operator<<(class logger& l, const Verbose& v)
|
---|
99 | {
|
---|
100 | int verbosityLevel = l.verbosity;
|
---|
101 | l.nix->clear();
|
---|
102 | if (v.DoOutput(verbosityLevel)) {
|
---|
103 | v.print(*logger::out);
|
---|
104 | return *logger::out;
|
---|
105 | } else
|
---|
106 | return *l.nix;
|
---|
107 | };
|
---|
108 | ostream& operator<<(class logger* l, const Verbose& v)
|
---|
109 | {
|
---|
110 | int verbosityLevel = l->verbosity;
|
---|
111 | l->nix->clear();
|
---|
112 | if (v.DoOutput(verbosityLevel)) {
|
---|
113 | v.print(*logger::out);
|
---|
114 | return *logger::out;
|
---|
115 | } else
|
---|
116 | return *l->nix;
|
---|
117 | };
|
---|
118 |
|
---|