2 * Copyright 2004-present Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <folly/File.h>
21 #include <folly/Range.h>
22 #include <folly/experimental/logging/LogHandler.h>
30 * StandardLogHandler is a LogHandler implementation that uses a LogFormatter
31 * class to serialize the LogMessage into a string, and then gives it to a
34 * This basically is a simple glue class that helps chain together
35 * configurable LogFormatter and LogWriter objects.
37 * StandardLogHandler also supports ignoring messages less than a specific
38 * LogLevel. By default it processes all messages.
40 class StandardLogHandler : public LogHandler {
43 std::shared_ptr<LogFormatter> formatter,
44 std::shared_ptr<LogWriter> writer);
45 ~StandardLogHandler();
48 * Get the handler's current LogLevel.
50 * Messages less than this LogLevel will be ignored. This defaults to
51 * LogLevel::NONE when the handler is constructed.
53 LogLevel getLevel() const {
54 return level_.load(std::memory_order_acquire);
58 * Set the handler's current LogLevel.
60 * Messages less than this LogLevel will be ignored.
62 void setLevel(LogLevel level) {
63 return level_.store(level, std::memory_order_release);
67 const LogMessage& message,
68 const LogCategory* handlerCategory) override;
70 void flush() override;
73 std::atomic<LogLevel> level_{LogLevel::NONE};
74 std::shared_ptr<LogFormatter> formatter_;
75 std::shared_ptr<LogWriter> writer_;