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.
16 #include <folly/experimental/logging/Init.h>
17 #include <folly/experimental/logging/xlog.h>
18 #include <folly/init/Init.h>
19 #include <folly/portability/GFlags.h>
21 #include <folly/experimental/logging/example/lib.h>
23 DEFINE_string(logging, "", "Logging category configuration string");
25 using namespace example;
26 using folly::LogLevel;
28 // Invoking code that uses XLOG() statements before main is safe,
29 // but will not log anywhere, since no handlers are configured yet.
30 static ExampleObject staticInitialized("static");
32 int main(int argc, char* argv[]) {
33 // Using log macros before configuring any log levels or log handlers is
34 // safe, but the messages will always be ignore since no handlers are defined.
35 XLOG(INFO, "no handlers configured yet, so this will go nowhere");
36 printf("main starting\n");
39 // Call folly::init() and then initialize log levels and handlers
40 folly::init(&argc, &argv);
41 initLoggingGlogStyle(FLAGS_logging, LogLevel::INFO);
43 // All XLOG() statements in this file will log to the category
44 // folly.experimental.logging.example.main
45 XLOG(INFO, "now log messages will be sent to stderr");
47 XLOG(DBG1, "log arguments are concatenated: ", 12345, ", ", 92.0);
48 XLOGF(DBG1, "XLOGF supports {}-style formatting: {:.3f}", "python", 1.0 / 3);
49 XLOG(DBG2) << "streaming syntax is also supported: " << 1234;
50 XLOG(DBG2, "you can even", " mix function-style") << " and streaming "
54 XLOG(INFO, "main returning");