source: src/Helpers/errorlogger.cpp@ dfafe7

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since dfafe7 was 052afe, checked in by Frederik Heber <heber@…>, 14 years ago

MEMFIX: ofstreams in ...logger.hpp as static objects were not recognized by MemDebug.

  • now they are allocated via new in the constructor of the ...logger's.
  • Calling new ofstream(..) globally would cause segfaults in some unit tests.
  • Constructor is private (due to logger's being singletons), hence this is safe.

NOTE: the problem is not the static object itself, but what is allocated
dynamically inside the object's constructor (this also concerns previous
fixes)

  • 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 "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
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.