-
Notifications
You must be signed in to change notification settings - Fork 298
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 Obj-C #3351
base: release/3.2
Are you sure you want to change the base?
New Logging API Obj-C #3351
Conversation
Jenkins still failing only on |
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.
Looks pretty good. Not a close read but the parts I understand seem fine.
NSString* domainName = [self domainName: domain]; | ||
NSLog(@"CouchbaseLite %@ %@: %@", domainName, levelName, message); | ||
} | ||
|
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 this an attribute of the LiteCore interface? Should it be somewhere generic for use by all of the loggers?
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.
Not sure what you mean here? NSLog is an Obj-C native method to write to console only.
options = { | ||
.base_path = CBLStringBytes(logSink.directory), | ||
.log_level = (C4LogLevel)logSink.level, | ||
.max_rotate_count = static_cast<int32_t>(logSink.maxKeptFiles - 1), |
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.
Nice! I missed this...
CBLFileLogSink* file = self.file; | ||
CBLLogLevel fileLevel = file != nil ? file.level : kCBLLogLevelNone; | ||
|
||
CBLLogLevel callbackLevel = std::min(consoleLevel, customLevel); |
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.
At first I thought that the two vars were redundant... but this is really nice and readable.
Log domain. | ||
*/ | ||
typedef NS_OPTIONS(NSUInteger, CBLLogDomain) { | ||
kCBLLogDomainAll = 1 << 0 | 1 << 1 | 1 << 2 | 1 << 3 | 1 << 4, ///< All domains |
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.
Would this be better as
kCBLLogDomainDatabase | kCBLLogDomainQuery | ...
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.
I actually did that for Swift as the namings are way shorter. As you now mentioned it now, I will change that for readability for Obj-C as well. Thanks!
@@ -131,7 +131,7 @@ + (void) CBLInit { | |||
|
|||
/** Check and show warning if file logging is not configured. */ | |||
+ (void) checkFileLogging { | |||
if (!CBLDatabase.log.file.config) { | |||
if (!CBLDatabase.log.file.config || !CBLLogSinks.file) { |
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.
Only need !CBLLogSinks.file
.
} | ||
|
||
- (CBLLogDomain) domains { | ||
[CBLLogSinks checkLogApiVersion: LogAPIOld]; |
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.
This check is not in CBL_LOCK(self) while the others are.
CBLLogDomain domain = toCBLLogDomain(c4domain); | ||
|
||
CBLStringBytes c4msg(message); | ||
c4slog(c4domain, c4level, c4msg); |
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.
When looking at this, I think CBLFileLogSink should implement CBLLogSinkProtocol protocol so this can be moved to CBLFileLogSink's writeLogWithLevel() the same way as the console and custom log sink below.
} | ||
|
||
+ (void)checkLogApiVersion: (LogAPI)version { | ||
if (!isInitialized) |
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.
Not sure if it's required to be checked? Is there a case that the initialize() is not called and what will happen if not checking at all?
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.
needed to bypass 1 time (every test instance, at init) in order to be able to run both old and new tests. Should I just disable old tests (and remove this workaround)?
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.
I don't understand how this works. I don't see any code reset isInitialized. I think reset _vAPI to none would be enough for testing both old and new 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.
After reading the code, I have noticed that the isInitialized is reset to NO in CBLLogSinks's initialize. I couldn't find where that method is called in this PR. Also I think a better way is to have an internal method that the test can used to reset the API version.
Log domain. | ||
*/ | ||
typedef NS_OPTIONS(NSUInteger, CBLLogDomain) { | ||
kCBLLogDomainAll = 1 << 0 | 1 << 1 | 1 << 2 | 1 << 3 | 1 << 4, ///< All domains |
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.
Maybe 0xFF?
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.
I will go with Blake's recommendation of using kCBL...
. I don't really want to go for 0xFF as we only have 5 bits not 8. The first thought I have for using 0xFF is that if LiteCore adds a new domain, All
will include the new one as well and it can go unnoticed. As if we get a new domain from LiteCore we most probably going to need a singular entry as well for the new domain.
@@ -76,12 +76,11 @@ - (void) setUp { | |||
AssertNotNil(_wordDB); | |||
|
|||
_logger = [[CustomLogger alloc] init]; | |||
_logger.level = kCBLLogLevelInfo; | |||
CBLDatabase.log.custom = _logger; | |||
CBLLogSinks.custom = [[CBLCustomLogSink alloc] initWithLevel: kCBLLogLevelInfo logSink: _logger]; |
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.
I don't remember why we have a custom logger set for the VectorSearchTest?
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 is used to check for Untrained index; queries may be slow
. I remember a conversation about this vaguely, but I wasn't sure enough to remove such checks. So I kept the custom logger in place. Do we still want to check for untrained? If not, I will remove this logger altogether.
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.
I see. Let's keep it for now I think.
_backupConsoleDomain = CBLDatabase.log.console.domains; | ||
_backup = [[CBLFileLogSink alloc] initWithLevel: CBLLogSinks.file.level directory: logFileDirectory]; | ||
_backupConsoleLevel = CBLLogSinks.console.level; | ||
_backupConsoleDomain = CBLLogSinks.console.domain; |
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.
The backup could just be some thing like this:
_file = CBLLogSinks.file;
_console = CBLLogSinks.console;
I think after all the only backup is the console log sink for the case that we have enabled the console log sink for debugging purpose.
@implementation LogTestOld { | ||
FileLoggerBackup* _backup; | ||
CBLLogLevel _backupConsoleLevel; | ||
CBLLogDomain _backupConsoleDomain; |
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.
I think, there is no need to backup anything for testing the old API. The backup is for the case that we enable a console log in the base test case for debugging purpose.
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.
How do you handle the new and the old API are both used as the new logging tests and the old logging tests will be both run? Doesn't an exception will be thrown?
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.
How do you handle the new and the old API are both used as the new logging tests and the old logging tests will be both run? Doesn't an exception will be thrown?
Both suites run one after the other. I've used isInitialized
to allow this only once, for the old custom logger needed in the old tests. Without that check, it will throw indeed
LogTestOld
, which will be removed altogether with the old api, when time comes