The Gaudi Framework  master (82fdf313)
Loading...
Searching...
No Matches
Message.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11#pragma once
12
14#include <GaudiKernel/Kernel.h> // for GAUDI_API
15#include <iostream>
16#include <string>
17
25class GAUDI_API Message final {
26public:
28 Message() = default;
29
31 Message( const char* src, int type, const char* msg );
32
34 Message( std::string src, int type, std::string msg );
35
37 ~Message() = default;
38
40 const std::string& getMessage() const { return m_message; }
41
43 void setMessage( std::string msg ) { m_message = std::move( msg ); }
44
46 int getType() const { return m_type; }
47
49 void setType( int msg_type ) { m_type = msg_type; }
50
52 const std::string& getSource() const { return m_source; }
53
55 void setSource( std::string_view src ) { m_source = src; }
56
61 const EventIDBase& getEventID() const { return m_ecEvtId; }
63
65 const std::string& getFormat() const { return m_format; }
66
68 static const std::string getDefaultFormat() { return DEFAULT_FORMAT; }
69
71 void setFormat( std::string msg ) const;
72
74 const std::string& getTimeFormat() const { return m_time_format; }
75
77 static const std::string getDefaultTimeFormat() { return DEFAULT_TIME_FORMAT; }
78
80 void setTimeFormat( std::string timeFormat ) const;
81
83 friend bool operator<( const Message& lhs, const Message& rhs );
84
86 friend std::ostream& operator<<( std::ostream& stream, const Message& msg );
87
89 friend bool operator==( const Message& a, const Message& b );
90
91private:
93 void invalidFormat() const;
94
96 void makeFormattedMsg( const std::string& format ) const;
97
99 void decodeFormat( const std::string& format ) const;
100
102 void sizeField( const std::string& text, bool middle = false ) const;
103
105 void setWidth( const std::string& formatArg ) const;
106
107 std::string m_message;
108 std::string m_source{ "UNKNOWN" };
109 int m_type{ 0 };
110 mutable std::string m_format{ DEFAULT_FORMAT };
111 mutable std::string m_time_format{ DEFAULT_TIME_FORMAT };
112 mutable std::string m_formatted_msg;
113 mutable char m_fill{ ' ' };
114 mutable int m_width{ 0 };
115 mutable bool m_left{ true };
116
122 pthread_t m_ecThrd{};
124
127
128 static const char FORMAT_PREFIX = '%';
129
131 static const char JUSTIFY_LEFT = 'L';
132
134 static const char JUSTIFY_RIGHT = 'R';
135
137 static const char MESSAGE = 'M';
138
140 static const char TYPE = 'T';
141
143 static const char TIME = 't';
144
146 static const char UTIME = 'u';
147
149 static const char SOURCE = 'S';
150
152 static const char COMP = 'C';
153
155 static const char SLOT = 's';
156
158 static const char EVTNUM = 'e';
159
161 static const char THREAD = 'X';
162
164 static const char EVENTID = 'E';
165
167 static const char FILL = 'F';
168
170 static const char WIDTH = 'W';
172
174 static constexpr const char* DEFAULT_FORMAT = "% F%18W%S%7W%R%T %0W%M";
175
177 static constexpr const char* DEFAULT_TIME_FORMAT = "%Y-%m-%d %H:%M:%S,%f";
178};
std::ostream & operator<<(std::ostream &s, AlgsExecutionStates::State x)
Streaming of State values.
bool operator==(const GaudiUtils::Allocator< T1 > &, const GaudiUtils::Allocator< T2 > &)
Definition Allocator.h:224
#define GAUDI_API
Definition Kernel.h:49
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition MsgStream.cpp:93
bool operator<(backwards_compatibility_hack_time_timespan, backwards_compatibility_hack_time_timespan)
Definition Time.icpp:219
static constexpr ContextEvt_t INVALID_CONTEXT_EVT
size_t ContextID_t
static constexpr ContextID_t INVALID_CONTEXT_ID
size_t ContextEvt_t
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
Definition EventIDBase.h:65
The Message class.
Definition Message.h:25
~Message()=default
Default destructor.
static const char SLOT
The character used to indicate that the slot number should be printed.
Definition Message.h:155
const std::string & getMessage() const
Get the message string.
Definition Message.h:40
std::string m_message
The message text.
Definition Message.h:107
static const std::string getDefaultTimeFormat()
Get the default time format string.
Definition Message.h:77
static constexpr const char * DEFAULT_FORMAT
The default message format.
Definition Message.h:174
std::string m_formatted_msg
Formatted message.
Definition Message.h:112
bool m_left
The message alignment.
Definition Message.h:115
EventIDBase m_ecEvtId
Full event ID.
Definition Message.h:121
int m_width
Current field width.
Definition Message.h:114
EventContext::ContextEvt_t getEventNumber() const
Definition Message.h:60
static const std::string getDefaultFormat()
Get the default format string.
Definition Message.h:68
void setSource(std::string_view src)
Set the message source.
Definition Message.h:55
Message()=default
Default constructor.
EventContext::ContextID_t m_ecSlot
Event slot.
Definition Message.h:119
const std::string & getFormat() const
Get the format string.
Definition Message.h:65
static const char THREAD
The character used to indicate that the thread ID should be printed.
Definition Message.h:161
int m_type
The message type/level.
Definition Message.h:109
static const char UTIME
The character used to indicate that the message timestamp should be printed in UTC time.
Definition Message.h:146
static const char EVTNUM
The character used to indicate that the event number should be printed.
Definition Message.h:158
std::string m_source
The message source.
Definition Message.h:108
const std::string & getSource() const
Get the message source.
Definition Message.h:52
static const char SOURCE
The character used to indicate that the message source should be printed.
Definition Message.h:149
void setMessage(std::string msg)
Set the message string.
Definition Message.h:43
static const char COMP
The character used to indicate that the message source should be printed, focus on the component.
Definition Message.h:152
const EventIDBase & getEventID() const
Definition Message.h:61
int getType() const
Get the message type.
Definition Message.h:46
static const char TIME
The character used to indicate that the message timestamp should be printed.
Definition Message.h:143
static const char JUSTIFY_LEFT
The character used to indicate start of left text justification.
Definition Message.h:131
static const char EVENTID
The character used to indicate that the full event ID should be printed.
Definition Message.h:164
static const char FORMAT_PREFIX
The character used to prefix formatting commands.
Definition Message.h:128
void setType(int msg_type)
Set the message type.
Definition Message.h:49
static const char WIDTH
The character used to indicate that the previous decimal characters should be taken as the field widt...
Definition Message.h:170
static const char TYPE
The character used to indicate that the message type should be printed.
Definition Message.h:140
std::string m_time_format
Time format string.
Definition Message.h:111
pthread_t m_ecThrd
Thread ID.
Definition Message.h:122
static const char JUSTIFY_RIGHT
The character used to indicate start of right text justification.
Definition Message.h:134
static constexpr const char * DEFAULT_TIME_FORMAT
The default time format (accepts strftime formatters plus %f for milliseconds).
Definition Message.h:177
char m_fill
Current fill character.
Definition Message.h:113
EventContext::ContextEvt_t m_ecEvt
Event number.
Definition Message.h:120
static const char FILL
The character used to indicate that the previous character is used to pad fields if the text is not l...
Definition Message.h:167
std::string m_format
The format string.
Definition Message.h:110
EventContext::ContextID_t getEventSlot() const
Definition Message.h:59
const std::string & getTimeFormat() const
Get the time format string.
Definition Message.h:74
static const char MESSAGE
The character used to indicate that the message should be printed.
Definition Message.h:137