update readme
[c11concurrency-benchmarks.git] / mabain / src / logger.h
1 /**
2  * Copyright (C) 2017 Cisco Inc.
3  *
4  * This program is free software: you can redistribute it and/or  modify
5  * it under the terms of the GNU General Public License, version 2,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15  */
16
17 // @author Changxue Deng <chadeng@cisco.com>
18
19 #ifndef __MB_LOGGER_H__
20 #define __MB_LOGGER_H__
21
22 #include <fstream>
23 #include <string>
24
25 namespace mabain {
26
27 #define LOG_LEVEL_ERROR   0
28 #define LOG_LEVEL_WARN    1
29 #define LOG_LEVEL_INFO    2
30 #define LOG_LEVEL_DEBUG   3
31
32 class Logger
33 {
34 public:
35     ~Logger();
36
37     // Logs a message
38     static void Log(int level, const std::string &message);
39     // Variable length log
40     static void Log(int level, const char *formt, ... );
41     static void FillDateTime(char *buffer, int bufsize);
42     static void InitLogFile(const std::string &logfile);
43     // Set log level. Default is logging everything except for debug.
44     static int SetLogLevel(int level);
45     static void Close();
46     static std::ofstream* GetLogStream();
47
48 private:
49     // This is a singleton class. Make sure nobody can create an instance.
50     Logger();
51     static void Rotate();
52
53     static std::string log_file;
54     static std::ofstream *log_stream;
55     static const char* LOG_LEVEL[4];
56     static int log_level_;
57     static int roll_size;
58 };
59
60 }
61
62 #endif