aboutsummaryrefslogtreecommitdiffstats
path: root/yt/cpp/mapreduce/interface/logging/logger.h
blob: 2b5aae87d14485d9abc3fa26aac8d9f368a77276 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#pragma once

#include <util/generic/ptr.h>
#include <util/generic/string.h>
#include <util/system/compat.h>
#include <util/system/src_location.h>

namespace NYT {

////////////////////////////////////////////////////////////////////////////////

class ILogger
    : public TThrRefBase
{
public:
    enum ELevel
    {
        FATAL /* "fatal", "FATAL" */,
        // We don't have such level as `warning', but we support it for compatibility with other APIs.
        ERROR /* "error", "warning", "ERROR", "WARNING" */,
        INFO /* "info", "INFO" */,
        DEBUG /* "debug", "DEBUG" */
    };

    virtual void Log(ELevel level, const ::TSourceLocation& sourceLocation, const char* format, va_list args) = 0;
};

using ILoggerPtr = ::TIntrusivePtr<ILogger>;

void SetLogger(ILoggerPtr logger);
ILoggerPtr GetLogger();

ILoggerPtr CreateStdErrLogger(ILogger::ELevel cutLevel);
ILoggerPtr CreateFileLogger(ILogger::ELevel cutLevel, const TString& path, bool append = false);

/**
 * Create logger that writes to a file in a buffered manner.
 * It should result in fewer system calls (useful if you expect a lot of log messages),
 * but in case of a crash, you would lose some log messages that haven't been flushed yet.
 */
ILoggerPtr CreateBufferedFileLogger(ILogger::ELevel cutLevel, const TString& path, bool append = false);

} // namespace NYT