Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//--------------------------------------------------------------------------
// $Id: ErrLineLog.cc,v 1.1.1.1 2005/03/29 17:04:19 steinke Exp $
//
// Description:
//
// Error & logging implementation which writes facility/code to messages.
// Based on ErrLogger/ErrStdLog.
//
// Environment:
// Software developed for the BaBar Detector at the SLAC B-Factory.
//
// Author List:
// Michael Kelsey <kelsey@slac.stanford.edu>
//
// Copyright Information:
// Copyright (C) 1999 Princeton University
//
//------------------------------------------------------------------------
//-----------------------
// This Class's Header --
//-----------------------
#include "ErrLogger/ErrLineLog.hh"
//-----------------
// C/C++ Headers --
//-----------------
#include <assert.h>
#include <string.h>
#include <iostream>
//-------------------------------
// Collaborating Class Headers --
//------------------------------
#include "ErrLogger/ErrStream.hh"
using std::ostream;
// --------------------------------
// -- Constructor and Destructor --
// --------------------------------
ErrLineLog::ErrLineLog( Severity theSeverity )
: ErrStdLog(theSeverity)
{ } // No actions beyond base class
ErrLineLog::~ErrLineLog()
{
// There can be only one, and it should be this one.
assert( ErrLog::_implementation() == this );
}
//-------------
//-- Actions --
//-------------
ErrStream&
ErrLineLog::doMsg( ErrLog::Severity severity,
const char* facility,
int code )
{
// Use base class to select stream, then write info
ErrStream& theStream = ErrStdLog::doMsg(severity,facility,code);
ostream& toWrite( theStream ); // Cast to ostream for writing;
// facility is the filename with the long path removed
char shortName[100];
char *fromLastSlash = (char*) strrchr(facility, '/');
if(fromLastSlash != NULL)
{
strncpy(shortName, &fromLastSlash[1], 100);
}
else
{
strncpy(shortName, facility, 100);
}
toWrite << shortName;
if ( code != 0 ) {
toWrite << " [" << code << "]";
}
toWrite << ":";
return theStream;
}