logger.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. void SetUseCoreLog();
  26. ILoggerPtr CreateStdErrLogger(ILogger::ELevel cutLevel);
  27. ILoggerPtr CreateFileLogger(ILogger::ELevel cutLevel, const TString& path, bool append = false);
  28. /**
  29. * Create logger that writes to a file in a buffered manner.
  30. * It should result in fewer system calls (useful if you expect a lot of log messages),
  31. * but in case of a crash, you would lose some log messages that haven't been flushed yet.
  32. */
  33. ILoggerPtr CreateBufferedFileLogger(ILogger::ELevel cutLevel, const TString& path, bool append = false);
  34. ////////////////////////////////////////////////////////////////////////////////
  35. } // namespace NYT