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 5 commits into
base: master
Choose a base branch
from

Conversation

velicuvlad
Copy link
Contributor

@velicuvlad velicuvlad commented Aug 19, 2024

  1. each LogLevel has been matched with a type of os_log - same behaviour as .NET

  2. Additionally, os_log categories, mapped to DomainLevels, will now be created at the time logging is initialised, on open/create db. And every CBL log, with its specific domain, will now appear in its own corresponding category in console logs.

image

  1. There are just a couple of NSLogs only for DEBUG, which for I've decided that the os_log object to be created dynamically as we dont care that much and based on those messages, there's an issue somewhere else anyway. The production ones will be generated as mentioned above.

  2. Removed CBLLog+Admin.h as is no longer needed.

@velicuvlad velicuvlad requested a review from pasin August 27, 2024 14:44
@pasin
Copy link
Contributor

pasin commented Aug 28, 2024

For some reason, a test was hang for 14 hour. I just canceled it.

@@ -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

@@ -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)

@@ -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?

@@ -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");
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?

Objective-C/CBLDatabase.mm Outdated Show resolved Hide resolved
Objective-C/CBLLog.mm Outdated Show resolved Hide resolved
to be used with any additional in-code logging

+ (os_log_t) internalLogger {
if(!logger){
logger = os_log_create("com.couchbase.lite.ios", "Log");
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not thread safe. You can use dispatch_once which is thread-safe to make it singleton.

- (void) initializeOSLogDomains {
osLogDictionary = [NSMutableDictionary dictionary];

osLogDictionary[@(kCBLLogDomainDatabase)] = os_log_create("com.couchbase.lite.ios", "Database");
Copy link
Contributor

Choose a reason for hiding this comment

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

We should also get "com.ouchbase.lite.ios" from the framework bundle identifier instead of hard code the string here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants