33 inline std::string formattedTime (
const std::string &fmt,
bool universal =
false )
46 m_message(
"" ), m_source(
"UNKNOWN" ), m_format( DEFAULT_FORMAT ),
47 m_time_format(DEFAULT_TIME_FORMAT), m_type(
NIL ),
48 m_fill(
' ' ), m_width( 0 ), m_left( true )
59 m_message( msg ), m_source( src ), m_format( DEFAULT_FORMAT ),
60 m_time_format(DEFAULT_TIME_FORMAT), m_type( type ),
61 m_fill(
' ' ), m_width( 0 ), m_left( true )
72 m_message( msg ), m_source( src ), m_format( DEFAULT_FORMAT ),
73 m_time_format(DEFAULT_TIME_FORMAT), m_type( type ),
74 m_fill(
' ' ), m_width( 0 ), m_left( true )
215 if ( format.empty() )
253 if ( timeFormat.empty() )
268 std::string::const_iterator
i = format.begin();
269 while( i != format.end() ) {
276 if ( i == format.end() )
break;
280 std::string this_format =
"";
289 if ( i == format.end() ) {
307 if ( ! format.empty() ) {
308 const char FORMAT_TYPE = format[ format.length() - 1 ];
309 const std::string FORMAT_PARAM = format.substr( 0, format.length() - 1 );
313 switch( FORMAT_TYPE ) {
315 if ( FORMAT_PARAM.length() == 1 ) {
324 const std::string& timeStr = formattedTime (
m_time_format ) ;
331 const std::string& timeStr = formattedTime (
m_time_format,
true ) ;
346 #define SET(x) case x: level=#x; break
354 case ALWAYS: level=
"SUCCESS";
break;
396 bool only_digits =
true;
397 for( std::string::const_iterator
i = formatArg.begin();
398 i != formatArg.end();
i++ ) {
400 if ( ! isdigit( *
i ) ) {
410 m_width = atoi( formatArg.c_str() );
412 m_width = atoi( formatArg.data() );
427 if (
m_width == 0 ||
m_width == static_cast<int>( text.length() ) ) {
433 if (
m_width < static_cast<int>( text.length() ) ) {
434 newText = text.substr( 0,
m_width );
435 for (
int i = 0, j = newText.length()-1; i < 3 && j >= 0;
i++, j-- )
443 newText.replace( newText.begin(), newText.begin() + text.length(),
444 text.begin(), text.end() );
446 newText.replace( newText.end() - text.length(), newText.end(),
447 text.begin(), text.end() );
static const char TYPE
The character used to indicate that the message type should be printed.
bool m_left
Justification.
static const char MESSAGE
The character used to indicate that the message should be printed.
const std::string & getFormat() const
Get the format string.
char m_fill
The current fill character.
static const char JUSTIFY_LEFT
The character used to indicate start of left text justification.
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
std::string m_formatted_msg
Formatted message.
std::string m_time_format
Time format string.
void decodeFormat(const std::string &format) const
Decode format.
void setMessage(const std::string &msg)
Set the message string.
void setWidth(const std::string &formatArg) const
Set the width of a stream.
bool operator<(const Message &test)
Needed to build maps.
bool operator==(const Message &a, const Message &b)
Insert the message into a stream.
static Time current(void)
Returns the current time.
std::string m_message
The message.
void setType(int msg_type)
Set the message type.
void setTimeFormat(const std::string &timeFormat) const
Set the time format string.
static const char * DEFAULT_FORMAT
The default message format.
int getType() const
Get the message type.
Message()
Default constructor.
void invalidFormat() const
Called when an invalid format string is encountered.
void setSource(const std::string &src)
Set the message source.
static const std::string getDefaultTimeFormat()
Get the default time format string.
std::ostream & operator<<(std::ostream &stream, const Message &msg)
Insert the message into a stream.
static const char * DEFAULT_TIME_FORMAT
The default time format.
static const std::string getDefaultFormat()
Get the default format string.
int m_width
The current field width.
static const char TIME
The character used to indicate that the message timestamp should be printed.
std::string m_format
The format string.
static const char JUSTIFY_RIGHT
The character used to indicate start of right text justification.
static const char UTIME
The character used to indicate that the message timestamp should be printed in UTC time...
static const char FILL
The character used to indicate that the previous character is to be used for padding out fields if th...
void makeFormattedMsg(const std::string &format) const
Format the message.
void sizeField(const std::string &text) const
Truncate or pad the output string to the field width as necessary.
const std::string & getSource() const
Get the message source.
const std::string & getTimeFormat() const
Get the time format string.
static const char FORMAT_PREFIX
The character used to prefix formatting commands.
std::string m_source
The source.
static const char WIDTH
The character used to indicate that the previous decimal characters should be taken as the field widt...
static const char SOURCE
The character used to indicate that the message source should be printed.
void setFormat(const std::string &msg) const
Set the format string.
std::string format(bool local, std::string spec="%c") const
Format the time using strftime.
const std::string & getMessage() const
Get the message string.