File indexing completed on 2025-02-21 10:00:33
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef GAUDIKERNEL_MESSAGE_H
0012 #define GAUDIKERNEL_MESSAGE_H
0013
0014 #include "GaudiKernel/EventContext.h"
0015 #include "GaudiKernel/Kernel.h" // for GAUDI_API
0016 #include <iostream>
0017 #include <string>
0018
0019
0020
0021
0022
0023
0024
0025
0026 class GAUDI_API Message final {
0027 public:
0028
0029 Message() = default;
0030
0031
0032 Message( const char* src, int type, const char* msg );
0033
0034
0035 Message( std::string src, int type, std::string msg );
0036
0037
0038 ~Message() = default;
0039
0040
0041 const std::string& getMessage() const { return m_message; }
0042
0043
0044 void setMessage( std::string msg ) { m_message = std::move( msg ); }
0045
0046
0047 int getType() const { return m_type; }
0048
0049
0050 void setType( int msg_type ) { m_type = msg_type; }
0051
0052
0053 const std::string& getSource() const { return m_source; }
0054
0055
0056 void setSource( std::string_view src ) { m_source = src; }
0057
0058
0059
0060 EventContext::ContextID_t getEventSlot() const { return m_ecSlot; }
0061 EventContext::ContextEvt_t getEventNumber() const { return m_ecEvt; }
0062 EventIDBase getEventID() const { return m_ecEvtId; }
0063
0064
0065
0066 const std::string& getFormat() const { return m_format; }
0067
0068
0069 static const std::string getDefaultFormat() { return DEFAULT_FORMAT; }
0070
0071
0072 void setFormat( std::string msg ) const;
0073
0074
0075 const std::string& getTimeFormat() const { return m_time_format; }
0076
0077
0078 static const std::string getDefaultTimeFormat() { return DEFAULT_TIME_FORMAT; }
0079
0080
0081 void setTimeFormat( std::string timeFormat ) const;
0082
0083
0084 friend bool operator<( const Message& lhs, const Message& rhs );
0085
0086
0087 friend std::ostream& operator<<( std::ostream& stream, const Message& msg );
0088
0089
0090 friend bool operator==( const Message& a, const Message& b );
0091
0092 private:
0093
0094 void invalidFormat() const;
0095
0096
0097 void makeFormattedMsg( const std::string& format ) const;
0098
0099
0100 void decodeFormat( const std::string& format ) const;
0101
0102
0103 void sizeField( const std::string& text, bool middle = false ) const;
0104
0105
0106 void setWidth( const std::string& formatArg ) const;
0107
0108 std::string m_message;
0109 std::string m_source{ "UNKNOWN" };
0110 int m_type{ 0 };
0111 mutable std::string m_format{ DEFAULT_FORMAT };
0112 mutable std::string m_time_format{ DEFAULT_TIME_FORMAT };
0113 mutable std::string m_formatted_msg;
0114 mutable char m_fill{ ' ' };
0115 mutable int m_width{ 0 };
0116 mutable bool m_left{ true };
0117
0118
0119
0120 EventContext::ContextID_t m_ecSlot;
0121 EventContext::ContextEvt_t m_ecEvt;
0122 EventIDBase m_ecEvtId;
0123 pthread_t m_ecThrd;
0124
0125
0126
0127
0128
0129 static const char FORMAT_PREFIX = '%';
0130
0131
0132 static const char JUSTIFY_LEFT = 'L';
0133
0134
0135 static const char JUSTIFY_RIGHT = 'R';
0136
0137
0138 static const char MESSAGE = 'M';
0139
0140
0141 static const char TYPE = 'T';
0142
0143
0144 static const char TIME = 't';
0145
0146
0147 static const char UTIME = 'u';
0148
0149
0150 static const char SOURCE = 'S';
0151
0152
0153 static const char COMP = 'C';
0154
0155
0156 static const char SLOT = 's';
0157
0158
0159 static const char EVTNUM = 'e';
0160
0161
0162 static const char THREAD = 'X';
0163
0164
0165 static const char EVENTID = 'E';
0166
0167
0168 static const char FILL = 'F';
0169
0170
0171 static const char WIDTH = 'W';
0172
0173
0174
0175 static constexpr const char* DEFAULT_FORMAT = "% F%18W%S%7W%R%T %0W%M";
0176
0177
0178 static constexpr const char* DEFAULT_TIME_FORMAT = "%Y-%m-%d %H:%M:%S,%f";
0179 };
0180
0181 #endif