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

Logging documentation should explain InitializeLog and SetStderrThreshold #467

Open
pjh opened this issue Nov 16, 2023 · 0 comments
Open

Comments

@pjh
Copy link

pjh commented Nov 16, 2023

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 that showed me how to properly initialize Abseil logging by calling absl::SetStderrThreshold() in addition to InitializeLog(). That led me to globals.h 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 <service-name>. 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

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

1 participant