56 if (numHandlers == 0) {
60 auto msg = folly::to<std::string>(
80 const std::shared_ptr<LogHandler>* handlers =
nullptr;
81 size_t numHandlers = 0;
82 constexpr
uint32_t kSmallOptimizationSize = 5;
83 std::array<std::shared_ptr<LogHandler>, kSmallOptimizationSize> handlersArray;
84 std::vector<std::shared_ptr<LogHandler>> handlersVector;
87 numHandlers = lockedHandlers->size();
88 if (numHandlers <= kSmallOptimizationSize) {
89 for (
size_t n = 0; n < numHandlers; ++n) {
90 handlersArray[n] = (*lockedHandlers)[n];
92 handlers = handlersArray.data();
94 handlersVector = *lockedHandlers;
95 handlers = handlersVector.data();
99 for (
size_t n = 0; n < numHandlers; ++n) {
101 handlers[n]->handleMessage(message,
this);
102 }
catch (
const std::exception& ex) {
109 "log handler for category \"",
111 "\" threw an error: ",
129 handlers->emplace_back(
std::move(handler));
133 std::vector<std::shared_ptr<LogHandler>> emptyHandlersList;
137 handlers->swap(emptyHandlersList);
149 std::vector<std::shared_ptr<LogHandler>> handlers) {
150 return handlers_.wlock()->swap(handlers);
154 std::shared_ptr<LogHandler>,
155 std::shared_ptr<LogHandler>>& handlerMap) {
157 for (
auto& entry : *handlers) {
183 auto newValue =
static_cast<uint32_t>(level);
189 uint32_t oldValue =
level_.exchange(newValue, std::memory_order_acq_rel);
192 if (oldValue == newValue) {
201 newEffectiveLevel = level;
207 auto oldEffectiveLevel =
208 effectiveLevel_.exchange(newEffectiveLevel, std::memory_order_acq_rel);
210 if (newEffectiveLevel == oldEffectiveLevel) {
216 levelPtr->store(newEffectiveLevel, std::memory_order_release);
221 while (child !=
nullptr) {
235 auto newEffectiveLevel =
std::min(myLevel, parentEffectiveLevel);
const Map::mapped_type * get_ptr(const Map &map, const Key &key)
folly::Synchronized< std::vector< std::shared_ptr< LogHandler > > > handlers_
LogCategory(LoggerDB *db)
std::atomic< uint32_t > level_
void processMessage(const LogMessage &message) const
std::vector< std::atomic< LogLevel > * > xlogLevels_
void setLevelLocked(LogLevel level, bool inherit)
fbstring exceptionStr(const std::exception &e)
constexpr detail::Map< Move > move
—— Concurrent Priority Queue Implementation ——
void handler(int, siginfo_t *, void *)
LogCategory * firstChild_
const std::string & getMessage() const
LogLevel getLevel() const
static std::string canonicalize(folly::StringPiece name)
void setLevel(LogLevel level, bool inherit=true)
ssize_t writeFull(int fd, const void *buf, size_t count)
folly::StringPiece getFileName() const
unsigned int getLineNumber() const
constexpr T const & constexpr_clamp(T const &v, T const &lo, T const &hi, Less less)
void updateHandlers(const std::unordered_map< std::shared_ptr< LogHandler >, std::shared_ptr< LogHandler >> &handlerMap)
void setLevel(folly::StringPiece name, LogLevel level, bool inherit=true)
std::vector< std::shared_ptr< LogHandler > > getHandlers() const
LogLevel getEffectiveLevel() const
void replaceHandlers(std::vector< std::shared_ptr< LogHandler >> handlers)
std::atomic< LogLevel > effectiveLevel_
LogCategory *const parent_
folly::Function< void()> child
size_t flushAllHandlers()
constexpr bool isLogLevelFatal(LogLevel level)
LogCategory * nextSibling_
void addHandler(std::shared_ptr< LogHandler > handler)
void updateEffectiveLevel(LogLevel newEffectiveLevel)
void admitMessage(const LogMessage &message) const
void parentLevelUpdated(LogLevel parentEffectiveLevel)
folly::Function< void()> parent
void registerXlogLevel(std::atomic< LogLevel > *levelPtr)
static void internalWarning(folly::StringPiece file, int lineNumber, Args &&...args) noexcept