From 4f198f16ddeda471b4d3c654285bf5c8a3e27944 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 21 Jan 2019 10:20:07 +0800 Subject: [PATCH] Add -log-file=stderr and make it default --- src/log.cc | 1 + src/main.cc | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/log.cc b/src/log.cc index a10a4a7d..3e2b5592 100644 --- a/src/log.cc +++ b/src/log.cc @@ -72,6 +72,7 @@ Message::~Message() { std::lock_guard lock(mtx); stream_ << '\n'; fputs(stream_.str().c_str(), file); + fflush(file); if (verbosity_ == Verbosity_FATAL) abort(); } diff --git a/src/main.cc b/src/main.cc index 95cd0363..a4df3b8a 100644 --- a/src/main.cc +++ b/src/main.cc @@ -59,7 +59,7 @@ opt opt_index("index", list opt_init("init", desc("extra initialization options in JSON"), cat(C)); opt opt_log_file("log-file", desc("log"), value_desc("filename"), - cat(C)); + init("stderr"), cat(C)); opt opt_log_file_append("log-file-append", desc("log"), value_desc("filename"), cat(C)); @@ -96,9 +96,11 @@ int main(int argc, char **argv) { bool language_server = true; if (opt_log_file.size() || opt_log_file_append.size()) { - ccls::log::file = opt_log_file.size() - ? fopen(opt_log_file.c_str(), "wb") - : fopen(opt_log_file_append.c_str(), "ab"); + if (opt_log_file.size()) + ccls::log::file = + opt_log_file == "stderr" ? stderr : fopen(opt_log_file.c_str(), "wb"); + else + ccls::log::file = fopen(opt_log_file_append.c_str(), "ab"); if (!ccls::log::file) { fprintf( stderr, "failed to open %s\n",