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