Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Commit

Permalink
Add EXIT level for log (#60)
Browse files Browse the repository at this point in the history
* Add EXIT level for log

(#59)

* Rename log level

(#59)
  • Loading branch information
Yang Ce authored and bluebore committed Jan 3, 2017
1 parent 177bd34 commit 1ed9550
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion include/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ enum LogLevel {
DEBUG = 2,
INFO = 4,
WARNING = 8,
FATAL = 16,
ERROR = 16,
FATAL = 32,
};

void SetLogLevel(int level);
Expand Down Expand Up @@ -47,6 +48,7 @@ class LogStream {
using common::DEBUG;
using common::INFO;
using common::WARNING;
using common::ERROR;
using common::FATAL;

} // namespace baidu
Expand Down
12 changes: 7 additions & 5 deletions src/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ void Logv(int log_level, const char* format, va_list ap) {
}

static const char level_char[] = {
'V', 'D', 'I', 'W', 'F'
'V', 'D', 'I', 'W', 'E', 'F'
};
char cur_level = level_char[0];
if (log_level < DEBUG) {
Expand All @@ -299,10 +299,12 @@ void Logv(int log_level, const char* format, va_list ap) {
cur_level = level_char[1];
} else if (log_level < WARNING) {
cur_level = level_char[2];
} else if (log_level < FATAL) {
} else if (log_level < ERROR) {
cur_level = level_char[3];
} else {
} else if (log_level < FATAL) {
cur_level = level_char[4];
} else {
cur_level = level_char[5];
}

// We try twice: the first time with a fixed-size stack allocated buffer,
Expand Down Expand Up @@ -358,7 +360,7 @@ void Logv(int log_level, const char* format, va_list ap) {
// fflush(g_warning_file);
//}
g_logger.WriteLog(log_level, base, p - base);
if (log_level >= FATAL) {
if (log_level >= ERROR) {
g_logger.Flush();
}
if (base != buffer) {
Expand All @@ -376,7 +378,7 @@ void Log(int level, const char* fmt, ...) {
Logv(level, fmt, ap);
}
va_end(ap);
if (level >= FATAL) {
if (level == FATAL) {
abort();
}
}
Expand Down

0 comments on commit 1ed9550

Please sign in to comment.