mirror of
https://github.com/facebook/sapling.git
synced 2024-10-05 14:28:17 +03:00
9fa292b9ed
Reviewed By: genevievehelsel Differential Revision: D36429182 fbshipit-source-id: 7d355917abf463493c37139856810de13e1090ff
51 lines
1.3 KiB
C++
51 lines
1.3 KiB
C++
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This software may be used and distributed according to the terms of the
|
|
* GNU General Public License version 2.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <unordered_map>
|
|
#include "eden/fs/telemetry/LogEvent.h"
|
|
#include "eden/fs/telemetry/SessionInfo.h"
|
|
|
|
namespace facebook::eden {
|
|
|
|
class StructuredLogger {
|
|
public:
|
|
explicit StructuredLogger(bool enabled, SessionInfo sessionInfo);
|
|
virtual ~StructuredLogger() = default;
|
|
|
|
template <typename Event>
|
|
void logEvent(const Event& event) {
|
|
// Avoid a bunch of work if it's going to be thrown away by the
|
|
// logDynamicEvent implementation.
|
|
if (!enabled_) {
|
|
return;
|
|
}
|
|
|
|
// constexpr to ensure that the type field on the Event struct is constexpr
|
|
// too.
|
|
constexpr const char* type = Event::type;
|
|
|
|
// TODO: consider moving the event to another thread and populating the
|
|
// default fields there to reduce latency at the call site.
|
|
DynamicEvent de{populateDefaultFields(type)};
|
|
event.populate(de);
|
|
logDynamicEvent(std::move(de));
|
|
}
|
|
|
|
private:
|
|
virtual void logDynamicEvent(DynamicEvent event) = 0;
|
|
|
|
DynamicEvent populateDefaultFields(const char* type);
|
|
|
|
bool enabled_;
|
|
uint32_t sessionId_;
|
|
SessionInfo sessionInfo_;
|
|
};
|
|
|
|
} // namespace facebook::eden
|