// $Id: EsafMsgSource.cc,v 1.8 2005/01/15 16:56:59 thea Exp $
// M. Pallavicini created Sep, 24 2004
/*****************************************************************************
* ESAF: Euso Simulation and Analysis Framework *
* *
* Id: EsafMsgSource *
* Package: Optics *
* Coordinator: Marco.Pallavicini *
* *
*****************************************************************************/
//_____________________________________________________________________________
//
// ESAF Message Source
// ===================
//
// Each class that wants to send messages must inherit from this one
//
// Two ways to send a message:
//
// Using a stream
// examples (equivalent):
// Msg(EsafMsg::Warning) << "my text" << MsgDispatch;
// or
// Msg(EsafMsg::Warning) << "my text";
// Dispatch();
//
// or using printf like syntax:
// example:
// MsgForm( EsafMsg::Severity, "msg with printf formatting", var1, var2...);
//
// The messages are dispatched on screen and log file according to the default
// values specified by the configuration files
//
//
//
#include "EsafMsgSource.hh"
#include "TClass.h"
#include "TString.h"
#include <iostream>
#include <list>
ClassImp(EsafMsgSource)
//______________________________________________________________________________
EsafMsgSource::EsafMsgSource() {
//
// ctor
//
fMsg.Clear();
}
//______________________________________________________________________________
EsafMsgSource::EsafMsgSource( const EsafMsgSource& ) {
//
// copy ctor
//
}
//______________________________________________________________________________
EsafMsg& EsafMsgSource::Msg(EsafMsg::MsgSeverity s) const {
//
// Prepare a new message and returns it
//
if ( fMsg.GetSender() == "None") fMsg.SetSender(IsA()->GetName());
fMsg.SetSeverity(s);
return fMsg;
}
const size_t kMaxBufSize = 4096;
//______________________________________________________________________________
void EsafMsgSource::MsgForm(EsafMsg::MsgSeverity s, const char *va_(fmt), ...) const {
//
// Prepare and send a message with printf syntax
//
static char b[kMaxBufSize];
va_list ap;
va_start(ap,fmt);
vsnprintf(b,kMaxBufSize,fmt,ap); // There is no boundary check here. (bug)
va_end(ap);
Msg(s) << b << MsgDispatch;
}