-
Notifications
You must be signed in to change notification settings - Fork 73
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
base: master
Are you sure you want to change the base?
New logging API #2194
Conversation
5d98e1e
to
b081c30
Compare
Code Coverage Results:
|
- 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".
The code got a lot cleaner when I replaced the three parallel arrays with a class `LogFile`.
7d5d573
to
ba1b80c
Compare
The logging code no longer has to create and tear down a stringstream every time.
ba1b80c
to
3a65c31
Compare
It was possible for the timestamps to differ by more than the last 3 digits, if the timestamp inside the file was written just after a new second started; i.e. the filename was constructed at time 12345678999 and the first log was written at 12345679001.
Apparently on Windows "%p" does not print a "0x" before the address.
e91f1f9
to
0b723fc
Compare
The Windows build failed in Jenkins, but I can't find an error anywhere in the full build log -- just thousands of linker warnings. Any idea, @borrrden ? It just ends with:
|
} | ||
|
||
void c4log_removeObserver(C4LogObserver* observer) noexcept { | ||
LogObserver::remove(reinterpret_cast<LogObserver*>(observer)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the reinterpret_cast "toInternal?"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, it could be changed to a call to toInternal()
.
#pragma mark - INITIALIZATION: | ||
|
||
LogDomain::LogDomain(const char* name, LogLevel level, bool internName) | ||
: _level(level), _name(internName ? strdup(name) : name), _observers(new LogObservers) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where is "strdup(name)" freed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It isn't! Log domains are never freed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then, we probably don't need the extra argument, internName.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most log domains are declared as globals and have names that are string constants. Those don't need to be copied. The internName flag is only for domains created dynamically via the C API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then, perhaps strdup at the place where C API is called.
API:
#include c4log.h
statements.c4log_initConsole()
adds an observer that logs to the console. CppTests and C4Tests call it at startup.Implementation:
LogObserver
is used to receive log messages.LogFiles
andLogCallback
.Review notes: