log_file_header: add option to disable log file headers. (#850)

Log lines can be customized for parsing by an external tool.

To simplify such customization and parsing, there should be an option to
customize the file header, or at least to disable adding it.
This commit is contained in:
Andrei Polushin 2022-08-13 16:10:00 +07:00 committed by GitHub
parent a1b6164ef1
commit 1fb4cc1958
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 27 deletions

View File

@ -455,6 +455,9 @@ DECLARE_bool(colorlogtostderr);
// stderr in addition to log files.
DECLARE_int32(stderrthreshold);
// Set whether the log file header should be written upon creating a file.
DECLARE_bool(log_file_header);
// Set whether the log prefix should be prepended to each line of output.
DECLARE_bool(log_prefix);

View File

@ -146,6 +146,8 @@ DEFINE_int32(stderrthreshold,
GLOG_DEFINE_string(alsologtoemail, "",
"log messages go to these email addresses "
"in addition to logfiles");
GLOG_DEFINE_bool(log_file_header, true,
"Write the file header at the start of each log file");
GLOG_DEFINE_bool(log_prefix, true,
"Prepend the log prefix to the start of each log line");
GLOG_DEFINE_bool(log_year_in_prefix, true,
@ -1244,6 +1246,7 @@ void LogFileObject::Write(bool force_flush,
}
// Write a header message into the log file
if (FLAGS_log_file_header) {
ostringstream file_header_stream;
file_header_stream.fill('0');
file_header_stream << "Log file created at: "
@ -1274,6 +1277,7 @@ void LogFileObject::Write(bool force_flush,
file_length_ += header_len;
bytes_since_flush_ += header_len;
}
}
// Write to LOG file
if ( !stop_writing ) {