-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor and move StructuredLoggerFactory from eden to edencommon
Summary: To support better telemetry and logging in watchman we want to use Eden's components. Lets migrate and detangle the needed pieces. This change refactors StructuredLoggerFactory to be a template specializing on a stats pointer (e.g. EdenStatsPtr) and then moves it from eden to edencommon. Reviewed By: kmancini Differential Revision: D56069823 fbshipit-source-id: 3507d521e809f91746a951c4273c5c323f965fa9
- Loading branch information
1 parent
c5d6f1e
commit c2c22c3
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "eden/common/telemetry/StatsGroup.h" | ||
|
||
namespace facebook::eden { | ||
|
||
struct TelemetryStats : StatsGroup<TelemetryStats> { | ||
Counter subprocessLoggerFailure{"telemetry.subprocess_logger_failure"}; | ||
}; | ||
|
||
} // namespace facebook::eden |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <folly/logging/xlog.h> | ||
#include <memory> | ||
#include <string> | ||
|
||
#include "eden/common/telemetry/NullStructuredLogger.h" | ||
#include "eden/common/telemetry/ScubaStructuredLogger.h" | ||
#include "eden/common/telemetry/Stats.h" | ||
#include "eden/common/telemetry/SubprocessScribeLogger.h" | ||
#include "eden/common/utils/RefPtr.h" | ||
|
||
namespace facebook::eden { | ||
|
||
class StructuredLogger; | ||
struct SessionInfo; | ||
|
||
/** | ||
* Returns a StructuredLogger appropriate for this platform and | ||
* configuration. | ||
*/ | ||
template <typename StatsPtr> | ||
std::shared_ptr<StructuredLogger> makeDefaultStructuredLogger( | ||
const std::string& binary, | ||
const std::string& category, | ||
SessionInfo sessionInfo, | ||
StatsPtr stats) { | ||
if (binary.empty()) { | ||
return std::make_shared<NullStructuredLogger>(); | ||
} | ||
|
||
if (category.empty()) { | ||
XLOGF( | ||
WARN, | ||
"Scribe binary '{}' specified, but no category specified. Structured logging is disabled.", | ||
binary); | ||
return std::make_shared<NullStructuredLogger>(); | ||
} | ||
|
||
try { | ||
auto logger = | ||
std::make_unique<SubprocessScribeLogger>(binary.c_str(), category); | ||
return std::make_shared<ScubaStructuredLogger>( | ||
std::move(logger), std::move(sessionInfo)); | ||
} catch (const std::exception& ex) { | ||
stats->increment(&TelemetryStats::subprocessLoggerFailure, 1); | ||
XLOGF( | ||
ERR, | ||
"Failed to create SubprocessScribeLogger: {}. Structured logging is disabled.", | ||
folly::exceptionStr(ex)); | ||
return std::make_shared<NullStructuredLogger>(); | ||
} | ||
} | ||
|
||
} // namespace facebook::eden |