src
log_event.h
Go to the documentation of this file.
1
// Log event with metadata
2
// Author: Max Schwarz <max.schwarz@ais.uni-bonn.de>
3
4
#ifndef ROSMON_LOG_EVENT_H
5
#define ROSMON_LOG_EVENT_H
6
7
#include <string>
8
#include <sstream>
9
10
namespace
rosmon
11
{
12
13
struct
LogEvent
14
{
15
public
:
16
enum class
Type
17
{
21
Raw
,
22
23
Debug
,
24
Info
,
25
Warning
,
26
Error
27
};
28
29
enum class
Channel
30
{
31
NotApplicable,
32
Stdout,
33
Stderr
34
};
35
36
LogEvent
(std::string
source
, std::string
message
,
Type
type
=
Type::Raw
)
37
: source{std::move(source)},
message
{std::move(
message
)},
type
{
type
}
38
{}
39
40
std::string
coloredString
()
const
41
{
42
auto
colorize = [](
const
char
* prefix,
const
std::string& str){
43
std::stringstream ss;
44
ss << prefix << str <<
"\e[0m"
;
45
return
ss.str();
46
};
47
48
switch
(
type
)
49
{
50
case
Type::Raw
:
return
message
;
51
case
Type::Debug
:
return
colorize(
"\e[32m"
,
message
);
52
case
Type::Info
:
return
colorize(
"\e[0m"
,
message
);
53
case
Type::Warning
:
return
colorize(
"\e[33m"
,
message
);
54
case
Type::Error
:
return
colorize(
"\e[31m"
,
message
);
55
}
56
57
return
message
;
58
}
59
60
std::string
source
;
61
std::string
message
;
62
Type
type
;
63
bool
muted
=
false
;
64
Channel
channel
=
Channel::NotApplicable
;
65
bool
showStdout
=
true
;
66
};
67
68
}
69
70
#endif
rosmon::LogEvent::muted
bool muted
Definition:
log_event.h:63
rosmon::LogEvent::type
Type type
Definition:
log_event.h:62
rosmon::LogEvent::Type::Debug
rosmon::LogEvent::Channel::NotApplicable
rosmon::LogEvent
Definition:
log_event.h:13
rosmon
Definition:
diagnostics_publisher.cpp:34
rosmon::LogEvent::channel
Channel channel
Definition:
log_event.h:64
rosmon::LogEvent::Type
Type
Definition:
log_event.h:16
rosmon::LogEvent::Type::Warning
rosmon::LogEvent::showStdout
bool showStdout
Definition:
log_event.h:65
rosmon::LogEvent::Type::Raw
rosmon::LogEvent::Channel
Channel
Definition:
log_event.h:29
rosmon::LogEvent::Type::Error
rosmon::LogEvent::Type::Info
rosmon::LogEvent::source
std::string source
Definition:
log_event.h:60
rosmon::LogEvent::LogEvent
LogEvent(std::string source, std::string message, Type type=Type::Raw)
Definition:
log_event.h:36
rosmon::LogEvent::coloredString
std::string coloredString() const
Definition:
log_event.h:40
rosmon::LogEvent::message
std::string message
Definition:
log_event.h:61
rosmon_core
Author(s): Max Schwarz
autogenerated on Fri Jun 16 2023 02:15:06