From 2e50410dcc4742b792c08a7bf046eb1372fd38ea Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 27 Sep 2020 14:37:35 +0300 Subject: [PATCH] Allow to disable stderr redirect when logging to file. GitOrigin-RevId: 7b91d362695cd73a640a9ed2a5d107b804536a16 --- td/generate/scheme/td_api.tl | 7 +++++-- td/generate/scheme/td_api.tlo | Bin 182708 -> 182748 bytes td/telegram/Log.cpp | 6 ++++-- td/telegram/Logging.cpp | 6 ++++-- tdutils/td/utils/FileLog.cpp | 4 ++++ tdutils/td/utils/FileLog.h | 2 ++ 6 files changed, 19 insertions(+), 6 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 55f8bc07c..94631f8fd 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -3377,8 +3377,11 @@ updates updates:vector = Updates; //@description The log is written to stderr or an OS specific log logStreamDefault = LogStream; -//@description The log is written to a file @path Path to the file to where the internal TDLib log will be written @max_file_size The maximum size of the file to where the internal TDLib log is written before the file will be auto-rotated -logStreamFile path:string max_file_size:int53 = LogStream; +//@description The log is written to a file +//@path Path to the file to where the internal TDLib log will be written +//@max_file_size The maximum size of the file to where the internal TDLib log is written before the file will be auto-rotated +//@redirect_stderr Pass true to additionally redirect stderr to the log file. Ignored on Windows +logStreamFile path:string max_file_size:int53 redirect_stderr:Bool = LogStream; //@description The log is written nowhere logStreamEmpty = LogStream; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index c61a67695cfb7e85d68d816654c5cd1725077092..cb16f7c04ef660bef2e5fcfaef2bf641c298abb2 100644 GIT binary patch delta 208 zcmdlonfuOU?hQE-EK^@KzusIR@!_>2h;{RrkPib86gji$aM-pT1c`z8AaGTVE9Pl$ zP&98&etK|8QEFnYTV_rw0|QJS^Yn!*jNX$2B3T6Zi&9fEi&B$I;)_dCQj3ZvC)mk= zZJPdrg;7BQrUPUuvQ6y4Wv2Gp{@?ijiB4;)o4%@baATbah1g^?)#e`{n z=;zJJPY*6BN=?jl%gjk-V1Vgkn!b>Q(R=cPNgQB9rz@~BDoDU2K?Wcj+8)8mxIKcE cX-gnZCEHcPnPeg$W*y*VQrModo~c3#0Q_q-vH$=8 diff --git a/td/telegram/Log.cpp b/td/telegram/Log.cpp index ff203459f..194d16d21 100644 --- a/td/telegram/Log.cpp +++ b/td/telegram/Log.cpp @@ -35,7 +35,8 @@ bool Log::set_file_path(string file_path) { return Logging::set_current_stream(td_api::make_object()).is_ok(); } - if (Logging::set_current_stream(td_api::make_object(file_path, max_log_file_size)).is_ok()) { + if (Logging::set_current_stream(td_api::make_object(file_path, max_log_file_size, true)) + .is_ok()) { log_file_path = std::move(file_path); return true; } @@ -46,7 +47,8 @@ bool Log::set_file_path(string file_path) { void Log::set_max_file_size(int64 max_file_size) { std::lock_guard lock(log_mutex); max_log_file_size = max(max_file_size, static_cast(1)); - Logging::set_current_stream(td_api::make_object(log_file_path, max_log_file_size)).ignore(); + Logging::set_current_stream(td_api::make_object(log_file_path, max_log_file_size, true)) + .ignore(); } void Log::set_verbosity_level(int new_verbosity_level) { diff --git a/td/telegram/Logging.cpp b/td/telegram/Logging.cpp index 81a4abd4e..921e79d20 100644 --- a/td/telegram/Logging.cpp +++ b/td/telegram/Logging.cpp @@ -61,8 +61,9 @@ Status Logging::set_current_stream(td_api::object_ptr stream) if (max_log_file_size <= 0) { return Status::Error("Max log file size must be positive"); } + auto redirect_stderr = file_stream->redirect_stderr_; - TRY_STATUS(file_log.init(file_stream->path_, max_log_file_size)); + TRY_STATUS(file_log.init(file_stream->path_, max_log_file_size, redirect_stderr)); std::atomic_thread_fence(std::memory_order_release); // better than nothing log_interface = &ts_log; return Status::OK(); @@ -85,7 +86,8 @@ Result> Logging::get_current_stream() { return td_api::make_object(); } if (log_interface == &ts_log) { - return td_api::make_object(file_log.get_path().str(), file_log.get_rotate_threshold()); + return td_api::make_object(file_log.get_path().str(), file_log.get_rotate_threshold(), + file_log.get_redirect_stderr()); } return Status::Error("Log stream is unrecognized"); } diff --git a/tdutils/td/utils/FileLog.cpp b/tdutils/td/utils/FileLog.cpp index d37cb3d52..b232a1571 100644 --- a/tdutils/td/utils/FileLog.cpp +++ b/tdutils/td/utils/FileLog.cpp @@ -65,6 +65,10 @@ int64 FileLog::get_rotate_threshold() const { return rotate_threshold_; } +bool FileLog::get_redirect_stderr() const { + return redirect_stderr_; +} + void FileLog::append(CSlice cslice, int log_level) { Slice slice = cslice; while (!slice.empty()) { diff --git a/tdutils/td/utils/FileLog.h b/tdutils/td/utils/FileLog.h index fe34244d1..8ef4318e2 100644 --- a/tdutils/td/utils/FileLog.h +++ b/tdutils/td/utils/FileLog.h @@ -32,6 +32,8 @@ class FileLog : public LogInterface { int64 get_rotate_threshold() const; + bool get_redirect_stderr() const; + void append(CSlice cslice, int log_level) override; void rotate() override;