Skip to content

Capture and emit function name in log messages#2080

Closed
chenBright wants to merge 1 commit into
abseil:masterfrom
chenBright:log_functin_name
Closed

Capture and emit function name in log messages#2080
chenBright wants to merge 1 commit into
abseil:masterfrom
chenBright:log_functin_name

Conversation

@chenBright

Copy link
Copy Markdown

This PR adds the function name (__func__) to absl log messages, making it appear in the log prefix right after the line number, which gives a more precise callsite identifier.

# before
I0102 03:04:05.678900     451 foo.cc:1234] RAW: hello world

# after
I0102 03:04:05.678900     451 foo.cc:1234 MyFunc] RAW: hello world

@google-cla

google-cla Bot commented Jun 12, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@chenBright

Copy link
Copy Markdown
Author

I have signed the CLA.

@derekmauro

Copy link
Copy Markdown
Member

Thanks for your interest in Abseil. Unfortunately there is no chance we can accept this, even though the code might be technically fine.

The major reasons why we can't accept this are:

  1. Abseil's primary purpose is to be used as a dependency by Google's open source C++ projects. Since the logging library dates back to the early 2000s, the format has ossified. No doubt there is code that is parsing the output. While parsing the output of a logging library is certainly a bad idea, we don't have time to fix that.
  2. Adding function names is going to cause binary bloat. This matters a lot when binaries consist of many thousands of files. This is actually one of the reasons absl::SourceLocation does not guarantee to expose the function name. For identifying the call site, it is mostly a nice to have. The filename and line number should be sufficient. If you want to add a function name, you can do LOG(INFO) << __func__.

@derekmauro derekmauro closed this Jun 15, 2026
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

Successfully merging this pull request may close these issues.

2 participants