Commit 61a56337 authored by Adam Simpkins's avatar Adam Simpkins Committed by Facebook Github Bot

update folly::Init to call folly::initLogging()

Summary:
Update the folly::Init code to define a `--logging` command line flag, and call
`folly::initLoggingOrDie()` with the value of this command line during
initialization.

This is similar to the existing code that initializes the glog library.
(Programs can use both glog and folly logging together in the same program, and
I expect that many programs will do so as parts get converted to folly::logging
and parts remain using glog.)

Reviewed By: yfeldblum

Differential Revision: D7827344

fbshipit-source-id: 8aa239fbad43bc0b551cbe40cad7b92fa97fcdde
parent f4f7645b
......@@ -19,6 +19,7 @@
#include <glog/logging.h>
#include <folly/Singleton.h>
#include <folly/logging/Init.h>
#include <folly/portability/Config.h>
#if FOLLY_USE_SYMBOLIZER
......@@ -26,6 +27,8 @@
#endif
#include <folly/portability/GFlags.h>
DEFINE_string(logging, "", "Logging configuration");
namespace folly {
void init(int* argc, char*** argv, bool removeFlags) {
......@@ -43,6 +46,7 @@ void init(int* argc, char*** argv, bool removeFlags) {
gflags::ParseCommandLineFlags(argc, argv, removeFlags);
folly::initLoggingOrDie(FLAGS_logging);
auto programName = argc && argv && *argc > 0 ? (*argv)[0] : "unknown";
google::InitGoogleLogging(programName);
......
......@@ -16,14 +16,10 @@
#include <folly/init/Init.h>
#include <folly/logging/Init.h>
#include <folly/logging/xlog.h>
#include <folly/portability/GFlags.h>
#include <folly/logging/example/lib.h>
DEFINE_string(logging, "", "Logging category configuration string");
using namespace example;
using folly::LogLevel;
// Invoking code that uses XLOG() statements before main() is safe.
// This will use default log settings defined by folly::initializeLoggerDB().
......@@ -42,9 +38,10 @@ int main(int argc, char* argv[]) {
XLOG(INFO) << "log messages less than WARNING will be ignored";
XLOG(ERR) << "error messages before initLogging() will be logged to stderr";
// Call folly::init() and then initialize log levels and handlers
folly::init(&argc, &argv);
folly::initLoggingOrDie(FLAGS_logging);
// folly::Init() will automatically initialize the logging settings based on
// the FOLLY_INIT_LOGGING_CONFIG declaration above and the --logging command
// line flag.
auto init = folly::Init(&argc, &argv);
// All XLOG() statements in this file will log to the category
// folly.logging.example.main
......
......@@ -39,7 +39,6 @@
#include <folly/system/ThreadName.h>
#include <folly/test/TestUtils.h>
DEFINE_string(logging, "", "folly::logging configuration");
DEFINE_int64(
async_discard_num_normal_writers,
30,
......@@ -802,11 +801,3 @@ TEST(AsyncFileWriter, crazyForks) {
SKIP() << "pthread_atfork() is not supported on this platform";
#endif // FOLLY_HAVE_PTHREAD_ATFORK
}
int main(int argc, char* argv[]) {
testing::InitGoogleTest(&argc, argv);
folly::init(&argc, &argv);
folly::initLoggingOrDie(FLAGS_logging);
return RUN_ALL_TESTS();
}
......@@ -14,12 +14,9 @@
* limitations under the License.
*/
#include <folly/init/Init.h>
#include <folly/logging/Init.h>
#include <folly/logging/xlog.h>
#include <folly/portability/Stdlib.h>
DEFINE_string(logging, "", "Logging category configuration string");
DEFINE_string(
category,
"",
......@@ -84,9 +81,7 @@ std::string fbLogFatalCheck() {
* This is a simple helper program to exercise the LOG(FATAL) functionality.
*/
int main(int argc, char* argv[]) {
// Call folly::init() and then initialize log levels and handlers
folly::init(&argc, &argv);
folly::initLoggingOrDie(FLAGS_logging);
auto init = folly::Init(&argc, &argv);
// Do most of the work in a separate helper function.
//
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment