- Aldebaran documentation |
- C++ Libraries |
- index

libqicore-api 2.8.7.4

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
logmessage.hpp
Go to the documentation of this file.
1 /*
2 ** Author(s):
3 ** - Herve Cuche <hcuche@aldebaran-robotics.com>
4 ** - Matthieu Nottale <mnottale@aldebaran-robotics.com>
5 **
6 ** Copyright (C) 2013 Aldebaran Robotics
7 */
8
9 #ifndef QICORE_LOG_HPP_
10 #define QICORE_LOG_HPP_
11
12 #include <qi/log.hpp>
13 #include <qi/anyobject.hpp>
14 #include <qi/clock.hpp>
15 #include <tuple>
16
17 QI_TYPE_ENUM(qi::LogLevel)
18
19 namespace qi
20 {
21 namespace detail
22 {
23 namespace name
24 {
25 // TODO will be used with VS2015
26 // constexpr auto LogMessage_timestamp = "timestamp";
27 // constexpr auto LogMessage_systemDate = "systemDate";
28 // constexpr auto LogMessage_date = "date";
29
30 inline const char* LogMessage_timestamp() { return "timestamp"; }
31 inline const char* LogMessage_systemDate() { return "systemDate"; }
32 inline const char* LogMessage_date() { return "date"; }
33 }
34 }
35
36 struct LogMessage
37 {
38 std::string source; // File:function:line
39 qi::LogLevel level = qi::LogLevel_Info; // Level of verbosity of the message
40 std::string category; // Category of the message
41 std::string location; // machineID:PID
42 std::string message; // The message itself
43 unsigned int id = 0; // Unique message ID
44 qi::Clock::time_point date; // Steady clock timestamp
45 qi::SystemClock::time_point systemDate; // Wall clock timestamp
46 };
47 }
48
49 inline bool toOld(std::map<std::string, ::qi::AnyValue>& fields,
50 const std::vector<std::tuple<std::string, qi::TypeInterface*>>& missing,
51 const std::map<std::string, ::qi::AnyReference>& dropfields)
52 {
53 try
54 {
55 if (missing.size() == 1 && std::get<0>(missing.front()) == qi::detail::name::LogMessage_timestamp())
56 {
57 if (dropfields.size() == 2)
58 {
59 auto systemDateIt = dropfields.find(qi::detail::name::LogMessage_systemDate());
60 auto dateIt = dropfields.find(qi::detail::name::LogMessage_systemDate());
61 if (systemDateIt != dropfields.end() && dateIt != dropfields.end())
62 {
63 const qi::SystemClock::time_point systemDate = systemDateIt->second.to<qi::SystemClock::time_point>();
64 fields[qi::detail::name::LogMessage_timestamp()] =
65 qi::AnyValue(qi::os::timeval(systemDate.time_since_epoch()));
66 return true;
67 }
68 }
69 }
70 }
71 catch (const std::exception& e)
72 {
73 qiLogVerbose("qi.core.LogMessage") << "Conversion error: " << e.what();
74 }
75 return false;
76 }
77
78 inline bool fromOld(std::map<std::string, ::qi::AnyValue>& fields,
79 const std::vector<std::tuple<std::string, qi::TypeInterface*>>& missing,
80 const std::map<std::string, ::qi::AnyReference>& dropfields)
81 {
82 try
83 {
84 if (dropfields.size() == 1)
85 {
86 auto dropfieldsIt = dropfields.find(qi::detail::name::LogMessage_timestamp());
87 if (dropfieldsIt != dropfields.end() && missing.size() == 2 &&
88 ((std::get<0>(missing.at(0)) == qi::detail::name::LogMessage_date() &&
89 std::get<0>(missing.at(1)) == qi::detail::name::LogMessage_systemDate()) ||
90 (std::get<0>(missing.at(1)) == qi::detail::name::LogMessage_date() &&
91 std::get<0>(missing.at(0)) == qi::detail::name::LogMessage_systemDate())))
92 {
93 const qi::os::timeval timestamp = dropfieldsIt->second.to<qi::os::timeval>();
94 fields[qi::detail::name::LogMessage_date()] = qi::AnyValue(qi::Clock::time_point());
95 fields[qi::detail::name::LogMessage_systemDate()] = qi::AnyValue(
96 qi::SystemClock::time_point(qi::Seconds(timestamp.tv_sec) + qi::MicroSeconds(timestamp.tv_usec)));
97 return true;
98 }
99 }
100 }
101 catch (const std::exception& e)
102 {
103 qiLogVerbose("qi.core.LogMessage") << "Conversion error: " << e.what();
104 }
105 return false;
106 }
107
108 QI_TYPE_STRUCT_EXTENSION_CONVERT_HANDLERS(::qi::LogMessage, fromOld, toOld);
109 QI_TYPE_STRUCT(::qi::LogMessage, source, level, category, location, message, id, date, systemDate);
110
111 #endif // !QICORE_LOG_HPP_
qi::LogMessage::date
qi::Clock::time_point date
Definition: logmessage.hpp:44
QI_TYPE_ENUM
QI_TYPE_ENUM(ProgressNotifier::Status)
qi::detail::name::LogMessage_timestamp
const char * LogMessage_timestamp()
Definition: logmessage.hpp:30
qi::LogMessage::category
std::string category
Definition: logmessage.hpp:40
QI_TYPE_STRUCT_EXTENSION_CONVERT_HANDLERS
QI_TYPE_STRUCT_EXTENSION_CONVERT_HANDLERS(::qi::LogMessage, fromOld, toOld)
qi::detail::name::LogMessage_systemDate
const char * LogMessage_systemDate()
Definition: logmessage.hpp:31
qi::LogMessage
Definition: logmessage.hpp:36
qi::LogMessage::location
std::string location
Definition: logmessage.hpp:41
fromOld
bool fromOld(std::map< std::string,::qi::AnyValue > &fields, const std::vector< std::tuple< std::string, qi::TypeInterface * >> &missing, const std::map< std::string,::qi::AnyReference > &dropfields)
Definition: logmessage.hpp:78
qi::detail::name::LogMessage_date
const char * LogMessage_date()
Definition: logmessage.hpp:32
qi::LogMessage::systemDate
qi::SystemClock::time_point systemDate
Definition: logmessage.hpp:45
qi::LogMessage::source
std::string source
Definition: logmessage.hpp:38
toOld
bool toOld(std::map< std::string,::qi::AnyValue > &fields, const std::vector< std::tuple< std::string, qi::TypeInterface * >> &missing, const std::map< std::string,::qi::AnyReference > &dropfields)
Definition: logmessage.hpp:49
QI_TYPE_STRUCT
QI_TYPE_STRUCT(::qi::LogMessage, source, level, category, location, message, id, date, systemDate)
qi::LogMessage::message
std::string message
Definition: logmessage.hpp:42