28 inline std::string formattedTime(
const std::string& fmt,
bool universal =
false ) {
65 msg.makeFormattedMsg( msg.m_format );
66 stream << msg.m_formatted_msg;
135 std::string this_format;
166 switch ( FORMAT_TYPE ) {
168 if ( FORMAT_PARAM.
length() == 1 ) {
183 std::ostringstream ost;
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 {
285 [](
typename C::const_reference i ) {
return isdigit( i ); } );
292 if ( all_digits( formatArg ) )
293 m_width = std::stoi( formatArg );
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(
'.' );
321 iTrunc = text.
length() - width / 2;
323 const size_t taillength = text.
length() - iTrunc;
324 const size_t frontlength = width - taillength - 3;
326 newText.
append( text, 0, frontlength );
328 newText.
append( text, iTrunc );
332 for (
int i = 0, j = newText.
length() - 1; i < 3 && j >= 0; ++i, --j ) newText[j] =
'.';
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
strong_ordering operator(const error_code &__lhs, const error_code &__rhs) noexcept
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
constexpr _OI move(_II __first, _II __last, _OI __result)
constexpr bool all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
basic_string< char > string
ios_base & hex(ios_base &__base)
bool isdigit(_CharT __c, const locale &__loc)
constexpr auto begin(_Container &__cont) -> decltype(__cont.begin())
constexpr auto end(_Container &__cont) -> decltype(__cont.end())
__string_type str() const
basic_string substr(size_type __pos=0, size_type __n=npos) const
size_type rfind(_CharT __c, size_type __pos=npos) const noexcept
_If_sv< _Tp, basic_string & > replace(const_iterator __i1, const_iterator __i2, const _Tp &__svt)
size_type length() const noexcept
basic_string & append(_InputIterator __first, _InputIterator __last)
bool empty() const noexcept
static const size_type npos
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.
friend bool operator==(const Message &a, const Message &b)
Insert the message into a stream.
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.