-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogging.hpp
More file actions
79 lines (62 loc) · 2.36 KB
/
Copy pathlogging.hpp
File metadata and controls
79 lines (62 loc) · 2.36 KB
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 License Version 2.0.
//
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2025-Present Datadog, Inc.
#pragma once
#include <cinttypes>
#include <memory>
#include <shared_mutex>
#include <string_view>
#include <vector>
#include "datadog/impl/core/attribute/typed_attribute.hpp"
#include "datadog/impl/core/feature.hpp"
#include "datadog/impl/core/platform/clock.hpp"
#include "datadog/impl/logging/types.hpp"
namespace datadog::impl {
/**
* Logging feature implementation. Keeps track of global state and allows Loggers to be
* created.
*/
class Logging final : public Feature {
public:
explicit Logging(const platform::IClock& clock);
FeatureId GetId() const override { return CreateFeatureId("LOGS"); }
std::string_view GetName() const override { return "logs"; }
std::optional<Report> UploadThread_PrepareReport(
BatchReader& reader, HttpRequestBuilder& builder
) override;
public:
/**
* Adds or updates a global logging attribute, which will be included in log events
* emitted by all loggers (unless shadowed by logger-level or message-level
* attributes).
*/
void AddAttribute(std::string_view name, const Attribute& value);
/**
* Removes a global logging attribute, if any exists with the given name.
*/
void RemoveAttribute(std::string_view name);
/**
* Creates a new Logger instance that can be wrapped in an API-layer Logger object,
* permitting the application to make log calls as desired.
*/
std::unique_ptr<Logger> CreateLogger(const LoggerConfig& config);
private:
// Reference to system clock; used to timestamp events
const platform::IClock& _clock;
// Global attributes applied to all log events
ObjectAttribute _global_attributes;
mutable std::shared_mutex _global_attributes_mutex;
// Reusable buffer for encoding events; accessed only on the context thread
std::vector<uint8_t> _encode_buffer;
// Each impl::Logger maintains a std::weak_ptr<impl::Logging> to access clock, global
// attributes, and encode buffer when handling log calls
friend class Logger;
private:
/**
* Obtains a thread-safe copy of the current set of global attributes; used by Logger.
*/
Attribute SnapshotGlobalAttributes() const;
};
} // namespace datadog::impl