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 | * errorLogger.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 "Helpers/MemDebug.hpp"
|
---|
21 |
|
---|
22 | #include <fstream>
|
---|
23 | #include <iostream>
|
---|
24 | #include "Helpers/errorlogger.hpp"
|
---|
25 | #include "Helpers/Verbose.hpp"
|
---|
26 | #include "Patterns/Singleton_impl.hpp"
|
---|
27 |
|
---|
28 | int errorLogger::verbosity = 2;
|
---|
29 | ostream* errorLogger::nix = NULL;
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Constructor. Do not use this function. Use getInstance() instead.
|
---|
33 | *
|
---|
34 | * \return errorLogger instance
|
---|
35 | */
|
---|
36 | errorLogger::errorLogger()
|
---|
37 | {
|
---|
38 | nix = new ofstream("/dev/null");
|
---|
39 | };
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Destructor. Better use purgeInstance().
|
---|
43 | */
|
---|
44 | errorLogger::~errorLogger()
|
---|
45 | {
|
---|
46 | delete nix;
|
---|
47 | }
|
---|
48 |
|
---|
49 | CONSTRUCT_SINGLETON(errorLogger)
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * Sets the verbosity.
|
---|
53 | *
|
---|
54 | * \param verbosityLevel verbosity
|
---|
55 | */
|
---|
56 | void errorLogger::setVerbosity(int verbosityLevel) {
|
---|
57 | verbosity = verbosityLevel;
|
---|
58 | }
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * Gets the verbosity.
|
---|
62 | *
|
---|
63 | * \return verbosity level
|
---|
64 | */
|
---|
65 | int errorLogger::getVerbosity()
|
---|
66 | {
|
---|
67 | return verbosity;
|
---|
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 | */
|
---|
79 | ostream& operator<<(class errorLogger& l, const Verbose& v)
|
---|
80 | {
|
---|
81 | int verbosityLevel = l.verbosity;
|
---|
82 | l.nix->clear();
|
---|
83 | if (v.DoErrorOutput(verbosityLevel)) {
|
---|
84 | switch(v.Verbosity) {
|
---|
85 | case 0:
|
---|
86 | cerr << "CRITICAL: ";
|
---|
87 | break;
|
---|
88 | case 1:
|
---|
89 | cerr << "ERROR: ";
|
---|
90 | break;
|
---|
91 | case 2:
|
---|
92 | cerr << "WARNING: ";
|
---|
93 | break;
|
---|
94 | default:
|
---|
95 | break;
|
---|
96 | }
|
---|
97 | v.print(cerr);
|
---|
98 | return cerr;
|
---|
99 | } else
|
---|
100 | return *l.nix;
|
---|
101 | };
|
---|
102 | ostream& operator<<(class errorLogger* l, const Verbose& v)
|
---|
103 | {
|
---|
104 | int verbosityLevel = l->verbosity;
|
---|
105 | l->nix->clear();
|
---|
106 | if (v.DoErrorOutput(verbosityLevel)) {
|
---|
107 | switch(v.Verbosity) {
|
---|
108 | case 0:
|
---|
109 | cerr << "CRITICAL: ";
|
---|
110 | break;
|
---|
111 | case 1:
|
---|
112 | cerr << "ERROR: ";
|
---|
113 | break;
|
---|
114 | case 2:
|
---|
115 | default:
|
---|
116 | cerr << "WARNING: ";
|
---|
117 | break;
|
---|
118 | }
|
---|
119 | v.print(cerr);
|
---|
120 | return cerr;
|
---|
121 | } else
|
---|
122 | return *l->nix;
|
---|
123 | };
|
---|
124 |
|
---|
125 |
|
---|