From f496580081bdca87c9410d8b3e0d808e9969b172 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 Change -log-file-append to a boolean flag --- src/log.cc | 1 + src/main.cc | 19 +++++++++---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/log.cc b/src/log.cc index fde88be3..ae3b277a 100644 --- a/src/log.cc +++ b/src/log.cc @@ -60,6 +60,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 37a50f45..80f05952 100644 --- a/src/main.cc +++ b/src/main.cc @@ -46,10 +46,10 @@ opt opt_index("index", value_desc("root"), cat(C)); list opt_init("init", desc("extra initialization options in JSON"), cat(C)); -opt opt_log_file("log-file", desc("log"), value_desc("filename"), +opt opt_log_file("log-file", desc("stderr or log file"), + value_desc("file"), init("stderr"), cat(C)); +opt opt_log_file_append("log-file-append", desc("append to log file"), cat(C)); -opt opt_log_file_append("log-file-append", desc("log"), - value_desc("filename"), cat(C)); void CloseLog() { fclose(ccls::log::file); } @@ -83,14 +83,13 @@ 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(), opt_log_file_append ? "ab" : "wb"); if (!ccls::log::file) { - fprintf( - stderr, "failed to open %s\n", - (opt_log_file.size() ? opt_log_file : opt_log_file_append).c_str()); + fprintf(stderr, "failed to open %s\n", opt_log_file.c_str()); return 2; } setbuf(ccls::log::file, NULL);