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

CBL-5396: Use os_log instead of NSLog for Console Log #3323

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions Objective-C/CBLConsoleLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

@implementation CBLConsoleLogger

@synthesize level=_level, domains=_domains;
@synthesize level=_level, domains=_domains, sysID=_sysID;

static NSMutableDictionary<NSNumber *, os_log_t>* osLogDictionary;
static os_log_t logger;
Expand All @@ -32,6 +32,7 @@ - (instancetype) initWithLogLevel: (CBLLogLevel)level {
if (self) {
_level = level;
_domains = kCBLLogDomainAll;
_sysID = [[NSBundle mainBundle] bundleIdentifier];
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if this is right as it think it will return the bundle identifier of the app not the framework. What is the value when you run the test? If this returns bundle id of the app, you may try to get the bundle id from one of the classes such as CBLConsoleLogger itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you are right, will fix

[self initializeOSLogDomains];
}
return self;
Expand Down Expand Up @@ -70,21 +71,22 @@ static os_log_type_t osLogTypeForLevel(CBLLogLevel level) {

- (void) initializeOSLogDomains {
osLogDictionary = [NSMutableDictionary dictionary];
osLogDictionary[@(kCBLLogDomainDatabase)] = os_log_create("com.couchbase.lite.ios", "Database");
osLogDictionary[@(kCBLLogDomainQuery)] = os_log_create("com.couchbase.lite.ios", "Query");
osLogDictionary[@(kCBLLogDomainReplicator)] = os_log_create("com.couchbase.lite.ios", "Replicator");
osLogDictionary[@(kCBLLogDomainNetwork)] = os_log_create("com.couchbase.lite.ios", "Network");

osLogDictionary[@(kCBLLogDomainDatabase)] = os_log_create([self.sysID UTF8String], "Database");
osLogDictionary[@(kCBLLogDomainQuery)] = os_log_create([self.sysID UTF8String], "Query");
osLogDictionary[@(kCBLLogDomainReplicator)] = os_log_create([self.sysID UTF8String], "Replicator");
osLogDictionary[@(kCBLLogDomainNetwork)] = os_log_create([self.sysID UTF8String], "Network");

#ifdef COUCHBASE_ENTERPRISE
osLogDictionary[@(kCBLLogDomainListener)] = os_log_create("com.couchbase.lite.ios", "Listener");
osLogDictionary[@(kCBLLogDomainListener)] = os_log_create([self.sysID UTF8String], "Listener");
#endif
}

+ (os_log_t) internalLogger {
if(!logger){
logger = os_log_create("com.couchbase.lite.ios", "Log");
}
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
logger = os_log_create("com.couchbase.lite.ios", "Internal");
Copy link
Contributor

Choose a reason for hiding this comment

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

This one still uses the hardcode string, "com.couchbase.lite.ios".

});
return logger;
}

Expand Down
2 changes: 1 addition & 1 deletion Objective-C/CBLDatabase.mm
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ to be done in CBLInit()which is called only once when the first CBLDatabase is c
*/
+ (void) initialize {
if (self == [CBLDatabase class]) {
[CBLConsoleLogger logWithInternal:[CBLVersion userAgent]];
// Initialize logging
CBLAssertNotNil(CBLLog.sharedInstance);
}
Expand All @@ -124,6 +123,7 @@ + (void) initialize {
+ (void) CBLInit {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[CBLConsoleLogger logWithInternal:[CBLVersion userAgent]];
[self checkFileLogging];
});
}
Expand Down
2 changes: 2 additions & 0 deletions Objective-C/Internal/CBLLog+Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ NS_ASSUME_NONNULL_BEGIN

@interface CBLConsoleLogger ()

@property (nonatomic, readonly) NSString* sysID;

- (instancetype) initWithLogLevel: (CBLLogLevel)level;

+ (os_log_t) internalLogger;
Expand Down