JobCMsgModule Class Reference

#include <JobCMsgModule.h>

Inheritance diagram for JobCMsgModule:

JobCModule List of all members.

Public Member Functions

 JobCMsgModule ()
 ~JobCMsgModule ()
void HandleCommand (JobCommand *cmd)
void Help ()
void Report ()
void Reset ()
void SetLevel (const char *stream, const char *level)
void Attach (const char *stream, const char *os)
void Format (const char *stream, const char *fmt, bool add=true)
void SetDefaultFormat (const char *fmt, const char *level="")
void Concat ()
void Stats ()

Detailed Description

Definition at line 16 of file JobCMsgModule.h.


Constructor & Destructor Documentation

JobCMsgModule::JobCMsgModule (  ) 

Definition at line 28 of file JobCMsgModule.cxx.

00028 {}

JobCMsgModule::~JobCMsgModule (  ) 

Definition at line 32 of file JobCMsgModule.cxx.

00032 {}


Member Function Documentation

void JobCMsgModule::Attach ( const char *  stream,
const char *  os 
)

Definition at line 36 of file JobCMsgModule.cxx.

References MsgStream::AttachOStream(), Msg::GetLevelCode(), JobCModule::GetName(), MsgService::GetStream(), MsgService::Instance(), Msg::kWarning, Munits::m, MSG, and JobCommand::SplitLine().

Referenced by HandleCommand().

00037 {
00038 //======================================================================
00039 // Purpose: Attach an output stream to a given message stream. Expected
00040 // order of options: <msg_stream_name>::<log_level> <output_stream>
00041 //  
00042 // Inputs: cmd - the job command
00043 //======================================================================
00044   if (msgstream == 0 || os == 0 ) {
00045     MSG("JobC", Msg::kWarning) <<
00046       "usage: /" << this->GetName() << "/Attach <stream> <level> <ostream>\n";
00047     return;
00048   }
00049   else {
00050     string stream; // Which stream?
00051     string level;  // Which priority?
00052     MsgStream *m;
00053     
00054     JobCommand::SplitLine(msgstream, ':', stream, level);
00055     Msg::LogLevel_t lvl = Msg::GetLevelCode(level.c_str());
00056     
00057     m = MsgService::Instance()->GetStream(stream.c_str());
00058     m->AttachOStream(lvl,os);
00059   }
00060 }

void JobCMsgModule::Concat (  ) 

Definition at line 64 of file JobCMsgModule.cxx.

References sorry().

Referenced by HandleCommand().

00065 { 
00066   sorry(); 
00067 }

void JobCMsgModule::Format ( const char *  stream,
const char *  fmt,
bool  add = true 
)

Definition at line 71 of file JobCMsgModule.cxx.

References Msg::GetFormatCode(), Msg::GetLevelCode(), MsgService::GetStream(), MsgService::Instance(), Munits::ms, JobCommand::SplitLine(), and JobCommand::StringTok().

Referenced by HandleCommand().

00074 {
00075 //======================================================================
00076 // Purpose: Set format flags for a given message stream.
00077 // 
00078 // Inputs: 
00079 //   msgstream : The stream to affect. Format is <msgname>::<loglevel>
00080 //   fmtflags  : List of format flags to affect (space, comma, sepatated)
00081 //   raiseFlag : true=raise the format flags, false=lower the flags
00082 //======================================================================
00083   string stream;
00084   string level;
00085   MsgStream *ms;
00086   Msg::LogLevel_t lvl;
00087 
00088   JobCommand::SplitLine(msgstream, ':', stream, level);
00089   ms = MsgService::Instance()->GetStream(stream.c_str());
00090   
00091   lvl = 0;
00092   lvl = Msg::GetLevelCode(level.c_str());
00093 
00094   // Walk over the input string and strip out the individual format flags
00095   vector<string> fmtlist;
00096   JobCommand::StringTok(fmtlist,fmtflags," +,");
00097   vector<string>::iterator itr(fmtlist.begin());
00098   vector<string>::iterator itrEnd(fmtlist.end());
00099   for (; itr!=itrEnd; ++itr) {
00100     int format = Msg::GetFormatCode( (*itr).c_str() );   
00101     if (raiseFlag) { ms->AddFormat(lvl,format);    }
00102     else           { ms->RemoveFormat(lvl,format); }
00103   }
00104 }

void JobCMsgModule::HandleCommand ( JobCommand cmd  )  [virtual]

Implement to handle a JobCommand

Reimplemented from JobCModule.

Definition at line 139 of file JobCMsgModule.cxx.

References Attach(), Concat(), Format(), JobCModule::GetName(), Msg::kWarning, MSG, JobCommand::PopCmd(), JobCommand::PopOpt(), Report(), SetLevel(), and Stats().

00140 {
00141 //======================================================================
00142 // Purpose: Handle a command related to the message service
00143 // configuration
00144 //
00145 // Inputs: cmd - a job command
00146 //======================================================================
00147   string c = cmd->PopCmd();
00148 
00149   if (c == "SetLevel")   {
00150     const char *stream = cmd->PopOpt();
00151     const char *level  = cmd->PopOpt();
00152     this->SetLevel(stream, level);
00153     return;
00154   }
00155   if (c == "Attach") {
00156     const char *stream = cmd->PopOpt();
00157     const char *os     = cmd->PopOpt();
00158     this->Attach(stream, os);
00159     return;
00160   }
00161   if (c == "Format") {
00162     std::string stream = cmd->PopOpt();
00163     std::string flags  = cmd->PopOpt();
00164     std::string add    = cmd->PopOpt();
00165     if (add == "Remove") {
00166       this->Format(stream.c_str(), flags.c_str(), false);
00167     }
00168     else {
00169       this->Format(stream.c_str(), flags.c_str(), true);
00170     }
00171     return;
00172   }
00173   if (c == "Concat") {
00174     this->Concat();
00175     return;
00176   }
00177   if (c == "Report") {
00178     this->Report();
00179     return;
00180   }
00181   if (c == "Stats") {
00182     this->Stats();
00183     return;
00184   }
00185   else {
00186     MSG("JobC",Msg::kWarning) << 
00187       "Module " << this->GetName() << 
00188       " does not implement command " << c << "." << endl;    
00189   }
00190 }

void JobCMsgModule::Help (  )  [virtual]

Implement to spew some useful help to cout

Reimplemented from JobCModule.

Definition at line 194 of file JobCMsgModule.cxx.

References _NL_, JobCModule::GetName(), Msg::kInfo, and MSG.

00195 {
00196 //======================================================================
00197 // Purpose: Print help for this module
00198 //======================================================================
00199 #define _NL_ <<"\n"<<
00200   const char *n = this->GetName();
00201   MSG("JobC",Msg::kInfo) <<
00202     "Help for '" << this->GetName() << "' module:\n" <<
00203     " " << this->GetName() << 
00204     " is a module for configuring the message service. It can be used" _NL_
00205     " to set log levels, direct output, set formats etc. for the" _NL_
00206     " various package streams. For example, to lower the print" _NL_
00207     " threshold for the stream 'Trk' use:" _NL_
00208     " /Msg/SetLevel Trk Debug" _NL_
00209     "" _NL_
00210     " Possible commands are:" _NL_
00211     "" _NL_
00212     " /" << n << "/SetLevel <stream> <level>" _NL_
00213     "" _NL_
00214     "  Set the log level for <stream> to <level> where <level> is" _NL_
00215     "  Verbose,Debug,Info,Error,Warning,Fatal" _NL_
00216     "" _NL_
00217     " /" << n << "/Attach <stream>::<loglevel> <ostream>" _NL_
00218     "" _NL_
00219     "  Attach the output stream <ostream> to the list of output streams" _NL_
00220     "  messages sent to <stream> of type <loglevel> get send to." _NL_
00221     "  <ostream> can be cout, cerr, clog, or file name. <loglevel> can" _NL_
00222     "  be Verbose, Debug, Info, Warning, Error, Fatal, or All." _NL_
00223     "" _NL_
00224     " /" << n << "/Format <stream>::<loglevel> <Add/Remove> <format>" _NL_
00225     "" _NL_
00226     "  Add/Remove additional tags to messages. Possibilities are:" _NL_
00227     "  Priority, Time, File, CVSId, Line, Host, and PID."  << 
00228     "" _NL_ endl;
00229 }

void JobCMsgModule::Report (  )  [virtual]

Implement to spew end of running report

Reimplemented from JobCModule.

Definition at line 240 of file JobCMsgModule.cxx.

References MsgService::Instance().

Referenced by HandleCommand().

00241 {  
00242   cerr << (*MsgService::Instance());
00243 }

void JobCMsgModule::Reset (  )  [virtual]

Implement to reset oneself

Reimplemented from JobCModule.

Definition at line 247 of file JobCMsgModule.cxx.

References sorry().

00248 { 
00249   sorry(); 
00250 }

void JobCMsgModule::SetDefaultFormat ( const char *  fmt,
const char *  level = "" 
)

Definition at line 108 of file JobCMsgModule.cxx.

References Msg::GetFormatCode(), Msg::GetLevelCode(), MsgService::Instance(), MsgService::SetDefaultFormat(), and JobCommand::StringTok().

00110 {
00111 //======================================================================
00112 // Purpose: Sets the default format flags for all newly created streams
00113 // 
00114 // Inputs: 
00115 //   fmtflags  : List of format flags to affect (space, comma, sepatated)
00116 //   level     : What format level. Blank = all levels
00117 //======================================================================
00118   Int_t lvl;
00119 
00120   lvl = Msg::GetLevelCode(level);
00121   if(lvl==-1) lvl=99;
00122 
00123   // Walk over the input string and strip out the individual format flags
00124   int format = 0;
00125   vector<string> fmtlist;
00126   JobCommand::StringTok(fmtlist,fmtflags," +,");
00127   vector<string>::iterator itr(fmtlist.begin());
00128   vector<string>::iterator itrEnd(fmtlist.end());
00129   for (; itr!=itrEnd; ++itr) {
00130     format |= Msg::GetFormatCode( (*itr).c_str() );   
00131   }
00132 
00133   MsgService::Instance()->SetDefaultFormat(format,lvl);
00134 
00135 }

void JobCMsgModule::SetLevel ( const char *  stream,
const char *  level 
)

Definition at line 254 of file JobCMsgModule.cxx.

References Msg::GetLevelCode(), MsgService::GetStream(), MsgService::Instance(), Msg::kDebug, Msg::kInfo, Msg::kWarning, MSG, and Munits::s.

Referenced by atmo_set_msg_levels(), far_all_set_msg_levels(), far_cosmic_mc_set_msg_levels(), far_mc_set_msg_levels(), far_set_msg_levels(), HandleCommand(), main(), mrcc_set_msg_levels(), near_cosmic_mc_set_msg_levels(), near_cosmic_set_msg_levels(), near_mc_set_msg_levels(), near_set_msg_levels(), run(), set_msg_levels_far(), set_msg_levels_far_all(), set_msg_levels_far_all_mc(), set_msg_levels_far_mc(), set_msg_levels_near(), set_msg_levels_near_cosmic(), set_msg_levels_near_cosmic_mc(), set_msg_levels_near_mc(), SetMSGLevels(), and srsafitter_set_msg_levels().

00255 {
00256 //======================================================================
00257 // Purpose: Set the print threshold for a given stream. Expects options
00258 // in the following order: <stream_name> <level>
00259 //
00260 // Inputs: cmd - job command
00261 //======================================================================
00262   MsgStream *s = MsgService::Instance()->GetStream(stream);
00263   if (s==0) {
00264     MSG("JobC", Msg::kWarning) <<
00265       "Can not find message stream " << stream << "." << endl;
00266     return;
00267   }
00268   
00269   Msg::LogLevel_t lvl = Msg::GetLevelCode(level);
00270   if (lvl>=0) {
00271     MSG("JobC", Msg::kDebug) << 
00272       "Setting level '" << level << "' for stream " << stream << "\n";
00273     s->SetLogLevel(lvl);
00274   }
00275   else {
00276     MSG("JobC", Msg::kInfo) << 
00277       "'" << level << "' is not valid log level. " <<
00278       "Using default log level 'Info'" << endl;
00279     s->SetLogLevel(Msg::kInfo);
00280   }
00281 }

void JobCMsgModule::Stats (  ) 

Definition at line 233 of file JobCMsgModule.cxx.

References MsgService::Instance(), and MsgService::PrintStatistics().

Referenced by HandleCommand(), and run().

00234 {  
00235   MsgService::Instance()->PrintStatistics();
00236 }


The documentation for this class was generated from the following files:
Generated on Mon Aug 11 01:05:57 2014 for loon by  doxygen 1.4.7