Skip to content

feat: file logging and configurable minimum log level#6

Merged
jpnurmi merged 3 commits into
getsentryfrom
jpnurmi/feat/log-file
Apr 20, 2026
Merged

feat: file logging and configurable minimum log level#6
jpnurmi merged 3 commits into
getsentryfrom
jpnurmi/feat/log-file

Conversation

@jpnurmi

@jpnurmi jpnurmi commented Apr 17, 2026

Copy link
Copy Markdown
Collaborator

File logging and configurable minimum log level for sentry-native/crashpad:

Two additions to mini_chromium's logging:

  1. LOG_TO_FILE destination. Implements the previously stubbed LOG_TO_FILE destination and adds a simplified base::OpenFile() helper (after upstream Chromium's helper of the same name). Callers pass the path via LoggingSettings::log_file_path. The file is opened lazily for appending on the first emitted message and held by a std::unique_ptr<FILE> with a silent closer, so an fclose failure during static destruction cannot re-enter Flush() and deadlock on the file lock. File state (lock, path, handle, and an enabled flag) is grouped in a file-scope LogFile struct; an empty path or a failed open is handled by clearing enabled, so a transient open failure cannot clobber a concurrent InitLogging(). Concurrent LOG calls are serialized with a base::Lock.

  2. Configurable minimum log level. Replaces the hardcoded GetMinLogLevel() with a runtime-configurable value. Adds SetMinLogLevel() and a min_log_level field on LoggingSettings (applied by InitLogging). Default remains LOG_INFO, so existing callers are unaffected.

g_logging_destination and g_min_log_level are std::atomic so reads on the LOG hot path don't need the file lock and writes from InitLogging / SetMinLogLevel don't race concurrent readers.

See also:

Comment thread base/logging.h
Comment thread base/logging.cc
Comment thread base/logging.cc Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 82b99ca. Configure here.

Comment thread base/logging.cc Outdated
Comment thread base/logging.cc
@jpnurmi jpnurmi force-pushed the jpnurmi/feat/log-file branch from 82b99ca to edd9975 Compare April 17, 2026 20:13
Comment thread base/logging.cc Outdated
Two additions to mini_chromium's logging:

1. LOG_TO_FILE destination. Implements the previously stubbed
   LOG_TO_FILE destination and adds a simplified base::OpenFile()
   helper (after upstream Chromium's helper of the same name).
   Callers pass the path via LoggingSettings::log_file_path. The
   file is opened lazily for appending on the first emitted message
   and held by a std::unique_ptr<FILE> with a silent closer so an
   fclose failure during static destruction cannot re-enter Flush()
   and deadlock on the file lock. File state (lock, path, handle,
   and an `enabled` flag) is grouped in a file-scope LogFile struct;
   an empty path or a failed open is handled by clearing `enabled`,
   so a transient open failure cannot clobber a concurrent
   InitLogging(). Concurrent LOG calls are serialized with a
   base::Lock.

2. Configurable minimum log level. Replaces the hardcoded
   GetMinLogLevel() with a runtime-configurable value. Adds
   SetMinLogLevel() and a min_log_level field on LoggingSettings
   (applied by InitLogging). Default remains LOG_INFO, so existing
   callers are unaffected.

g_logging_destination and g_min_log_level are std::atomic so reads
on the LOG hot path don't need the file lock and writes from
InitLogging / SetMinLogLevel don't race concurrent readers.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

@JoshuaMoelans JoshuaMoelans left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few open questions left, but otherwise LGTM!

Comment thread base/files/file_util.cc
Comment thread base/logging.cc Outdated
Comment thread base/logging.cc
jpnurmi and others added 2 commits April 20, 2026 11:05
The source file was omitted when file_util.cc was introduced alongside
file_util.h. CMake already lists both.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment thread base/logging.cc
@jpnurmi jpnurmi merged commit 64339ac into getsentry Apr 20, 2026
7 checks passed
@jpnurmi jpnurmi deleted the jpnurmi/feat/log-file branch April 20, 2026 09:57
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.

3 participants