summaryrefslogtreecommitdiff
path: root/src/logger.hh
blob: 3d5fd0d22d100b7d61fe24850baa47cf602b17ac (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
#ifndef LOGGER_HH
#define LOGGER_HH

#include <filesystem>
#include <memory>
#include <string>

class Logger {
public:
  virtual ~Logger() = default;

  static std::unique_ptr<Logger> create_stdio();
  // Can return nullptr, will write reason to fallback.
  static std::unique_ptr<Logger> create_file(std::filesystem::path const& path,
                                             Logger* fallback);
  static std::unique_ptr<Logger> create_syslog(std::string const& prgname);
  static std::unique_ptr<Logger> create_null();

  virtual void err(char const* format, ...)
#if HAVE_ATTRIBUTE_FORMAT
    __attribute__((format(printf, 2, 3)))  // this takes up 1
#endif  // HAVE_ATTRIBUTE_FORMAT
    = 0;

  virtual void warn(char const* format, ...)
#if HAVE_ATTRIBUTE_FORMAT
    __attribute__((format(printf, 2, 3)))
#endif  // HAVE_ATTRIBUTE_FORMAT
    = 0;

  virtual void info(char const* format, ...)
#if HAVE_ATTRIBUTE_FORMAT
    __attribute__((format(printf, 2, 3)))
#endif  // HAVE_ATTRIBUTE_FORMAT
    = 0;

#ifdef NDEBUG
  void dbg(char const*, ...)
#if HAVE_ATTRIBUTE_FORMAT
    __attribute__((format(printf, 2, 3)))
#endif  // HAVE_ATTRIBUTE_FORMAT
  {}
#else
  virtual void dbg(char const* format, ...)
#if HAVE_ATTRIBUTE_FORMAT
    __attribute__((format(printf, 2, 3)))
#endif  // HAVE_ATTRIBUTE_FORMAT
    = 0;
#endif

protected:
  Logger() = default;
  Logger(Logger const&) = delete;
  Logger& operator=(Logger const&) = delete;
};

#endif  // LOGGER_HH