abseil / abseil/abseil-cpp

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

オープン
#1,656 コメント 7 件 リアクション 7 件 担当者 0 名 GitHub で見る
主要言語
C++
スター
18.1k
フォーク
3.2k
平均マージ
20時間 36分
マージ済み PR(30日)
1

説明

### 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](https://github.com/openxla/xla/blob/6a257dc8805d11c11d25de557dadcb4e248d0849/xla/pjrt/c/pjrt_c_api_gpu.cc#L27C1-L29C1) 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_

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。