FileHandlerFactory.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. #pragma once
  17. #include <folly/logging/LogHandlerFactory.h>
  18. namespace folly {
  19. /**
  20. * FileHandlerFactory is a LogHandlerFactory that constructs log handlers
  21. * that write to a file.
  22. *
  23. * Note that FileHandlerFactory allows opening and appending to arbitrary files
  24. * based on the handler options. This may make it unsafe to use
  25. * FileHandlerFactory in some contexts: for instance, a setuid binary should
  26. * generally avoid registering the FileHandlerFactory if they allow log
  27. * handlers to be configured via command line parameters, since otherwise this
  28. * may allow non-root users to append to files that they otherwise would not
  29. * have write permissions for.
  30. */
  31. class FileHandlerFactory : public LogHandlerFactory {
  32. public:
  33. StringPiece getType() const override {
  34. return "file";
  35. }
  36. std::shared_ptr<LogHandler> createHandler(const Options& options) override;
  37. private:
  38. class WriterFactory;
  39. };
  40. } // namespace folly