-
Notifications
You must be signed in to change notification settings - Fork 333
/
Copy pathCloudwatch.cpp
82 lines (66 loc) · 2.21 KB
/
Cloudwatch.cpp
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
#include "Include.h"
#include "Cloudwatch.h"
namespace CppInteg {
Cloudwatch::Cloudwatch(ClientConfiguration* pClientConfig)
: logs(pClientConfig), monitoring(pClientConfig), terminated(FALSE)
{
}
STATUS Cloudwatch::init(PCHAR channelName, PCHAR region, BOOL isMaster, BOOL isStorage)
{
ENTERS();
STATUS retStatus = STATUS_SUCCESS;
ClientConfiguration clientConfig;
CreateLogGroupRequest createLogGroupRequest;
Aws::CloudWatchLogs::Model::CreateLogStreamOutcome createLogStreamOutcome;
CreateLogStreamRequest createLogStreamRequest;
clientConfig.region = region;
auto& instance = getInstanceImpl(&clientConfig);
if (STATUS_FAILED(instance.logs.init(channelName, region, isMaster, isStorage))) {
DLOGW("Failed to create Cloudwatch logger");
} else {
globalCustomLogPrintFn = logger;
}
CHK_STATUS(instance.monitoring.init(channelName, region, isMaster, isStorage));
CleanUp:
LEAVES();
return retStatus;
}
Cloudwatch& Cloudwatch::getInstance()
{
return getInstanceImpl();
}
Cloudwatch& Cloudwatch::getInstanceImpl(ClientConfiguration* pClientConfig)
{
static Cloudwatch instance{pClientConfig};
return instance;
}
VOID Cloudwatch::deinit()
{
auto& instance = getInstance();
instance.logs.deinit();
instance.monitoring.deinit();
instance.terminated = TRUE;
}
VOID Cloudwatch::logger(UINT32 level, PCHAR tag, PCHAR fmt, ...)
{
CHAR logFmtString[MAX_LOG_FORMAT_LENGTH + 1];
CHAR cwLogFmtString[MAX_LOG_FORMAT_LENGTH + 1];
UINT32 logLevel = GET_LOGGER_LOG_LEVEL();
UNUSED_PARAM(tag);
if (level >= logLevel) {
addLogMetadata(logFmtString, (UINT32) ARRAY_SIZE(logFmtString), fmt, level);
// Creating a copy to store the logFmtString for cloudwatch logging purpose
va_list valist, valist_cw;
va_start(valist_cw, fmt);
vsnprintf(cwLogFmtString, (SIZE_T) SIZEOF(cwLogFmtString), logFmtString, valist_cw);
va_end(valist_cw);
va_start(valist, fmt);
vprintf(logFmtString, valist);
va_end(valist);
auto& instance = getInstance();
if (!instance.terminated) {
instance.logs.push(cwLogFmtString);
}
}
}
} // namespace Canary