373b0586aa5a04b2e43bf74c3b4502b65ec3131f
[folly.git] / folly / experimental / logging / printf.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 /*
19  * C-style printf-like macros for the logging library.
20  *
21  * These are defined in their own separate header file to discourage their use
22  * in new code.  These macros make it somewhat easier to convert existing code
23  * using printf()-like statements to the logging library.  However, new code
24  * should generally prefer to use one of the other macro forms instead
25  * (simple argument concatenation, folly::format based, or iostream-like).
26  *
27  * These use a "C" suffix to the macro name since these use C-style format
28  * syntax.  (The "F" suffix is used for folly:format()-style.)
29  */
30
31 #include <folly/experimental/logging/Logger.h>
32 #include <folly/experimental/logging/xlog.h>
33
34 namespace folly {
35 std::string loggingFormatPrintf(
36     FOLLY_PRINTF_FORMAT const char* format,
37     ...) noexcept FOLLY_PRINTF_FORMAT_ATTR(1, 2);
38 }
39
40 /**
41  * Log a message to the specified logger using a printf-style format string.
42  */
43 #define FB_LOGC(logger, level, fmt, ...)   \
44   FB_LOG_IMPL(                             \
45       logger,                              \
46       ::folly::LogLevel::level,            \
47       ::folly::LogStreamProcessor::APPEND, \
48       ::folly::loggingFormatPrintf(fmt, ##__VA_ARGS__))
49
50 /**
51  * Log a message to the file's default log category using a printf-style format
52  * string.
53  */
54 #define XLOGC(level, fmt, ...)             \
55   XLOG_IMPL(                               \
56       ::folly::LogLevel::level,            \
57       ::folly::LogStreamProcessor::APPEND, \
58       ::folly::loggingFormatPrintf(fmt, ##__VA_ARGS__))