-
Notifications
You must be signed in to change notification settings - Fork 147
/
Copy pathLog.h
79 lines (65 loc) · 2.74 KB
/
Log.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
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2022 Datadog, Inc.
#pragma once
#include "EnvironmentVariables.h"
#include <mutex>
#include <string>
#include "shared/src/native-src/logger.h"
#include "shared/src/native-src/logmanager.h"
#include "shared/src/native-src/string.h"
namespace ds = datadog::shared;
class Log final
{
private:
struct ProfilerLoggerPolicy
{
inline static const std::string file_name = "DD-DotNet-Profiler-Native";
#ifdef _WIN32
inline static const shared::WSTRING folder_path = WStr(R"(Datadog .NET Tracer\logs)");
#endif
inline static const std::string pattern = "[%Y-%m-%d %H:%M:%S.%e | %l | PId: %P | TId: %t] %v";
struct logging_environment
{
inline static const shared::WSTRING log_path = EnvironmentVariables::LogPath;
inline static const shared::WSTRING log_directory = EnvironmentVariables::LogDirectory;
inline static const shared::WSTRING deprecated_log_directory = EnvironmentVariables::DeprecatedLogDirectory;
};
};
inline static ds::Logger* const Instance = ds::LogManager::Get<Log::ProfilerLoggerPolicy>();
public:
static bool IsDebugEnabled()
{
return Instance->IsDebugEnabled();
}
static void EnableDebug()
{
Instance->EnableDebug(true);
}
template <typename... Args>
static inline void Debug(const Args&... args)
{
Instance->Debug<Args...>(args...);
}
template <typename... Args>
static void Info(const Args&... args)
{
Instance->Info<Args...>(args...);
}
template <typename... Args>
static void Warn(const Args&... args)
{
Instance->Warn<Args...>(args...);
}
template <typename... Args>
static void Error(const Args&... args)
{
Instance->Error<Args...>(args...);
}
};
#define LogOnce(level, ...) \
do \
{ \
static std::once_flag UNIQUE_ONCE_FLAG_##__COUNTER__; \
std::call_once( \
UNIQUE_ONCE_FLAG_##__COUNTER__, [](auto&&... args) { Log::level(std::forward<decltype(args)>(args)...); }, __VA_ARGS__); \
} while (0) // NOLINT