logging: add GlogStyleFormatter
[folly.git] / folly / experimental / logging / GlogStyleFormatter.h
1 /*
2  * Copyright 2004-present Facebook, Inc.
3  *
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
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 #pragma once
17
18 #include <folly/Range.h>
19 #include <folly/experimental/logging/LogFormatter.h>
20
21 namespace folly {
22
23 /**
24  * A LogFormatter implementation that produces messages in a format similar to
25  * that produced by the Google logging library.
26  *
27  * The glog message format is:
28  *
29  *   LmmDD HH:MM:SS.USECS THREAD [THREADNAME] (THREADCTX) FILE:LINE] MSG
30  *
31  * L:  A 1-character code describing the log level (e.g., E, W, I, V)
32  * mm: 2-digit month
33  * DD: 2-digit day
34  * HH: 2-digit hour, 24-hour format
35  * MM: 2-digit minute
36  * SS: 2-digit second
37  * USECS: 6-digit microseconds
38  * THREAD: Thread ID
39  * FILE: Filename (just the last component)
40  * LINE: Line number
41  * MSG: The actual log message
42  *
43  * [THREADNAME] is the thread name, and is only included if --logthreadnames
44  * was enabled on the command line.
45  *
46  * (THREADCTX) is thread-local log context data, if it has been set.  (This is
47  * a Facebook-specific modification, and is disabled unless --logthreadcontext
48  * was enabled on the command line.)
49  *
50  * Exception information and a custom log prefix may also appear after the
51  * file name and line number, before the ']' character.
52  */
53 class GlogStyleFormatter : public LogFormatter {
54  public:
55   std::string formatMessage(
56       const LogMessage& message,
57       const LogCategory* handlerCategory) override;
58 };
59 }