logging: split FileHandlerFactory into two classes
[folly.git] / folly / experimental / logging / Init.cpp
index 59d4f8b8b950f4228d9c5ecba860fbc21d8a09b2..24600510da59d04813160cc498f95032f660b58c 100644 (file)
  */
 #include <folly/experimental/logging/Init.h>
 
-#include <folly/experimental/logging/FileHandlerFactory.h>
 #include <folly/experimental/logging/LogConfig.h>
 #include <folly/experimental/logging/LogConfigParser.h>
 #include <folly/experimental/logging/LoggerDB.h>
+#include <folly/experimental/logging/StreamHandlerFactory.h>
 
 namespace folly {
 
@@ -44,16 +44,24 @@ namespace folly {
  * handler, the handler will be automatically forgotten by the LoggerDB code.
  */
 constexpr StringPiece kDefaultLoggingConfig =
-    ".=WARN:default; default=file,stream=stderr,async=false";
+    ".=WARN:default; default=stream,stream=stderr,async=false";
 
 void initLogging(StringPiece configString) {
-  // Register the FileHandlerFactory
-  //
+  // Register the StreamHandlerFactory
+  LoggerDB::get()->registerHandlerFactory(
+      std::make_unique<StreamHandlerFactory>());
+
   // TODO: In the future it would be nice to build a better mechanism so that
   // additional LogHandlerFactory objects could be automatically registered on
   // startup if they are linked into our current executable.
-  LoggerDB::get()->registerHandlerFactory(
-      std::make_unique<FileHandlerFactory>());
+  //
+  // For now we register only the StreamHandlerFactory.  There is a
+  // FileHandlerFactory, but we do not register it by default: it allows
+  // appending to arbitrary files based on the config settings, and we do not
+  // want to allow this by default for security reasons.  (In the future
+  // maybe it would be worth enabling the FileHandlerFactory by default if we
+  // confirm that we are not a setuid or setgid binary.  i.e., if the real
+  // UID+GID is the same as the effective UID+GID.)
 
   // Parse the default log level settings before processing the input config
   // string.