proxygen
Init.cpp
Go to the documentation of this file.
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/logging/Init.h>
17 
20 #include <folly/logging/LoggerDB.h>
22 
23 namespace folly {
24 
25 void initLogging(StringPiece configString) {
26  // Get the base logging configuration
27  auto* const baseConfigStr = getBaseLoggingConfig();
28  // Return early if we have nothing to do
29  if (!baseConfigStr && configString.empty()) {
30  return;
31  }
32 
33  // Parse the configuration string(s)
35  if (baseConfigStr) {
36  config = parseLogConfig(baseConfigStr);
37  if (!configString.empty()) {
38  config.update(parseLogConfig(configString));
39  }
40  } else {
41  config = parseLogConfig(configString);
42  }
43 
44  // Apply the config settings
45  LoggerDB::get().updateConfig(config);
46 }
47 
48 void initLoggingOrDie(StringPiece configString) {
49  try {
50  initLogging(configString);
51  } catch (const std::exception& ex) {
52  // Print the error message. We intentionally use ex.what() here instead
53  // of folly::exceptionStr() to avoid including the exception type name in
54  // the output. The exceptions thrown by the logging library on error
55  // should have enough information to diagnose what is wrong with the
56  // input config string.
57  //
58  // We want the output here to be user-friendly since this will be shown
59  // to any user invoking a program with an error in the logging
60  // configuration string. This output is intended for end users rather
61  // than developers.
62  fprintf(stderr, "error parsing logging configuration: %s\n", ex.what());
63  exit(1);
64  }
65 }
66 
67 } // namespace folly
const char * getBaseLoggingConfig()
Definition: InitWeak.cpp:29
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
LogConfig parseLogConfig(StringPiece value)
AHArrayT::Config config
constexpr bool empty() const
Definition: Range.h:443
void updateConfig(const LogConfig &config)
Definition: LoggerDB.cpp:395
void initLogging(StringPiece configString)
Definition: Init.cpp:25
void update(const LogConfig &other)
Definition: LogConfig.cpp:31
void initLoggingOrDie(StringPiece configString)
Definition: Init.cpp:48
static LoggerDB & get()
Definition: LoggerDB.cpp:112