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 c61a67695..cb16f7c04 100644 Binary files a/td/generate/scheme/td_api.tlo and b/td/generate/scheme/td_api.tlo differ 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;