The Gaudi Framework  v33r0 (d5ea422b)
Message.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 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 #ifndef GAUDIKERNEL_MESSAGE_H
12 #define GAUDIKERNEL_MESSAGE_H
13 
15 #include "GaudiKernel/Kernel.h" // for GAUDI_API
17 #include <iostream>
18 #include <string>
19 
27 class GAUDI_API Message final {
28 public:
30  Message() = default;
31 
33  Message( const char* src, int type, const char* msg );
34 
36  Message( std::string src, int type, std::string msg );
37 
39  ~Message() = default;
40 
42  const std::string& getMessage() const;
43 
45  void setMessage( std::string msg );
46 
48  int getType() const;
49 
51  void setType( int msg_type );
52 
54  const std::string& getSource() const;
55 
57  void setSource( std::string src );
58 
60  const std::string& getFormat() const;
61 
63  static const std::string getDefaultFormat();
64 
66  void setFormat( std::string msg ) const;
67 
69  const std::string& getTimeFormat() const;
70 
72  static const std::string getDefaultTimeFormat();
73 
75  void setTimeFormat( std::string timeFormat ) const;
76 
78  bool operator<( const Message& test );
79 
81  friend std::ostream& operator<<( std::ostream& stream, const Message& msg );
82 
84  friend bool operator==( const Message& a, const Message& b );
85 
86 private:
88  void invalidFormat() const;
89 
91  void makeFormattedMsg( const std::string& format ) const;
92 
94  void decodeFormat( const std::string& format ) const;
95 
97  void sizeField( const std::string& text ) const;
98 
100  void setWidth( const std::string& formatArg ) const;
101 
103  std::string m_source{"UNKNOWN"};
104  int m_type{0};
105  mutable std::string m_format{DEFAULT_FORMAT};
106  mutable std::string m_time_format{DEFAULT_TIME_FORMAT};
108  mutable char m_fill{' '};
109  mutable int m_width{0};
110  mutable bool m_left{true};
111 
117  pthread_t m_ecThrd{pthread_self()};
118 
119 
122  static const char FORMAT_PREFIX = '%';
124 
126  static const char JUSTIFY_LEFT = 'L';
127 
129  static const char JUSTIFY_RIGHT = 'R';
130 
132  static const char MESSAGE = 'M';
133 
135  static const char TYPE = 'T';
136 
138  static const char TIME = 't';
139 
141  static const char UTIME = 'u';
142 
144  static const char SOURCE = 'S';
145 
147  static const char SLOT = 's';
148 
150  static const char EVTNUM = 'e';
151 
153  static const char THREAD = 'X';
154 
156  static const char EVENTID = 'E';
157 
159  static const char FILL = 'F';
160 
162  static const char WIDTH = 'W';
164 
166  static constexpr const char* DEFAULT_FORMAT = "% F%18W%S%7W%R%T %0W%M";
167 
169  static constexpr const char* DEFAULT_TIME_FORMAT = "%Y-%m-%d %H:%M:%S,%f";
170 };
171 
174 
176 GAUDI_API bool operator==( const Message& a, const Message& b );
177 
178 #endif
ContextID_t slot() const
Definition: EventContext.h:51
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
std::string m_formatted_msg
Formatted message.
Definition: Message.h:107
ContextEvt_t evt() const
Definition: EventContext.h:50
std::string m_message
The message text.
Definition: Message.h:102
size_t ContextID_t
Definition: EventContext.h:36
STL class.
GAUDI_API const EventContext & currentContext()
bool operator<(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:255
GAUDI_API std::ostream & operator<<(std::ostream &stream, const Message &msg)
Insert the message into a stream.
Definition: Message.cpp:104
The Message class.
Definition: Message.h:27
GAUDI_API bool operator==(const Message &a, const Message &b)
Insert the message into a stream.
Definition: Message.cpp:126
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
Definition: EventIDBase.h:66
#define GAUDI_API
Definition: Kernel.h:81
STL class.
const EventIDBase & eventID() const
Definition: EventContext.h:55