-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathConsoleLogger.h
107 lines (92 loc) · 2.69 KB
/
ConsoleLogger.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "ILogger.h"
#include "LogLevel.h"
#include <cstdint>
#include <string>
namespace Aws
{
namespace IoTFleetWise
{
/**
* @brief This logger instance logs messages to the standard output.
*/
class ConsoleLogger : public ILogger
{
public:
~ConsoleLogger() override = default;
ConsoleLogger();
ConsoleLogger( const ConsoleLogger & ) = delete;
ConsoleLogger &operator=( const ConsoleLogger & ) = delete;
ConsoleLogger( ConsoleLogger && ) = delete;
ConsoleLogger &operator=( ConsoleLogger && ) = delete;
/**
* @brief Logs a log message to the standard output. Includes current Thread ID and timestamp.
* The log message has this structure : [Thread : ID] [Time] [Level] [filename:lineNumber] [function]:
* [Message]
* @param level log level
* @param filename file that emitted the log
* @param lineNumber line number
* @param function calling function
* @param logEntry actual message
*/
void logMessage( LogLevel level,
const std::string &filename,
const uint32_t lineNumber,
const std::string &function,
const std::string &logEntry ) override;
/**
* @brief Try to flush any log that has been buffered
*/
void flush() override;
private:
/**
* @brief Time stamp as a String. The actual timestamp conversion and format happens
* in the Clock API
* @return the current time in a string representation as it's defined in the clock.
*/
static std::string timeAsString();
/**
* @brief Current Thread ID that's logging the message.
* @return Thread ID.
*/
static uint64_t currentThreadId();
/**
* @brief converts the Log Level enum to a color for logging
* @param level the log level enum to convert
* @return empty string if unrecognized LogLevel
* */
const std::string &levelToColor( LogLevel level ) const;
bool mColorEnabled{ false };
};
enum class LogColorOption
{
Auto,
Yes,
No
};
inline bool
stringToLogColorOption( const std::string level, LogColorOption &outLogColorOption )
{
if ( level == "Auto" )
{
outLogColorOption = LogColorOption::Auto;
}
else if ( level == "Yes" )
{
outLogColorOption = LogColorOption::Yes;
}
else if ( level == "No" )
{
outLogColorOption = LogColorOption::No;
}
else
{
return false;
}
return true;
}
extern LogColorOption gLogColorOption; // NOLINT Global log color
} // namespace IoTFleetWise
} // namespace Aws