source: src/Helpers/errorlogger.cpp@ 115378

Last change on this file since 115378 was 115378, checked in by Frederik Heber <heber@…>, 15 years ago

Changes to allow for (re-)incorporation of CodePatterns into MoleCuilder.

library:

  • no more suffixed with version, this should be dealt by pkg-config (.pc) or a contained version information.
  • corrected and extended .pc file
  • m4 macro ax_codepatterns.m4 created to allow for easy checking with autotools

codepatterns-config:

  • if pkg-config fails there is a small tool that tells about necessary cflags and the likes to compile with CodePatterns library (this was developed before we noticed we had a (half-)working pkg-config present).

smaller changes:

  • moved all Helpers files to src/Helpers (again).
  • changed include paths for Assert.hpp, ... accordingly.
  • version is not prefixed with "v" anymore.
  • small stuff in fast_functions.hpp is absolete (stl::algorithms)
  • Helpers/enumeration.hpp contains enumeration class ("iterable enum")
  • Property mode set to 100644
File size: 2.4 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 "MemDebug.hpp"
21
22#include <fstream>
23#include <iostream>
24#include "errorlogger.hpp"
25#include "Verbose.hpp"
26#include "Patterns/Singleton_impl.hpp"
27
28int errorLogger::verbosity = 2;
29ostream* errorLogger::nix = NULL;
30
31/**
32 * Constructor. Do not use this function. Use getInstance() instead.
33 *
34 * \return errorLogger instance
35 */
36errorLogger::errorLogger()
37{
38 nix = new ofstream("/dev/null");
39};
40
41/**
42 * Destructor. Better use purgeInstance().
43 */
44errorLogger::~errorLogger()
45{
46 delete nix;
47}
48
49CONSTRUCT_SINGLETON(errorLogger)
50
51/**
52 * Sets the verbosity.
53 *
54 * \param verbosityLevel verbosity
55 */
56void errorLogger::setVerbosity(int verbosityLevel) {
57 verbosity = verbosityLevel;
58}
59
60/**
61 * Gets the verbosity.
62 *
63 * \return verbosity level
64 */
65int 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 */
79ostream& 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};
102ostream& 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
Note: See TracBrowser for help on using the repository browser.