Allow to disable stderr redirect when logging to file.
GitOrigin-RevId: 7b91d362695cd73a640a9ed2a5d107b804536a16
This commit is contained in:
parent
75aac4dd46
commit
2e50410dcc
@ -3377,8 +3377,11 @@ updates updates:vector<Update> = 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;
|
||||
|
Binary file not shown.
@ -35,7 +35,8 @@ bool Log::set_file_path(string file_path) {
|
||||
return Logging::set_current_stream(td_api::make_object<td_api::logStreamDefault>()).is_ok();
|
||||
}
|
||||
|
||||
if (Logging::set_current_stream(td_api::make_object<td_api::logStreamFile>(file_path, max_log_file_size)).is_ok()) {
|
||||
if (Logging::set_current_stream(td_api::make_object<td_api::logStreamFile>(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<std::mutex> lock(log_mutex);
|
||||
max_log_file_size = max(max_file_size, static_cast<int64>(1));
|
||||
Logging::set_current_stream(td_api::make_object<td_api::logStreamFile>(log_file_path, max_log_file_size)).ignore();
|
||||
Logging::set_current_stream(td_api::make_object<td_api::logStreamFile>(log_file_path, max_log_file_size, true))
|
||||
.ignore();
|
||||
}
|
||||
|
||||
void Log::set_verbosity_level(int new_verbosity_level) {
|
||||
|
@ -61,8 +61,9 @@ Status Logging::set_current_stream(td_api::object_ptr<td_api::LogStream> 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<td_api::object_ptr<td_api::LogStream>> Logging::get_current_stream() {
|
||||
return td_api::make_object<td_api::logStreamEmpty>();
|
||||
}
|
||||
if (log_interface == &ts_log) {
|
||||
return td_api::make_object<td_api::logStreamFile>(file_log.get_path().str(), file_log.get_rotate_threshold());
|
||||
return td_api::make_object<td_api::logStreamFile>(file_log.get_path().str(), file_log.get_rotate_threshold(),
|
||||
file_log.get_redirect_stderr());
|
||||
}
|
||||
return Status::Error("Log stream is unrecognized");
|
||||
}
|
||||
|
@ -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()) {
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user