logger.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #pragma once
  2. #include <util/generic/ptr.h>
  3. #include <util/generic/string.h>
  4. #include <util/system/compat.h>
  5. #include <util/system/src_location.h>
  6. namespace NYT {
  7. ////////////////////////////////////////////////////////////////////////////////
  8. class ILogger
  9. : public TThrRefBase
  10. {
  11. public:
  12. enum ELevel
  13. {
  14. FATAL /* "fatal", "FATAL" */,
  15. // We don't have such level as `warning', but we support it for compatibility with other APIs.
  16. ERROR /* "error", "warning", "ERROR", "WARNING" */,
  17. INFO /* "info", "INFO" */,
  18. DEBUG /* "debug", "DEBUG" */
  19. };
  20. virtual void Log(ELevel level, const ::TSourceLocation& sourceLocation, const char* format, va_list args) = 0;
  21. };
  22. using ILoggerPtr = ::TIntrusivePtr<ILogger>;
  23. void SetLogger(ILoggerPtr logger);
  24. ILoggerPtr GetLogger();
  25. ILoggerPtr CreateStdErrLogger(ILogger::ELevel cutLevel);
  26. ILoggerPtr CreateFileLogger(ILogger::ELevel cutLevel, const TString& path, bool append = false);
  27. /**
  28. * Create logger that writes to a file in a buffered manner.
  29. * It should result in fewer system calls (useful if you expect a lot of log messages),
  30. * but in case of a crash, you would lose some log messages that haven't been flushed yet.
  31. */
  32. ILoggerPtr CreateBufferedFileLogger(ILogger::ELevel cutLevel, const TString& path, bool append = false);
  33. } // namespace NYT