Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Make absl::InitializeLog safe to be called multiple times #1656

Open
janpfeifer opened this issue Apr 18, 2024 · 3 comments
Open

[Bug]: Make absl::InitializeLog safe to be called multiple times #1656

janpfeifer opened this issue Apr 18, 2024 · 3 comments

Comments

@janpfeifer
Copy link

Describe the issue

I don't really use absl::log, but a library I depend on uses it. It logs a bunch of "garbage" (unrelated to my project) that appears on the stderr. It includes the message:

WARNING: All log messages before absl::InitializeLog() is called are written to STDERR

Now I'm adding an earlier call in my program to absl::InitializeLog() in an attempt to eliminate the noise. But I noticed the library I use also eventually calls absl::InitializeLog().

Checking the documentation of absl::InitializeLog it's an error to call it more than once.

More generically, a project and one or more of its dependencies may need to call absl::InitializeLog, and there is no way to coordinate this across completely independent libraries -- ideally, libraries should never call it but ... it happens -- see Google's XLA as an example.

Hence my bug/feature request to make InitializeLog safe to be called multiple times -- a no-op if it has already been called.

ps.: I'm no expert on absl library, it's very likely there is nuance I'm missing.

Steps to reproduce the problem

Use two libraries where both call absl::InitializeLog()

What version of Abseil are you using?

Head.

What operating system and version are you using?

Ubuntu, various versions.

What compiler and version are you using?

clang

What build system are you using?

bazel

Additional context

No response

@janpfeifer
Copy link
Author

Any considerations on this one ? I bumped into the exact same issue again.

Apparently this is also a dependency, for similar reasons for GRPC Proposal to use Absl Logging.

@AustinSchuh
Copy link

Definitely not a great long term strategy since it is an internal API, but the following works in a single threaded environment:

if (!absl::log_internal::IsInitialized()) {
  absl::InitializeLog();
}

Maybe that suggests that should become a public API instead of internal? This bug got mentioned in the glog -> absl conversion for ceres-solver.

@janpfeifer
Copy link
Author

Well, if only I had access to all the code (of all dependencies) ... One could also create a wrapper to absl::InitiailzedLog that includes a std::call_once() to the original.

Alas, the issue is that the other libraries that I link call absl::InitailizeLog and I cannot change their code with any of the suggestions. Case in point, I'm not able to change the Abseil library to include such a test inside abls::InitializedLog directly 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants