Skip to content

Commit

Permalink
logger: output to std::cerr by default
Browse files Browse the repository at this point in the history
Currently writing the log messages to std::cout is unsafe
and messages can get lost if the program terminates abnormally
on segfault or abort().  Use std::cerr instead, by default,
to prevent that as std::cerr is unbuffered by default.

Signed-off-by: Benny Halevy <[email protected]>
  • Loading branch information
bhalevy committed Jan 1, 2020
1 parent 8fd8568 commit 2930e09
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/seastar/util/log.hh
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class logger_registry;
class logger {
sstring _name;
std::atomic<log_level> _level = { log_level::info };
static std::ostream* _out;
static std::atomic<bool> _stdout;
static std::atomic<bool> _syslog;
private:
Expand Down
3 changes: 2 additions & 1 deletion src/util/log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ std::istream& operator>>(std::istream& in, log_level& level) {
return in;
}

std::ostream* logger::_out = &std::cerr;
std::atomic<bool> logger::_stdout = { true };
std::atomic<bool> logger::_syslog = { false };

Expand Down Expand Up @@ -209,7 +210,7 @@ logger::really_do_log(log_level level, const char* fmt, const stringer* stringer
if (is_stdout_enabled) {
out << level_map[int(level)] << space_and_current_timestamp();
print_once(out);
std::cout << out.str();
*_out << out.str();
}
if (is_syslog_enabled) {
print_once(log);
Expand Down

0 comments on commit 2930e09

Please sign in to comment.