Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JDB::JLoggerMessage Struct Reference

Auxiliary data structure for logger message. More...

#include <JLoggerMessage.hh>

Public Member Functions

 JLoggerMessage ()
 Default constructor.
 
 JLoggerMessage (const JDatalogString &datalog)
 Copy constructor.
 
bool match (const JLoggerMessage &message) const
 Get match.
 
bool hasTime () const
 Check if message has date and time.
 
long int getTime () const
 Get UTC time.
 

Public Attributes

std::string file_name
 
std::string tag
 
std::string process
 
JDateAndTime datim
 
std::string ip
 
std::string nickname
 
std::string fullname
 
std::string level
 
std::string data
 

Friends

std::istream & operator>> (std::istream &in, JLoggerMessage &object)
 Read message from input.
 
std::ostream & operator<< (std::ostream &out, const JLoggerMessage &object)
 Write message to output.
 

Detailed Description

Auxiliary data structure for logger message.

Definition at line 36 of file JLoggerMessage.hh.

Constructor & Destructor Documentation

◆ JLoggerMessage() [1/2]

JDB::JLoggerMessage::JLoggerMessage ( )
inline

Default constructor.

Definition at line 40 of file JLoggerMessage.hh.

41 {}

◆ JLoggerMessage() [2/2]

JDB::JLoggerMessage::JLoggerMessage ( const JDatalogString & datalog)
inline

Copy constructor.

Parameters
datalogdata log

Definition at line 49 of file JLoggerMessage.hh.

50 {
51 using namespace std;
52 using namespace JPP;
53 using namespace KM3NETDAQ;
54
55 if (datalog.source == MESSAGE_TAG) {
56
57 this->tag = datalog.source;
58
59 istringstream is(datalog.data);
60
61 if (is >> this->datim >> this->ip >> this->nickname >> this->level) {
62
63 this->datim.set(datalog.utc / 1000, (float) (datalog.utc%1000) * 1.0e-3, true);
64
65 while (is.peek() != EOF && isspace((char) is.peek())) { is.ignore(1); }
66
67 getline(is, this->data);
68
69 } else {
70
71 THROW(JParseError, "Invalid string " << datalog.source << " " << datalog.data);
72 }
73
74 } else {
75
76 THROW(JParseError, "Invalid source " << datalog.source);
77 }
78 }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Exception for parsing value.
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition JString.hh:478
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
void set(const bool utc=false)
Set to current local time.

Member Function Documentation

◆ match()

bool JDB::JLoggerMessage::match ( const JLoggerMessage & message) const
inline

Get match.

Parameters
messagemessage
Returns
true if message matches; else false

Definition at line 87 of file JLoggerMessage.hh.

88 {
89 using namespace std;
90
91 if (!message.tag .empty() && message.tag != tag) { return false; }
92 if (!message.process .empty() && message.process != process) { return false; }
93 if (!message.nickname.empty() && message.nickname != nickname) { return false; }
94 if (!message.ip .empty() && message.ip != ip) { return false; }
95 if (!message.fullname.empty() && message.fullname != fullname) { return false; }
96 if (!message.level .empty() && message.level != level) { return false; }
97 if (!message.data .empty() && !regex_match(data, regex(message.data))) { return false; }
98
99 return true;
100 }

◆ hasTime()

bool JDB::JLoggerMessage::hasTime ( ) const
inline

Check if message has date and time.

Returns
true if messages has date and time; else false

Definition at line 108 of file JLoggerMessage.hh.

109 {
110 using namespace JPP;
111
112 return (tag != DISPTAG_Born.toString() &&
113 tag != DISPTAG_Died.toString());
114 }

◆ getTime()

long int JDB::JLoggerMessage::getTime ( ) const
inline

Get UTC time.

Returns
time [ms]

Definition at line 122 of file JLoggerMessage.hh.

123 {
124 return (long int) 1000 * (long int) datim.getTime() + (long int) 500;
125 }
time_t getTime() const
time

Friends And Related Symbol Documentation

◆ operator>>

std::istream & operator>> ( std::istream & in,
JLoggerMessage & object )
friend

Read message from input.

Parameters
ininput stream
objectmessage
Returns
input stream

Definition at line 135 of file JLoggerMessage.hh.

136 {
137 using namespace JPP;
138
139 object = JLoggerMessage();
140
141 in >> object.file_name
142 >> object.tag
143 >> object.process;
144
145 if (object.tag != DISPTAG_Born.toString() &&
146 object.tag != DISPTAG_Died.toString()) {
147
148 in >> object.datim
149 >> object.ip
150 >> object.nickname
151 >> object.level;
152
153 while (in.peek() != EOF && isspace((char) in.peek())) { in.ignore(1); }
154
155 return getline(in, object.data);
156
157 } else {
158
159 return in >> object.fullname;
160 }
161 }
JLoggerMessage()
Default constructor.

◆ operator<<

std::ostream & operator<< ( std::ostream & out,
const JLoggerMessage & object )
friend

Write message to output.

Parameters
outoutput stream
objectmessage
Returns
output stream

Definition at line 171 of file JLoggerMessage.hh.

172 {
173 using namespace std;
174 using namespace JPP;
175
176 if (object.tag != DISPTAG_Born.toString() &&
177 object.tag != DISPTAG_Died.toString()) {
178
179 out << LEFT(8)
180 << object.tag << ' ' << right;
181 out << object.datim << ' ';
182 //out << object.getTime() << ' ';
183 //out << object.ip << ' ';
184 out << object.nickname << ' ';
185 //out << object.level << ' ';
186 out << object.data;
187
188 } else {
189
190 out << object.tag << ' ';
191 //out << object.process << ' ';
192 out << object.fullname;
193 }
194
195 return out;
196 }
Auxiliary data structure for alignment of data.
Definition JManip.hh:266

Member Data Documentation

◆ file_name

std::string JDB::JLoggerMessage::file_name

Definition at line 199 of file JLoggerMessage.hh.

◆ tag

std::string JDB::JLoggerMessage::tag

Definition at line 200 of file JLoggerMessage.hh.

◆ process

std::string JDB::JLoggerMessage::process

Definition at line 201 of file JLoggerMessage.hh.

◆ datim

JDateAndTime JDB::JLoggerMessage::datim

Definition at line 202 of file JLoggerMessage.hh.

◆ ip

std::string JDB::JLoggerMessage::ip

Definition at line 203 of file JLoggerMessage.hh.

◆ nickname

std::string JDB::JLoggerMessage::nickname

Definition at line 204 of file JLoggerMessage.hh.

◆ fullname

std::string JDB::JLoggerMessage::fullname

Definition at line 205 of file JLoggerMessage.hh.

◆ level

std::string JDB::JLoggerMessage::level

Definition at line 206 of file JLoggerMessage.hh.

◆ data

std::string JDB::JLoggerMessage::data

Definition at line 207 of file JLoggerMessage.hh.


The documentation for this struct was generated from the following file: