Skip to content
This repository was archived by the owner on Jan 27, 2025. It is now read-only.

Commit be19435

Browse files
committed
fix(common): fix LOG_LEVEL
1 parent 294a02b commit be19435

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/common/logging.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#ifndef LOGGING_H_
22
#define LOGGING_H_
33

4-
#include <stdexcept>
54
#include <string>
5+
#include <system_error>
66

7+
#include "llvm/ADT/StringRef.h"
8+
#include "llvm/Support/FileSystem.h"
79
#include "llvm/Support/raw_ostream.h"
10+
#include "path.h"
811

912
#ifndef LOG_PATH
1013
#define LOG_PATH "/dev/stderr"
@@ -24,9 +27,10 @@
2427

2528
class Logger : public llvm::raw_fd_ostream {
2629
public:
27-
using llvm::raw_fd_ostream::raw_fd_ostream;
30+
explicit Logger(llvm::StringRef filename, std::error_code& ec,
31+
llvm::sys::fs::OpenFlags flags);
32+
~Logger();
2833

29-
public:
3034
template <class... Args>
3135
Logger& critical(const char* fmt, Args&&... args) {
3236
if (this->log_level() > LOG_LEVEL_CRITICAL) return *this;
@@ -40,7 +44,7 @@ class Logger : public llvm::raw_fd_ostream {
4044

4145
template <class... Args>
4246
Logger& error(const char* fmt, Args&&... args) {
43-
if (this->log_level() > LOG_LEVEL_INFO) return *this;
47+
if (this->log_level() > LOG_LEVEL_ERROR) return *this;
4448
this->change_color(llvm::raw_ostream::Colors::RED);
4549
this->log("{}", Logger::get_prompt("ERROR"));
4650
this->log(fmt, args...);
@@ -51,7 +55,7 @@ class Logger : public llvm::raw_fd_ostream {
5155

5256
template <class... Args>
5357
Logger& warning(const char* fmt, Args&&... args) {
54-
if (this->log_level() > LOG_LEVEL_INFO) return *this;
58+
if (this->log_level() > LOG_LEVEL_WARNING) return *this;
5559
this->change_color(llvm::raw_ostream::Colors::YELLOW, /*bold=*/true);
5660
this->log("{}", Logger::get_prompt("WARNING"));
5761
this->log(fmt, args...);
@@ -73,19 +77,19 @@ class Logger : public llvm::raw_fd_ostream {
7377

7478
template <class... Args>
7579
Logger& debug(const char* fmt, Args&&... args) {
76-
if (this->log_level() > LOG_LEVEL_INFO) return *this;
80+
if (this->log_level() > LOG_LEVEL_DEBUG) return *this;
7781
this->log("{}", Logger::get_prompt("DEBUG"));
7882
this->log(fmt, args...);
7983
this->log("\n");
8084
return *this;
8185
}
8286

83-
public:
87+
fs::path filename() const;
8488
int log_level() const;
8589
void set_log_level(const int new_log_level = LOG_LEVEL_NOTSET);
8690

87-
public:
88-
static const char* get_log_path();
91+
static fs::path get_log_path();
92+
static std::string time();
8993

9094
protected:
9195
template <class T, class... Args>
@@ -116,15 +120,14 @@ class Logger : public llvm::raw_fd_ostream {
116120

117121
Logger& log(const char* fmt);
118122

119-
protected:
120123
Logger& change_color(llvm::raw_ostream::Colors color, bool bold = false,
121124
bool background = false);
122125
Logger& reset_color();
123126

124-
protected:
125127
static std::string get_prompt(const std::string& type);
126128

127129
private:
130+
fs::path _filename;
128131
int _log_level = LOG_LEVEL_NOTSET;
129132
};
130133

0 commit comments

Comments
 (0)