/*
- * Copyright 2004-present Facebook, Inc.
+ * Copyright 2017-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <cstdio>
#include <cstdlib>
+#include <folly/ConstexprMath.h>
#include <folly/ExceptionString.h>
#include <folly/FileUtil.h>
+#include <folly/MapUtil.h>
#include <folly/experimental/logging/LogHandler.h>
#include <folly/experimental/logging/LogMessage.h>
#include <folly/experimental/logging/LogName.h>
return *(handlers_.rlock());
}
+void LogCategory::replaceHandlers(
+ std::vector<std::shared_ptr<LogHandler>> handlers) {
+ return handlers_.wlock()->swap(handlers);
+}
+
+void LogCategory::updateHandlers(const std::unordered_map<
+ std::shared_ptr<LogHandler>,
+ std::shared_ptr<LogHandler>>& handlerMap) {
+ auto handlers = handlers_.wlock();
+ for (auto& entry : *handlers) {
+ auto* ptr = get_ptr(handlerMap, entry);
+ if (ptr) {
+ entry = *ptr;
+ }
+ }
+}
+
void LogCategory::setLevel(LogLevel level, bool inherit) {
// We have to set the level through LoggerDB, since we require holding
// the LoggerDB lock to iterate through our children in case our effective
//
// This makes sure that UNINITIALIZED is always less than any valid level
// value, and that level values cannot conflict with our flag bits.
- //
- // In debug builds we clamp the maximum to DFATAL rather than MAX_LEVEL
- // (FATAL), to ensure that fatal log messages can never be disabled.
- constexpr LogLevel maxLogLevel =
- kIsDebug ? LogLevel::DFATAL : LogLevel::MAX_LEVEL;
- if (level > maxLogLevel) {
- level = maxLogLevel;
- } else if (level < LogLevel::MIN_LEVEL) {
- level = LogLevel::MIN_LEVEL;
- }
+ level = constexpr_clamp(level, LogLevel::MIN_LEVEL, LogLevel::MAX_LEVEL);
// Make sure the inherit flag is always off for the root logger.
if (!parent_) {