28 inline std::string formattedTime(
const std::string& fmt,
bool universal =
false ) {
65 msg.makeFormattedMsg( msg.m_format );
66 stream << msg.m_formatted_msg;
125 while ( i !=
format.end() ) {
131 if ( i ==
format.end() )
break;
135 std::string this_format;
143 if ( i ==
format.end() ) {
162 const std::string FORMAT_PARAM =
format.substr( 0,
format.length() - 1 );
166 switch ( FORMAT_TYPE ) {
168 if ( FORMAT_PARAM.length() == 1 ) {
183 std::ostringstream ost;
185 ost <<
"0x" << std::hex <<
m_ecThrd;
186 const std::string& thrStr( ost.str() );
191 std::ostringstream ost;
197 std::ostringstream ost;
203 std::ostringstream ost;
281 constexpr struct all_digit_t {
282 template <
typename C>
283 bool operator()(
const C& c )
const {
284 return std::all_of( std::begin( c ), std::end( c ),
285 [](
typename C::const_reference i ) {
return isdigit( i ); } );
292 if ( all_digits( formatArg ) )
293 m_width = std::stoi( formatArg );
307 if (
m_width == 0 ||
m_width ==
static_cast<int>( text.length() ) ) {
310 const size_t width =
static_cast<size_t>(
m_width );
312 if ( width < text.length() ) {
313 if ( middle && width > 4 ) {
316 const size_t iDot = text.rfind(
'.' );
317 if ( iDot != std::string::npos && width > text.length() - iDot + 3 ) {
321 iTrunc = text.length() - width / 2;
323 const size_t taillength = text.length() - iTrunc;
324 const size_t frontlength = width - taillength - 3;
325 newText.reserve( width );
326 newText.append( text, 0, frontlength );
327 newText.append( 3,
'.' );
328 newText.append( text, iTrunc );
331 newText = text.substr( 0,
m_width );
332 for (
int i = 0, j = newText.length() - 1; i < 3 && j >= 0; ++i, --j ) newText[j] =
'.';
339 newText.replace( newText.begin(), newText.begin() + text.length(), text.begin(), text.end() );
341 newText.replace( newText.end() - text.length(), newText.end(), text.begin(), text.end() );
bool operator==(const Message &a, const Message &b)
std::ostream & operator<<(std::ostream &stream, const Message &msg)
bool operator<(const Message &lhs, const Message &rhs)
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
This class represents an entry point to all the event specific data.
static constexpr ContextEvt_t INVALID_CONTEXT_EVT
static constexpr ContextID_t INVALID_CONTEXT_ID
std::string format(bool local, std::string spec="%c") const
Format the time using strftime.
static Time current()
Returns the current time.
void sizeField(const std::string &text, bool middle=false) const
Truncate or pad the output string to the field width. If middle is true, cut the central part,...
static const char SLOT
The character used to indicate that the slot number should be printed.
void setTimeFormat(std::string timeFormat) const
Set the time format string.
std::string m_message
The message text.
static constexpr const char * DEFAULT_FORMAT
The default message format.
std::string m_formatted_msg
Formatted message.
bool m_left
The message alignment.
void decodeFormat(const std::string &format) const
Decode format.
EventIDBase m_ecEvtId
Full event ID.
int m_width
Current field width.
void invalidFormat() const
Called when an invalid format string is encountered.
Message()=default
Default constructor.
EventContext::ContextID_t m_ecSlot
Event slot.
static const char THREAD
The character used to indicate that the thread ID should be printed.
int m_type
The message type/level.
static const char UTIME
The character used to indicate that the message timestamp should be printed in UTC time.
static const char EVTNUM
The character used to indicate that the event number should be printed.
std::string m_source
The message source.
static const char SOURCE
The character used to indicate that the message source should be printed.
static const char COMP
The character used to indicate that the message source should be printed, focus on the component.
static const char TIME
The character used to indicate that the message timestamp should be printed.
static const char JUSTIFY_LEFT
The character used to indicate start of left text justification.
static const char EVENTID
The character used to indicate that the full event ID should be printed.
static const char FORMAT_PREFIX
The character used to prefix formatting commands.
static const char WIDTH
The character used to indicate that the previous decimal characters should be taken as the field widt...
static const char TYPE
The character used to indicate that the message type should be printed.
std::string m_time_format
Time format string.
void setFormat(std::string msg) const
Set the format string.
pthread_t m_ecThrd
Thread ID.
static const char JUSTIFY_RIGHT
The character used to indicate start of right text justification.
static constexpr const char * DEFAULT_TIME_FORMAT
The default time format (accepts strftime formatters plus %f for milliseconds).
void makeFormattedMsg(const std::string &format) const
Format the message.
char m_fill
Current fill character.
EventContext::ContextEvt_t m_ecEvt
Event number.
static const char FILL
The character used to indicate that the previous character is used to pad fields if the text is not l...
std::string m_format
The format string.
void setWidth(const std::string &formatArg) const
Set the width of a stream.
static const char MESSAGE
The character used to indicate that the message should be printed.
GAUDI_API const EventContext & currentContext()
Print levels enumeration.