source: ThirdParty/CodePatterns/src/Helpers/errorlogger.cpp@ 6458e7

AutomationFragmentation_failures Candidate_v1.6.1 ChemicalSpaceEvaluator Exclude_Hydrogens_annealWithBondGraph ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_contraction-expansion Gui_displays_atomic_force_velocity PythonUI_with_named_parameters StoppableMakroAction TremoloParser_IncreasedPrecision
Last change on this file since 6458e7 was 9eb71b3, checked in by Frederik Heber <frederik.heber@…>, 8 years ago

Commented out MemDebug include and Memory::ignore.

  • MemDebug clashes with various allocation operators that use a specific placement in memory. It is so far not possible to wrap new/delete fully. Hence, we stop this effort which so far has forced us to put ever more includes (with clashes) into MemDebug and thereby bloat compilation time.
  • MemDebug does not add that much usefulness which is not also provided by valgrind.
  • Property mode set to 100644
File size: 2.9 KB
Line 
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 "CodePatterns/MemDebug.hpp"
21
22#include <fstream>
23#include <iostream>
24#include "CodePatterns/errorlogger.hpp"
25#include "CodePatterns/Verbose.hpp"
26#include "CodePatterns/Singleton_impl.hpp"
27
28int errorLogger::verbosity = 2;
29ostream* errorLogger::nix = NULL;
30ostream* errorLogger::defaultout = NULL;
31ostream* errorLogger::out = NULL;
32
33/**
34 * Constructor. Do not use this function. Use getInstance() instead.
35 *
36 * \return errorLogger instance
37 */
38errorLogger::errorLogger()
39{
40 nix = new ofstream("/dev/null");
41 defaultout = &cerr;
42 out = defaultout;
43};
44
45/**
46 * Destructor. Better use purgeInstance().
47 */
48errorLogger::~errorLogger()
49{
50 delete nix;
51 out = NULL; // we are not responsible if out got changed
52 defaultout = NULL; // do not delete cerr
53}
54
55CONSTRUCT_SINGLETON(errorLogger)
56
57/**
58 * Sets the verbosity.
59 *
60 * \param verbosityLevel verbosity
61 */
62void errorLogger::setVerbosity(int verbosityLevel) {
63 verbosity = verbosityLevel;
64}
65
66/**
67 * Gets the verbosity.
68 *
69 * \return verbosity level
70 */
71int errorLogger::getVerbosity()
72{
73 return verbosity;
74}
75
76/** Sets a new output stream.
77 *
78 * \param _newout new output stream, if NULL we set to defaultout
79 */
80void errorLogger::setOutputStream(ostream *_newout)
81{
82 if(_newout != NULL)
83 out = _newout;
84 else
85 out = defaultout;
86}
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 */
98ostream& operator<<(class errorLogger& l, const Verbose& v)
99{
100 int verbosityLevel = l.verbosity;
101 l.nix->clear();
102 if (v.DoErrorOutput(verbosityLevel)) {
103 switch(v.Verbosity) {
104 case 0:
105 cerr << "CRITICAL: ";
106 break;
107 case 1:
108 cerr << "ERROR: ";
109 break;
110 case 2:
111 cerr << "WARNING: ";
112 break;
113 default:
114 break;
115 }
116 v.print(*errorLogger::out);
117 return *errorLogger::out;
118 } else
119 return *l.nix;
120};
121ostream& operator<<(class errorLogger* l, const Verbose& v)
122{
123 int verbosityLevel = l->verbosity;
124 l->nix->clear();
125 if (v.DoErrorOutput(verbosityLevel)) {
126 switch(v.Verbosity) {
127 case 0:
128 cerr << "CRITICAL: ";
129 break;
130 case 1:
131 cerr << "ERROR: ";
132 break;
133 case 2:
134 default:
135 cerr << "WARNING: ";
136 break;
137 }
138 v.print(*errorLogger::out);
139 return *errorLogger::out;
140 } else
141 return *l->nix;
142};
143
144
Note: See TracBrowser for help on using the repository browser.