GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Attributes | Friends | List of all members
genie::Messenger Class Reference

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

#include <Messenger.h>

Collaboration diagram for genie::Messenger:
Collaboration graph
[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 cern.ch> University of Liverpool
Created:
June 16, 2004
License:
Copyright (c) 2003-2024, 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::Messenger ( )
private

Definition at line 39 of file Messenger.cxx.

References fInstance.

Referenced by Instance().

40 {
41  fInstance = 0;
42 }
static Messenger * fInstance
Definition: Messenger.h:273
genie::Messenger::Messenger ( const Messenger config_pool)
private
Messenger::~Messenger ( )
privatevirtual

Definition at line 44 of file Messenger.cxx.

References fInstance.

45 {
46  fInstance = 0;
47 }
static Messenger * fInstance
Definition: Messenger.h:273

Member Function Documentation

void Messenger::Configure ( void  )
private

Definition at line 96 of file Messenger.cxx.

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

Referenced by Instance().

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
bool SetPrioritiesFromXmlFile(string filename)
Definition: Messenger.cxx:114
string GetXMLFilePath(string basename)
#define SLOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a short string (using the FUNCTION and...
Definition: Messenger.h:84
Messenger * Messenger::Instance ( void  )
static

Definition at line 49 of file Messenger.cxx.

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

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

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 }
void DummyMethodAndSilentCompiler()
Definition: Messenger.h:280
void Configure(void)
Definition: Messenger.cxx:96
void PrintBanner(void)
Definition: PrintUtils.cxx:114
static Messenger * fInstance
Definition: Messenger.h:273
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 }
log4cpp::Priority::Value Messenger::PriorityFromString ( string  priority)
private

Definition at line 192 of file Messenger.cxx.

References pWARN, and SLOG.

Referenced by SetPrioritiesFromXmlFile().

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
#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 Messenger::SetPrioritiesFromXmlFile ( string  filename)

Definition at line 114 of file Messenger.cxx.

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::TrimSpaces().

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

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::TrimSpaces( 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 pERROR
Definition: Messenger.h:59
string TrimSpaces(xmlChar *xmls)
log4cpp::Priority::Value PriorityFromString(string priority)
Definition: Messenger.cxx:192
string GetXMLFilePath(string basename)
#define pINFO
Definition: Messenger.h:62
string TrimSpaces(string input)
Definition: StringUtils.cxx:18
vector< string > Split(string input, string delim)
Definition: StringUtils.cxx:36
void SetPriorityLevel(const char *stream, log4cpp::Priority::Value p)
Definition: Messenger.cxx:88
#define pNOTICE
Definition: Messenger.h:61
#define SLOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a short string (using the FUNCTION and...
Definition: Messenger.h:84
string GetAttribute(xmlNodePtr xml_cur, string attr_name)
void Messenger::SetPriorityLevel ( const char *  stream,
log4cpp::Priority::Value  p 
)

Definition at line 88 of file Messenger.cxx.

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

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

Friends And Related Function Documentation

friend struct Cleaner
friend

Definition at line 288 of file Messenger.h.

Member Data Documentation

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: