abseil / abseil/abseil.github.io

Logging documentation should explain InitializeLog and SetStderrThreshold

Aberta
#467 1 comentário 13 reações 1 responsável Reivindicada por @derekmauro Ver no GitHub
Linguagem predominante
HTML
Estrelas
169
Forks
124
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

### Describe the issue

I developed a C++ service that uses Abseil logging and I could not figure out why my log messages with INFO severity did not appear in the Linux systemd journal. I reviewed https://abseil.io/docs/cpp/guides/logging and its information about log severity, and I tried defining ABSL_MIN_LOG_LEVEL to 0, but it did not help.

I had previously added a call to `absl::InitializeLog()` (which is not explained in that docs page) in order to eliminate this warning from my server's output: `WARNING: All log messages before absl::InitializeLog() is called are written to STDERR`. I eventually figured out to my dismay that removing this call to `InitializeLog()` was all I needed to fix my problem: INFO log messages now appeared in the journal output.

I eventually stumbled upon an [example](https://github.com/google/sandboxed-api/blob/main/sandboxed_api/examples/zlib/main_zlib.cc#L43) that showed me how to properly initialize Abseil logging by calling `absl::SetStderrThreshold()` in addition to `InitializeLog()`. That led me to [globals.h](https://github.com/abseil/abseil-cpp/blob/master/absl/log/globals.h#L91) which also explains that `--minloglevel` can be used to control this behavior.

I feel misled since Abseil *told me* to call `InitializeLog()`, but it didn't tell me that I might also need to call `SetStderrThreshold()`. I did the right thing and read the documentation, but none of `InitializeLog()`, `SetStderrThreshold()` or `--minloglevel` are mentioned at all at https://abseil.io/docs/cpp/guides/logging. It would be great if this documentation could be improved, it would have saved me quite a bit of troubleshooting.

### Steps to reproduce the problem

Write a C++ service with a main that begins with:

```
int main(int argc, char **argv) {
absl::InitializeLog();
absl::ParseCommandLine(argc, argv);
```

Add some `LOG(INFO)` and `LOG(ERROR)` messages in the service. Build it and register the service with systemd on a Linux system. Start the service then run `journalctl -u `. Observe that the log messages with INFO severity do not appear in the journal, but the messages with ERROR severity do.

Add a call to `absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);` at the start of `main()`, rebuild and restart the service and observe that now INFO log messages appear in the journal.

### What version of Abseil are you using?

https://github.com/abseil/abseil-cpp/archive/1adf896ec842bd9788a1bbede94a33e1402b8ecb.tar.gz

### What operating system and version are you using?

Linux ARM64

### What compiler and version are you using?

gcc

### What build system are you using?

Bazel 6.0.0

### Additional context

_No response_

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.