ealogger
ealogger is a c++ library that provides a blazing fast and easy to use logging mechanism
logmessage.h
1 // ealogger is a simple, asynchronous and powerful logger library for c++
2 // Copyright 2013 - 2016 Christian Rapp
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef LOGMESSAGE_H
17 #define LOGMESSAGE_H
18 
19 #include <chrono>
20 #include <ctime>
21 #include <string>
22 #include <vector>
23 
24 #include <ealogger/global.h>
25 
26 namespace ealogger
27 {
42 struct LogMessage {
43 public:
47  enum LOGTYPE {
48  DEFAULT = 0,
51  };
52 
56  typedef std::vector<std::string>::const_iterator msg_vec_it;
57 
68  LogMessage(ealogger::constants::LOG_LEVEL severity, std::string message,
69  LOGTYPE log_type, std::string file, int lnumber, std::string func)
70  : severity(severity),
71  message(std::move(message)),
72  log_type(log_type),
73  call_file(std::move(file)),
74  call_file_line_num(lnumber),
75  call_func(std::move(func))
76  {
77  this->t = std::chrono::system_clock::now();
78  }
90  std::vector<std::string> message_vec, LOGTYPE log_type,
91  std::string file, int lnumber, std::string func)
92  : severity(severity),
93  message_vec(std::move(message_vec)),
94  log_type(log_type),
95  call_file(std::move(file)),
96  call_file_line_num(lnumber),
97  call_func(std::move(func))
98  {
99  this->t = std::chrono::system_clock::now();
100  this->message = "";
101  }
102 
107  std::time_t get_timepoint()
108  {
109  return std::chrono::system_clock::to_time_t(this->t);
110  }
115  ealogger::constants::LOG_LEVEL get_severity() { return this->severity; }
120  std::string get_message() { return this->message; }
125  LOGTYPE get_log_type() { return this->log_type; }
130  msg_vec_it get_msg_vec_begin() { return this->message_vec.cbegin(); }
135  msg_vec_it get_msg_vec_end() { return this->message_vec.cend(); }
140  std::string get_call_file() { return this->call_file; }
145  int get_call_file_line() { return this->call_file_line_num; }
150  std::string get_call_func() { return this->call_func; }
151 private:
153  std::chrono::system_clock::time_point t;
157  std::string message;
159  std::vector<std::string> message_vec;
161  LOGTYPE log_type;
162  std::string
163  call_file;
164  int call_file_line_num;
165  std::string call_func;
166 };
167 }
168 
169 #endif // LOGMESSAGE_H
std::string get_call_file()
Return file from where this log message was issued.
Definition: logmessage.h:140
std::string get_message()
Get the log message.
Definition: logmessage.h:120
LOGTYPE
The LOGTYPE enum stands for the LogMessage type.
Definition: logmessage.h:47
msg_vec_it get_msg_vec_end()
Returns a constant iterator pointing the end of the message vector.
Definition: logmessage.h:135
ealogger::constants::LOG_LEVEL get_severity()
Returns the severity of the message.
Definition: logmessage.h:115
Definition: logmessage.h:49
Global ealogger constants.
Main namespace for ealogger.
Definition: conversion_pattern.h:28
std::vector< std::string >::const_iterator msg_vec_it
A constant iterator typedef that is internally used.
Definition: logmessage.h:56
int get_call_file_line()
Return line number in file from where this log message was issued.
Definition: logmessage.h:145
LogMessage(ealogger::constants::LOG_LEVEL severity, std::vector< std::string > message_vec, LOGTYPE log_type, std::string file, int lnumber, std::string func)
Initializes a log message object with a vector of message strings.
Definition: logmessage.h:89
Definition: logmessage.h:48
LogMessage(ealogger::constants::LOG_LEVEL severity, std::string message, LOGTYPE log_type, std::string file, int lnumber, std::string func)
Initializes a log message object.
Definition: logmessage.h:68
std::time_t get_timepoint()
Return the time_point when this message was created.
Definition: logmessage.h:107
Log message struct.
Definition: logmessage.h:42
msg_vec_it get_msg_vec_begin()
Returns a constant iterator pointing the begin of the message vector.
Definition: logmessage.h:130
LOGTYPE get_log_type()
Get the log message type.
Definition: logmessage.h:125
std::string get_call_func()
Return function name from where this log message was issued.
Definition: logmessage.h:150
LOG_LEVEL
An enumaration representing the supported loglevels.
Definition: global.h:58