Skip to content

Commit

Permalink
Update glog dependency.
Browse files Browse the repository at this point in the history
This should address a weird segmentation fault issue we have seen
during logging shutdown with older versions of the glog library.

I'm also disabling symlinks with SetLogSymlink(), to prevent the
duplicate "UNKNOWN.INFO" logfile. Doing so also helps with FreeBSD,
because there was an issue with std::filesystem::remove_all (used in our
unit test) which was fixed only recently, causing it to error out due to
the dangling symlinks: llvm/llvm-project#79540

Bug: b/352597329
Change-Id: Ie4faf2740e8eabc7f9dda9127f571084f1a510b3
  • Loading branch information
tdbhacks committed Jul 17, 2024
1 parent ec932ac commit 1709e24
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
8 changes: 4 additions & 4 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ http_archive(
)

http_archive(
name = "com_github_google_glog", # 2020-02-16
sha256 = "6fc352c434018b11ad312cd3b56be3597b4c6b88480f7bd4e18b3a3b2cf961aa",
strip_prefix = "glog-3ba8976592274bc1f907c402ce22558011d6fc5e",
url = "https://github.com/google/glog/archive/3ba8976592274bc1f907c402ce22558011d6fc5e.tar.gz",
name = "com_github_google_glog", # v0.7.1 / 2024-06-08
sha256 = "00e4a87e87b7e7612f519a41e491f16623b12423620006f59f5688bfd8d13b08",
strip_prefix = "glog-0.7.1",
url = "https://github.com/google/glog/archive/refs/tags/v0.7.1.tar.gz",
)

http_archive(
Expand Down
28 changes: 18 additions & 10 deletions kmsp11/util/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void GrpcLog(gpr_log_func_args* args) {
// Map gRPC severities to glog severities.
// gRPC severities: ERROR, INFO, DEBUG
// glog severities: FATAL, ERROR, WARNING, INFO
int severity;
google::LogSeverity severity;
switch (args->severity) {
// gRPC ERROR -> glog WARNING. gRPC errors aren't necessarily errors for
// us; see e.g. https://github.com/grpc/grpc/issues/22613. We should emit
Expand All @@ -61,7 +61,7 @@ void GrpcLog(gpr_log_func_args* args) {
class GlogSink : public absl::LogSink {
public:
virtual void Send(const absl::LogEntry& entry) override {
int severity;
google::LogSeverity severity;
switch (entry.log_severity()) {
case absl::LogSeverity::kError:
severity = google::GLOG_ERROR;
Expand Down Expand Up @@ -108,25 +108,33 @@ absl::Status InitializeLogging(std::string_view output_directory,
{google::GLOG_INFO, google::GLOG_WARNING, google::GLOG_ERROR,
google::GLOG_FATAL}) {
google::SetLogDestination(severity, "");
google::SetLogSymlink(severity, "");
}
} else {
// FATAL logs crash the program; emit these to standard error as well.
google::SetStderrLogging(google::GLOG_FATAL);

google::SetLogDestination(
google::GLOG_INFO,
absl::StrCat(output_directory, "/libkmsp11.log-").c_str());
if (!output_filename_suffix.empty()) {
google::SetLogDestination(
google::GLOG_INFO, absl::StrCat(output_directory, "/libkmsp11.log-",
output_filename_suffix, "-")
.c_str());
} else {
google::SetLogDestination(
google::GLOG_INFO,
absl::StrCat(output_directory, "/libkmsp11.log-").c_str());
}

// Disable symlink creation, which causes removal issues on FreeBSD.
// https://www.mail-archive.com/[email protected]/msg79713.html
google::SetLogSymlink(google::GLOG_INFO, "");

// Disable discrete log files for all levels but INFO -- they all still
// get logged to the INFO logfile.
for (google::LogSeverity severity :
{google::GLOG_WARNING, google::GLOG_ERROR, google::GLOG_FATAL}) {
google::SetLogDestination(severity, "");
}

if (!output_filename_suffix.empty()) {
google::SetLogFilenameExtension(
absl::StrCat(output_filename_suffix, "-").c_str());
google::SetLogSymlink(severity, "");
}
}

Expand Down

0 comments on commit 1709e24

Please sign in to comment.