17 #include "log4cplus/logger.h"
18 #include "log4cplus/fileappender.h"
19 #include "log4cplus/loglevel.h"
21 #include "xdaq/Application.h"
36 void makeFileAppender()
38 static bool iscalled =
false;
42 using namespace log4cplus;
43 using namespace log4cplus::helpers;
45 SharedAppenderPtr ap(
new FileAppender(
"log4cplus.output"));
47 ap->setLayout(std::auto_ptr<Layout>(
new log4cplus::TTCCLayout()) );
48 Logger::getRoot().addAppender(ap);
59 static char ts[] =
"dd-Mon-yyyy hh:mm:ss XYZ";
63 char *
c = ctime( &t );
64 strncpy( ts+ 0, c+ 8, 2 );
65 strncpy( ts+ 3, c+ 4, 3 );
66 strncpy( ts+ 7, c+20, 4 );
67 strncpy( ts+12, c+11, 8 );
68 strncpy( ts+21, tzname[localtime(&t)->tm_isdst], 3 );
71 strftime( ts, strlen(ts)+1,
"%d-%b-%Y %H:%M:%S %Z", localtime(&t) );
90 , wantTimestamp (
true )
92 , wantSubroutine (
true )
94 , wantSomeContext (
true )
95 , wantSerial (
false )
96 , wantFullContext (
false )
97 , wantTimeSeparate (
false )
98 , wantEpilogueSeparate(
false )
104 #ifdef ELlog4cplusCONSTRUCTOR_TRACE
105 std::cerr <<
"Constructor for ELlog4cplus()\n";
110 emit(
"\n=======================================================",
true );
111 emit(
"\nMessageLogger service established\n" );
113 emit(
"\n=======================================================\n",
true );
122 , osIsOwned ( orig.osIsOwned )
123 , charsOnLine ( orig.charsOnLine )
125 , wantTimestamp ( orig.wantTimestamp )
126 , wantModule ( orig.wantModule )
127 , wantSubroutine ( orig.wantSubroutine )
128 , wantText ( orig.wantText )
129 , wantSomeContext ( orig.wantSomeContext )
130 , wantSerial ( orig.wantSerial )
131 , wantFullContext ( orig.wantFullContext )
132 , wantTimeSeparate ( orig.wantTimeSeparate )
133 , wantEpilogueSeparate( orig.wantEpilogueSeparate )
134 , xxxxInt ( orig.xxxxInt )
135 , appl_ ( orig.appl_ )
138 #ifdef ELlog4cplusCONSTRUCTOR_TRACE
139 std::cerr <<
"Copy constructor for ELlog4cplus\n";
165 #ifdef ELlog4cplusCONSTRUCTOR_TRACE
166 std::cerr <<
"Destructor for ELlog4cplus\n";
170 ((std::ofstream*)
os)->close();
190 os->str(std::string());
192 #ifdef ELlog4cplusTRACE_LOG
193 std::cerr <<
" =:=:=: Log to an ELlog4cplus \n";
205 #ifdef ELlog4cplusTRACE_LOG
206 std::cerr <<
" =:=:=: Limits table work done \n";
210 bool mustPop =
false;
212 log4cplus::Logger loghere =
appl_ ?
appl_->getApplicationLogger() :
213 log4cplus::Logger::getInstance(msg.
xid().
module.c_str());
214 LOG4CPLUS_DEBUG(loghere,
"Message2log4cplus will use logger from appl_ ? "
215 << (
appl_ ?
"yes" :
"no"));
218 log4cplus::getNDC().push(msg.
xid().
module.c_str());
221 log4cplus::getNDC().push(msg.
context().c_str());
232 #ifdef ELlog4cplusTRACE_LOG
238 std::ostringstream
s;
246 ELlist_string::const_iterator it;
247 for ( it = msg.
items().begin(); it != msg.
items().end(); ++it ) {
248 #ifdef ELlog4cplusTRACE_LOG
249 std::cerr <<
" =:=:=: Item: " << *it <<
'\n';
257 bool needAspace =
true;
269 if (needAspace) {
emit(
ELstring(
" ")); needAspace =
false; }
273 if (needAspace) {
emit(
ELstring(
" ")); needAspace =
false; }
277 #ifdef ELlog4cplusTRACE_LOG
278 std::cerr <<
" =:=:=: Module and Subroutine done \n";
288 if (needAspace) {
emit(
ELstring(
" ")); needAspace =
false; }
292 #ifdef ELlog4cplusTRACE_LOG
293 std::cerr <<
" =:=:=: TimeStamp done \n";
299 if (needAspace) {
emit(
ELstring(
" ")); needAspace =
false; }
300 #ifdef ELlog4cplusTRACE_LOG
301 std::cerr <<
" =:=:=:>> context supplier is at 0x"
310 #ifdef ELlog4cplusTRACE_LOG
311 std::cerr <<
" =:=:=: fullContext done: \n";
315 #ifdef ELlog4cplusTRACE_LOG
330 #ifdef ELlog4cplusTRACE_LOG
331 std::cerr <<
" =:=:=: Trace routine done: \n";
337 #ifdef ELlog4cplusTRACE_LOG
338 std::cerr <<
" =:=:=: log(msg) done: \n";
348 LOG4CPLUS_DEBUG(loghere,
os->str());
353 LOG4CPLUS_INFO(loghere,
os->str());
358 LOG4CPLUS_WARN(loghere,
os->str());
364 LOG4CPLUS_ERROR(loghere,
os->str());
368 if(mustPop) log4cplus::getNDC().pop();
369 log4cplus::getNDC().pop();
397 #ifdef ELlog4cplus_EMIT_TRACE
399 std::cerr <<
"[][][] in emit: s.length() " << s.length() <<
'\n';
403 if (s.length() == 0) {
405 (*os) <<
newline << std::flush;
415 second = (s.length() < 2) ?
'\0' : s[1];
416 last = (s.length() < 2) ?
'\0' : s[s.length()-1];
417 last2 = (s.length() < 3) ?
'\0' : s[s.length()-2];
423 || (charsOnLine + static_cast<int>(s.length())) >
lineLength ) {
424 #ifdef ELlog4cplus_EMIT_TRACE
425 std::cerr <<
"[][][] in emit: about to << to *os \n";
428 charsOnLine = indent.length();
433 if ( first ==
'\n' ) {
434 (*os) << s.substr(1);
441 #ifdef ELlog4cplus_EMIT_TRACE
442 std::cerr <<
"[][][] in emit: about to << s to *os: " << s <<
" \n";
449 if (last ==
'\n' || last2 ==
'\n') {
453 charsOnLine = indent.length() + 1;
456 if ( nl ) { (*os) <<
newline << std::flush; charsOnLine = 0; }
457 else { charsOnLine += s.length(); }
459 #ifdef ELlog4cplus_EMIT_TRACE
460 std::cerr <<
"[][][] in emit: completed \n";
506 const int titleMaxLength( 40 );
533 std::cout <<
"setting application pointer in ELlog4cplus" << std::endl;
ELseverityLevel traceThreshold
const ELcontextSupplier & getContextSupplier() const
virtual void suppressSerial()
const ELstring & idOverflow() const
virtual void attachEpilogue()
virtual void separateTime()
virtual void includeSerial()
virtual void suppressSubroutine()
virtual void includeText()
virtual void includeSubroutine()
virtual bool thisShouldBeIgnored(const ELstring &s) const
virtual void includeTime()
ELseverityLevel threshold
void setAppl(xdaq::Application *a)
virtual void suppressContext()
U second(std::pair< T, U > const &p)
const ELstring getSymbol() const
virtual void separateEpilogue()
virtual void emit(const ELstring &s, bool nl=false)
const ELextendedID & xid() const
bool add(const ELextendedID &xid)
ELset_string respondToThese
virtual bool log(const ErrorObj &msg)
virtual void attachTime()
virtual ELlog4cplus * clone() const
xdaq::Application * appl_
virtual void includeModule()
virtual ELstring context() const =0
const ELlist_string & items() const
static ELadministrator * instance()
virtual void suppressModule()
static char * formatTime(const time_t t)
bool respondToMostModules
virtual void suppressText()
virtual void suppressTime()
virtual void includeContext()
virtual void useFullContext()
bool wantEpilogueSeparate
T first(std::pair< T, U > const &p)
virtual void useContext()
virtual void summarization(const ELstring &fullTitle, const ELstring &sumLines)