Skip to content

Simplify logger setup#1904

Merged
ischoegl merged 2 commits intoCantera:mainfrom
speth:global-logger
Jun 8, 2025
Merged

Simplify logger setup#1904
ischoegl merged 2 commits intoCantera:mainfrom
speth:global-logger

Conversation

@speth
Copy link
Copy Markdown
Member

@speth speth commented Jun 7, 2025

Changes proposed in this pull request

  • Make logging global rather than thread-specific. Thread-specific logging is difficult to initialize when the user doesn't
    control thread creation, as in environments like .NET.
  • Fix ownership handling of Logger objects. The Application instance takes ownership of these objects. Changing
    the interface to use unique_ptr reflects this and prevents errors like the double-delete during application teardown that was previously occurring (as identified by @burkenyo).

Checklist

  • The pull request includes a clear description of this code change
  • Commit messages have short titles and reference relevant issues
  • Build passes (scons build & scons test) and unit tests address code coverage
  • Style & formatting of contributed code follows contributing guidelines
  • The pull request is ready for review

speth added 2 commits June 7, 2025 14:00
Thread-specific logging is difficult to initialize when the user doesn't
control thread creation, as in environments like .NET.
The Application instance takes ownership of these objects. Changing
the interface to use unique_ptr reflects this and prevents errors like
the double-delete during application teardown that was previously
occurring.
@codecov
Copy link
Copy Markdown

codecov bot commented Jun 7, 2025

Codecov Report

Attention: Patch coverage is 72.72727% with 6 lines in your changes missing coverage. Please review.

Project coverage is 74.10%. Comparing base (929c3d6) to head (dbe2fa1).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/base/application.cpp 84.61% 2 Missing ⚠️
src/base/global.cpp 50.00% 2 Missing ⚠️
src/clib/ct.cpp 0.00% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1904   +/-   ##
=======================================
  Coverage   74.09%   74.10%           
=======================================
  Files         444      444           
  Lines       55516    55514    -2     
  Branches     9128     9128           
=======================================
+ Hits        41137    41138    +1     
+ Misses      11287    11285    -2     
+ Partials     3092     3091    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@burkenyo
Copy link
Copy Markdown
Contributor

burkenyo commented Jun 7, 2025

Some background here: In the .NET assembly, I want to use a module initializer to set the log callback. A module initializer ensures some initialization is run before any user code. In order to achieve this initialization previously, I was using a static constructor in the the Application class. This has two drawbacks:

  1. All user access to Cantera through the .NET interface has to be routed through the Application class to ensure the static constructor is run.
  2. The runtime has to emit runtime checks on each access of the Application class to ensure the static constructor has run. (This can be seen by the lack of the `Not so for simple static field initializers, which are prevented from referencing other fields. See https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1810)

The second one will likely only cause a minimal case in every-day use, but the first requires a very awkward library design.

When switching to a module initializer, I found that logging tests started failing. It turns out this was because the runtime was running the initializer on a different thread from the one the tests were running on. Thus, the logCallback was not getting invoked because it was only applied to the thread the on which the initializer run. By applying this commits on this PR, the test started working again.

Copy link
Copy Markdown
Contributor

@burkenyo burkenyo left a comment

Choose a reason for hiding this comment

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

Verified these changes with @speth

Copy link
Copy Markdown
Member

@ischoegl ischoegl left a comment

Choose a reason for hiding this comment

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

Thanks @speth ... this looks all good to me!

While this barely touches the inconsistent writelog nomenclature (we use camelCase in related definitions), this isn't worth addressing.

@ischoegl ischoegl merged commit b308592 into Cantera:main Jun 8, 2025
50 of 51 checks passed
@ischoegl
Copy link
Copy Markdown
Member

ischoegl commented Jun 8, 2025

Fwiw, the PR appears to have broken the post-merge Cython test, although it’s never clear whether it’ll wash out as the pre-release progresses
https://github.com/Cantera/cantera/actions/runs/15519808401/job/43691507167

@speth
Copy link
Copy Markdown
Member Author

speth commented Jun 8, 2025

From my reading of that error log, I don't think it's anything in this PR that broke that test, but a change in the pre-release Cython. It is a bit concerning though, if there are changes in Cython that are going to break our somewhat non-standard practice of compiling multiple Cython source files and linking them as a single extension module.

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