summaryrefslogtreecommitdiff
path: root/graphs/cpp/logger/logger.hh
blob: 4b3a43b7a8f52cb8605b6470e53d6a9d4d621583 (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
#pragma once
#include <fstream>
#include <string>

namespace LogMe
{
    enum logging_level
    {
        DEBUG,
        INFO,
        WARN,
        ERROR,
        CRITICAL
    };
    class Logger
    {
    public:
        Logger(logging_level level, const std::string& log_file)
            : level_{ level }
        {
            output_stream_.open(log_file);
        }
        Logger(logging_level level)
            : level_{ level }
        {}

        ~Logger()
        {
            if (output_stream_.is_open())
            {
                output_stream_.close();
            }
        }

        void set_debug_level(logging_level level);
        void log(logging_level level, const std::string& msg);
        void debug(const std::string& msg);
        void info(const std::string& msg);
        void warn(const std::string& msg);
        void critical(const std::string& msg);
        void error(const std::string& msg);

    private:
        logging_level level_;
        std::ofstream output_stream_;
    };
} // namespace LogMe