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
14 changes: 14 additions & 0 deletions Objective-C/CBLConsoleLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ @implementation CBLConsoleLogger
@synthesize level=_level, domains=_domains;

static NSMutableDictionary<NSNumber *, os_log_t>* osLogDictionary;
static os_log_t logger;

- (instancetype) initWithLogLevel: (CBLLogLevel)level {
self = [super init];
Expand Down Expand Up @@ -79,4 +80,17 @@ - (void) initializeOSLogDomains {
osLogDictionary[@(kCBLLogDomainListener)] = os_log_create("com.couchbase.lite.ios", "Listener");
#endif
}

+ (os_log_t) internalLogger {
if(!logger){
logger = os_log_create("com.couchbase.lite.ios", "Log");
velicuvlad marked this conversation as resolved.
Show resolved Hide resolved
}
return logger;
}

+ (void) logWithInternal: (NSString*)message {
logger = [self internalLogger];
os_log(logger, "%@", message);
}

@end
3 changes: 1 addition & 2 deletions Objective-C/CBLDatabase.mm
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ to be done in CBLInit()which is called only once when the first CBLDatabase is c
*/
+ (void) initialize {
if (self == [CBLDatabase class]) {
os_log_t logger = os_log_create("com.couchbase.lite.ios", "UserAgent");
os_log(logger, "%@", [CBLVersion userAgent]);
[CBLConsoleLogger logWithInternal:[CBLVersion userAgent]];
// Initialize logging
CBLAssertNotNil(CBLLog.sharedInstance);
}
Expand Down
4 changes: 2 additions & 2 deletions Objective-C/CBLLog.mm
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ - (instancetype) initWithDefault {
#ifdef DEBUG
// Check if user overrides the default callback log level:
NSString* userLogLevel = [NSUserDefaults.standardUserDefaults objectForKey: @"CBLLogLevel"];
oslogger = os_log_create("com.couchbase.lite.ios", "DebugBuild");
if (userLogLevel) {
callbackLogLevel = string2level(userLogLevel);
}
if (callbackLogLevel != kC4LogWarning) {
os_log(oslogger, "CouchbaseLite minimum log level is %s", kLevelNames[callbackLogLevel]);
NSString* message = [NSString stringWithFormat: @"CouchbaseLite minimum log level is %s", kLevelNames[callbackLogLevel]];
[CBLConsoleLogger logWithInternal: message];
}
#endif

Expand Down
4 changes: 4 additions & 0 deletions Objective-C/Internal/CBLLog+Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ NS_ASSUME_NONNULL_BEGIN

- (instancetype) initWithLogLevel: (CBLLogLevel)level;

+ (os_log_t) internalLogger;

+ (void) logWithInternal: (nonnull NSString*)message;

@end

@interface CBLFileLogger ()
Expand Down
Loading