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 2 commits
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
3 changes: 2 additions & 1 deletion Objective-C/CBLConsoleLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ - (void) logWithLevel: (CBLLogLevel)level domain: (CBLLogDomain)domain message:

NSString* levelName = CBLLog_GetLevelName(level);
NSString* domainName = CBLLog_GetDomainName(domain);
NSLog(@"CouchbaseLite %@ %@: %@", domainName, levelName, message);
os_log_t log = os_log_create("CouchbaseLite", "OSDebug");
Copy link
Contributor

Choose a reason for hiding this comment

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

What is "OSDebug"? Where does it appear in the log?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed to com.couchbase.lite.ios and the category now represents a domain (CBL)

os_log(log, "CouchbaseLite %@ %@: %@", domainName, levelName, message);
Copy link
Contributor

Choose a reason for hiding this comment

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

There are different types of os_log function based on the log level. I think we should use those functions. What is .NET using?

}

@end
3 changes: 2 additions & 1 deletion Objective-C/CBLDatabase.mm
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ to be done in CBLInit()which is called only once when the first CBLDatabase is c
*/
+ (void) initialize {
if (self == [CBLDatabase class]) {
NSLog(@"%@", [CBLVersion userAgent]);
os_log_t log = os_log_create("CouchbaseLite", "OSLogging");
Copy link
Contributor

Choose a reason for hiding this comment

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

What is "OSLogging"? Where does it appear in the log?

os_log(log, "%@", [CBLVersion userAgent]);
// Initialize logging
CBLAssertNotNil(CBLLog.sharedInstance);
}
Expand Down
1 change: 1 addition & 0 deletions Objective-C/CBLLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
//

#import <Foundation/Foundation.h>
#import <os/log.h>

@protocol CBLLogger;
@class CBLConsoleLogger;
Expand Down
5 changes: 3 additions & 2 deletions Objective-C/CBLLog.mm
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,12 @@ - (instancetype) initWithDefault {
#ifdef DEBUG
// Check if user overrides the default callback log level:
NSString* userLogLevel = [NSUserDefaults.standardUserDefaults objectForKey: @"CBLLogLevel"];
os_log_t log = os_log_create("CouchbaseLite", "OSLogging");
if (userLogLevel) {
callbackLogLevel = string2level(userLogLevel);
}
if (callbackLogLevel != kC4LogWarning) {
NSLog(@"CouchbaseLite minimum log level is %s", kLevelNames[callbackLogLevel]);
os_log(log, "CouchbaseLite minimum log level is %s", kLevelNames[callbackLogLevel]);
}
#endif

Expand Down Expand Up @@ -190,7 +191,7 @@ - (instancetype) initWithDefault {
C4LogDomain domain = c4log_getDomain(domainName, true);
C4LogLevel level = string2level(defaults[key]);
c4log_setLevel(domain, level);
NSLog(@"CouchbaseLite logging to %s domain at level %s", domainName, kLevelNames[level]);
os_log(log, "CouchbaseLite logging to %s domain at level %s", domainName, kLevelNames[level]);
}
}
#endif
Expand Down
3 changes: 2 additions & 1 deletion Objective-C/Tests/Util/CBLWordEmbeddingModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ - (CBLDictionary*) predict: (CBLDictionary*)input {
NSString* inputWord = [input stringForKey: @"word"];

if (!inputWord) {
NSLog(@"No word input !!!");
os_log_t log = os_log_create("CouchbaseLite", "OSLogging");
os_log(log, "No word input !!!");
Copy link
Contributor

Choose a reason for hiding this comment

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

For this one we can use NSLog, I guessed or change it to assertion instead of logging.

Copy link
Contributor Author

@velicuvlad velicuvlad Aug 28, 2024

Choose a reason for hiding this comment

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

changed to assert

return nil;
}

Expand Down
Loading