Adds writer test case for RCU
[folly.git] / folly / experimental / logging / example / main.cpp
1 /*
2  * Copyright 2017-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 #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>
20
21 #include <folly/experimental/logging/example/lib.h>
22
23 DEFINE_string(logging, "", "Logging category configuration string");
24
25 using namespace example;
26 using folly::LogLevel;
27
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");
31
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");
37   fflush(stdout);
38
39   // Call folly::init() and then initialize log levels and handlers
40   folly::init(&argc, &argv);
41   folly::initLogging(FLAGS_logging);
42
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");
46
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 "
51                                                     << "syntax";
52
53   ExampleObject("foo");
54   XLOG(INFO, "main returning");
55   return 0;
56 }