Skip to content

Commit

Permalink
Update styleguide documentation for logging
Browse files Browse the repository at this point in the history
This CL adds more context (rationale). This CL points out that logging
does not help with the common use case of crash debugging.

Change-Id: I21373b5c02bf397eb6aee3c24960908d9b558dd2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5260687
Reviewed-by: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Erik Chen <erikchen@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1255429}
  • Loading branch information
erikchen authored and Chromium LUCI CQ committed Feb 2, 2024
1 parent c2fa0d5 commit cd92bd2
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions styleguide/c++/c++.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,13 @@ named using `snake_case()`. Virtual functions should never be declared this way.

## Logging

Remove most logging calls before checking in. Unless you're adding temporary
logging to track down a specific bug, and you have a plan for how to collect
the logged data from user machines, you should generally not add logging
statements.
Remove all logging before checking in code. The exception is temporary logging
to track down a specific bug. This should be a rare exception, and you should
have a plan for how to manually collect/use the logged data. Afterwards you
should remove the logging. Note that logs are not present in crashes. Use
`base::debug::ScopedCrashKeyString`
([link](https://chromium.googlesource.com/chromium/src/+/main/base/debug/crash_logging.h))
for that.

For the rare case when logging needs to stay in the codebase for a while,
prefer `DVLOG(1)` to other logging methods. This avoids bloating the release
Expand All @@ -126,6 +129,14 @@ arguments:
while supplying a wildcard like `*bar/baz*` will affect all files with
`bar/baz` in their full pathnames.

Rationale:
* Logging is expensive: binary size, runtime.
* Logging quickly loses utility as more components emit logs: too much noise,
not enough signal.
* Logging is often used to document impossible edge cases which should be
enforced with CHECKs. The latter makes it easier to reason about the code, and
can result in more performant binaries.

## Platform-specific code

To `#ifdef` code for specific platforms, use the macros defined in
Expand Down

0 comments on commit cd92bd2

Please sign in to comment.