GENIEGenerator
Loading...
Searching...
No Matches
genie::Messenger Class Reference

A more convenient interface to the log4cpp Message Service. More...

#include <Messenger.h>

Collaboration diagram for genie::Messenger:
[legend]

Classes

struct  Cleaner

Public Member Functions

log4cpp::Category & operator() (const char *stream)
void SetPriorityLevel (const char *stream, log4cpp::Priority::Value p)
bool SetPrioritiesFromXmlFile (string filename)

Static Public Member Functions

static MessengerInstance (void)

Private Member Functions

 Messenger ()
 Messenger (const Messenger &config_pool)
virtual ~Messenger ()
void Configure (void)
log4cpp::Priority::Value PriorityFromString (string priority)

Static Private Attributes

static MessengerfInstance = 0

Friends

struct Cleaner

Detailed Description

A more convenient interface to the log4cpp Message Service.

Author
Costas Andreopoulos <c.andreopoulos \at cern.ch> University of Liverpool
Created:\n June 16, 2004
License:\n Copyright (c) 2003-2025, The GENIE Collaboration
For the full text of the license visit http://copyright.genie-mc.org

Definition at line 258 of file Messenger.h.

Constructor & Destructor Documentation

◆ Messenger() [1/2]

Messenger::Messenger ( )
private

Definition at line 39 of file Messenger.cxx.

40{
41 fInstance = 0;
42}
static Messenger * fInstance
Definition Messenger.h:273

References fInstance.

Referenced by Instance(), and Messenger().

◆ Messenger() [2/2]

genie::Messenger::Messenger ( const Messenger & config_pool)
private

References Messenger().

◆ ~Messenger()

Messenger::~Messenger ( )
privatevirtual

Definition at line 44 of file Messenger.cxx.

45{
46 fInstance = 0;
47}

References fInstance.

Member Function Documentation

◆ Configure()

void Messenger::Configure ( void )
private

Definition at line 96 of file Messenger.cxx.

97{
98// The Configure() method will look for priority level xml config files, read
99// the priority levels and set them.
100// By default, first it will look for the $GENIE/config/Messenger.xml file.
101// Look at this file for the XML schema.
102
103 string msg_config_file = utils::xml::GetXMLFilePath("Messenger.xml");
104
105 // parse & set the default priority levels
106 bool ok = this->SetPrioritiesFromXmlFile(msg_config_file);
107 if(!ok) {
108 SLOG("Messenger", pERROR)
109 << "Priority levels from: " << msg_config_file << " were not set!";
110 }
111
112}
#define pERROR
Definition Messenger.h:59
#define SLOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a short string (using the FUNCTION and...
Definition Messenger.h:84
bool SetPrioritiesFromXmlFile(string filename)
string GetXMLFilePath(string basename)

References genie::utils::xml::GetXMLFilePath(), pERROR, SetPrioritiesFromXmlFile(), and SLOG.

◆ Instance()

Messenger * Messenger::Instance ( void )
static

Definition at line 49 of file Messenger.cxx.

50{
51 if(fInstance == 0) {
52
53 // the first thing that get's printed in a GENIE session is the banner
55
56 static Messenger::Cleaner cleaner;
58
59 fInstance = new Messenger;
60
61 log4cpp::Appender * appender;
62 appender = new log4cpp::OstreamAppender("default", &cout);
63 const char* layoutenv = gSystem->Getenv("GMSGLAYOUT");
64 std::string layoutstr = (layoutenv) ? string(layoutenv) : "BASIC";
65 if ( layoutstr == "SIMPLE" )
66 appender->setLayout(new log4cpp::SimpleLayout());
67 else
68 appender->setLayout(new log4cpp::BasicLayout());
69
70
71 log4cpp::Category & MSG = log4cpp::Category::getRoot();
72
73 MSG.setAdditivity(false);
74 MSG.addAppender(appender);
75
76 fInstance->Configure(); // set user-defined priority levels
77 }
78 return fInstance;
79}
friend struct Cleaner
Definition Messenger.h:288

References genie::Messenger::Cleaner::DummyMethodAndSilentCompiler(), fInstance, Messenger(), and genie::utils::print::PrintBanner().

Referenced by genie::GMCJDriver::InitJob(), main(), main(), genie::utils::app_init::MesgThresholds(), and VerticalSlice().

◆ operator()()

log4cpp::Category & Messenger::operator() ( const char * stream)

Definition at line 81 of file Messenger.cxx.

82{
83 log4cpp::Category & MSG = log4cpp::Category::getInstance(stream);
84
85 return MSG;
86}

◆ PriorityFromString()

log4cpp::Priority::Value Messenger::PriorityFromString ( string priority)
private

Definition at line 192 of file Messenger.cxx.

193{
194 if ( p.find("DEBUG") != string::npos ) return log4cpp::Priority::DEBUG;
195 if ( p.find("INFO") != string::npos ) return log4cpp::Priority::INFO;
196 if ( p.find("NOTICE") != string::npos ) return log4cpp::Priority::NOTICE;
197 if ( p.find("WARN") != string::npos ) return log4cpp::Priority::WARN;
198 if ( p.find("ERROR") != string::npos ) return log4cpp::Priority::ERROR;
199 if ( p.find("CRIT") != string::npos ) return log4cpp::Priority::CRIT;
200 if ( p.find("ALERT") != string::npos ) return log4cpp::Priority::ALERT;
201 if ( p.find("FATAL") != string::npos ) return log4cpp::Priority::FATAL;
202
203 SLOG("Messenger", pWARN)
204 << "Unknown priority = " << p << " - Setting to INFO";
205 return log4cpp::Priority::INFO;
206}
#define pWARN
Definition Messenger.h:60

References pWARN, and SLOG.

Referenced by SetPrioritiesFromXmlFile().

◆ SetPrioritiesFromXmlFile()

bool Messenger::SetPrioritiesFromXmlFile ( string filename)

Definition at line 114 of file Messenger.cxx.

115{
116// Reads input XML config file and sets the priority levels.
117// The input can be a colection of XML files, delimited with a ":".
118// The full path for each file should be given.
119// In case of multiple files, all files are read.
120// The later each file is, the higher priority it has (if the same mesg
121// stream is listed twice with conflicting priority, the last one is used.).
122//
123
124 if(filenames.size()==0) return false;
125
126 vector<string> filename_vec = utils::str::Split(filenames, ":");
127 if(filename_vec.size() == 0) return false;
128
129 vector<string>::const_iterator filename_iter;
130 for(filename_iter = filename_vec.begin();
131 filename_iter != filename_vec.end(); ++filename_iter)
132 {
133 // look in all known XML locations, just like primary file
134 string filename = utils::xml::GetXMLFilePath(*filename_iter);
135
136 SLOG("Messenger", pNOTICE)
137 << "Reading msg stream priorities from XML file: " << filename;
138
139 xmlDocPtr xml_doc = xmlParseFile(filename.c_str());
140 if(xml_doc==NULL) {
141 SLOG("Messenger", pERROR)
142 << "XML file could not be parsed! [file: " << filename << "]";
143 return false;
144 }
145
146 xmlNodePtr xml_root = xmlDocGetRootElement(xml_doc);
147 if(xml_root==NULL) {
148 SLOG("Messenger", pERROR)
149 << "XML doc. has null root element! [file: " << filename << "]";
150 xmlFreeDoc(xml_doc);
151 return false;
152 }
153
154 if( xmlStrcmp(xml_root->name, (const xmlChar *) "messenger_config") ) {
155 SLOG("Messenger", pERROR)
156 << "XML doc. has invalid root element! [file: " << filename << "]";
157 xmlFreeNode(xml_root);
158 xmlFreeDoc(xml_doc);
159 return false;
160 }
161
162 xmlNodePtr xml_msgp = xml_root->xmlChildrenNode; // <priority>'s
163
164 // loop over all xml tree nodes that are children of the <spline> node
165 while (xml_msgp != NULL) {
166
167 // enter everytime you find a <priority> tag
168 if( (!xmlStrcmp(xml_msgp->name, (const xmlChar *) "priority")) ) {
169
170 string msgstream = utils::str::TrimSpaces(
171 utils::xml::GetAttribute(xml_msgp, "msgstream"));
172 string priority =
173 utils::xml::TrimSpacesClean( xmlNodeListGetString(
174 xml_doc, xml_msgp->xmlChildrenNode, 1));
175 log4cpp::Priority::Value pv = this->PriorityFromString(priority);
176 this->SetPriorityLevel(msgstream.c_str(), pv);
177 SLOG("Messenger", pINFO)
178 << "Set priority level: " << setfill('.')
179 << setw(24) << msgstream << " --> " << priority;
180 }
181 xml_msgp = xml_msgp->next;
182 }//xml_msgp != NULL
183
184 //xmlFree(xml_msgp);
185 xmlFreeNode(xml_msgp);
186 xmlFreeDoc(xml_doc);
187 }//filename_iter
188
189 return true;
190}
#define pNOTICE
Definition Messenger.h:61
#define pINFO
Definition Messenger.h:62
log4cpp::Priority::Value PriorityFromString(string priority)
void SetPriorityLevel(const char *stream, log4cpp::Priority::Value p)
Definition Messenger.cxx:88
string TrimSpaces(string input)
vector< string > Split(string input, string delim)
string GetAttribute(xmlNodePtr xml_cur, string attr_name)
string TrimSpacesClean(xmlChar *xmls)

References genie::utils::xml::GetAttribute(), genie::utils::xml::GetXMLFilePath(), pERROR, pINFO, pNOTICE, PriorityFromString(), SetPriorityLevel(), SLOG, genie::utils::str::Split(), genie::utils::str::TrimSpaces(), and genie::utils::xml::TrimSpacesClean().

Referenced by Configure(), and genie::utils::app_init::MesgThresholds().

◆ SetPriorityLevel()

void Messenger::SetPriorityLevel ( const char * stream,
log4cpp::Priority::Value p )

Definition at line 88 of file Messenger.cxx.

90{
91 log4cpp::Category & MSG = log4cpp::Category::getInstance(stream);
92
93 MSG.setPriority(priority);
94}

Referenced by main(), main(), SetPrioritiesFromXmlFile(), and VerticalSlice().

◆ Cleaner

friend struct Cleaner
friend

Definition at line 288 of file Messenger.h.

Member Data Documentation

◆ fInstance

Messenger * Messenger::fInstance = 0
staticprivate

Definition at line 273 of file Messenger.h.

Referenced by Instance(), Messenger(), genie::Messenger::Cleaner::~Cleaner(), and ~Messenger().


The documentation for this class was generated from the following files: