summaryrefslogtreecommitdiffstats
path: root/src/libs/dxvk-native-1.9.2a/src/util/log/log.h
blob: 93c05ffb7929ceb871a1bd33bccf2db998e0c12c (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#pragma once

#include <array>
#include <fstream>
#include <iostream>
#include <string>

#include "../thread.h"

namespace dxvk {
  
  enum class LogLevel : uint32_t {
    Trace = 0,
    Debug = 1,
    Info  = 2,
    Warn  = 3,
    Error = 4,
    None  = 5,
  };
  
  /**
   * \brief Logger
   * 
   * Logger for one DLL. Creates a text file and
   * writes all log messages to that file.
   */
  class Logger {
    
  public:
    
    Logger(const std::string& file_name);
    ~Logger();
    
    static void trace(const std::string& message);
    static void debug(const std::string& message);
    static void info (const std::string& message);
    static void warn (const std::string& message);
    static void err  (const std::string& message);
    static void log  (LogLevel level, const std::string& message);
    
    static LogLevel logLevel() {
#ifndef VBOX
      return s_instance.m_minLevel;
#else
      return LogLevel::Info;
#endif
    }
    
  private:

#ifndef VBOX
    static Logger s_instance;
#endif

    const LogLevel m_minLevel;
    
    dxvk::mutex   m_mutex;
    std::ofstream m_fileStream;

#ifndef VBOX
    void emitMsg(LogLevel level, const std::string& message);
#endif
    
    static LogLevel getMinLogLevel();
    
    static std::string getFileName(
      const std::string& base);

  };
  
}