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

New logging API #2194

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

New logging API #2194

wants to merge 12 commits into from

Conversation

snej
Copy link
Collaborator

@snej snej commented Dec 16, 2024

API:

  • Implemented new C4LogObserver API as described in the design doc.
  • It was necessary to change some includes: c4Base.h no longer includes c4Log.h, it's now the other way around. Platform code may need to add some explicit #include c4log.h statements.
  • The existing API for logging callbacks and files still exists, but should eventually be deprecated / removed.
  • There is no logging by default: something has to register an observer. c4log_initConsole() adds an observer that logs to the console. CppTests and C4Tests call it at startup.

Implementation:

  • Lots of refactoring of logging code. New class LogObserver is used to receive log messages.
  • File and callback logging are implemented as subclasses LogFiles and LogCallback.

Review notes:

  • The first three commits are just some preparations, moving the c4log code and moving the logging files to a new dir.
  • "Implemented LogObserver. Refactored logging code." is the internal implementation, adding the LogObserver class and moving the file and callback logging code into implementations of it.
  • "Implemented C4LogObserver [API]" implements the C API for LogObserver.
  • "Heavily refactored LogFiles" is where I succumbed to the unnecessary task of cleaning up the file logging code. I merged the three parallel arrays (of file streams, log encoders and rotation counts) into an array of a new LogFile class, and most of the logic went into the new class.
  • "Reimplemented old c4log API using new one" simplifies the implementation of the old C file/callback log APIs by calling the C LogObserver APIs.
  • "c4Tests' logging stub should preserve the domain" just fixes a small mistake in the C4Tests logging glue: it should preserve the log domain instead of routing the logs to the default logger. This also eliminates the lint warning that the method could be made static.

@snej snej force-pushed the feature/log-observer branch 3 times, most recently from 7708a61 to cf107a9 Compare December 16, 2024 23:03
snej added 5 commits December 16, 2024 15:03
- c4Log.h now includes c4Base.h, not the other way around
  (this is because the new log API requires C4Timestamp)
- Added includes to sources files that now need it
- Moved c4Log implementation out of c4Base.cc to new c4Log.cc
Old API is still present but "semi-deprecated".
@snej snej force-pushed the feature/log-observer branch 2 times, most recently from 5be1ef6 to aaff463 Compare December 17, 2024 23:06
The code got a lot cleaner when I replaced the three parallel arrays
with a class `LogFile`.
@snej snej force-pushed the feature/log-observer branch from 1785311 to 5d98e1e Compare December 18, 2024 20:24
@snej snej force-pushed the feature/log-observer branch from 5d98e1e to b081c30 Compare December 18, 2024 20:33
@cbl-bot
Copy link

cbl-bot commented Dec 18, 2024

Code Coverage Results:

Type Percentage
branches 66.19
functions 78.56
instantiations 70.78
lines 77.59
regions 73.39

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