From ed9ecfbb10d784b51576cce1a466050a0b3e49b6 Mon Sep 17 00:00:00 2001 From: Vlad Velicu Date: Mon, 19 Aug 2024 17:15:27 +0100 Subject: [PATCH 01/10] move NSLog to os_log --- Objective-C/CBLConsoleLogger.m | 3 ++- Objective-C/CBLDatabase.mm | 3 ++- Objective-C/CBLLog.h | 1 + Objective-C/CBLLog.mm | 5 +++-- Objective-C/Tests/Util/CBLWordEmbeddingModel.m | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Objective-C/CBLConsoleLogger.m b/Objective-C/CBLConsoleLogger.m index eef775304..b948d4d8d 100644 --- a/Objective-C/CBLConsoleLogger.m +++ b/Objective-C/CBLConsoleLogger.m @@ -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); } @end diff --git a/Objective-C/CBLDatabase.mm b/Objective-C/CBLDatabase.mm index 8cfc9b42f..b9038a540 100644 --- a/Objective-C/CBLDatabase.mm +++ b/Objective-C/CBLDatabase.mm @@ -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"); + os_log(log, "%@", [CBLVersion userAgent]); // Initialize logging CBLAssertNotNil(CBLLog.sharedInstance); } diff --git a/Objective-C/CBLLog.h b/Objective-C/CBLLog.h index 26e389c3b..8a9cb0170 100644 --- a/Objective-C/CBLLog.h +++ b/Objective-C/CBLLog.h @@ -18,6 +18,7 @@ // #import +#import @protocol CBLLogger; @class CBLConsoleLogger; diff --git a/Objective-C/CBLLog.mm b/Objective-C/CBLLog.mm index c78c41b9b..389f7f5cf 100644 --- a/Objective-C/CBLLog.mm +++ b/Objective-C/CBLLog.mm @@ -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 @@ -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[callbackLogLevel]); } } #endif diff --git a/Objective-C/Tests/Util/CBLWordEmbeddingModel.m b/Objective-C/Tests/Util/CBLWordEmbeddingModel.m index b01e3d4c4..e891b4fc0 100644 --- a/Objective-C/Tests/Util/CBLWordEmbeddingModel.m +++ b/Objective-C/Tests/Util/CBLWordEmbeddingModel.m @@ -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 !!!"); return nil; } From 9a03db9d23907745f75dde5c59f195bd1da64330 Mon Sep 17 00:00:00 2001 From: Vlad Velicu Date: Tue, 27 Aug 2024 15:30:40 +0100 Subject: [PATCH 02/10] typo --- Objective-C/CBLLog.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Objective-C/CBLLog.mm b/Objective-C/CBLLog.mm index 389f7f5cf..5ea4d54a2 100644 --- a/Objective-C/CBLLog.mm +++ b/Objective-C/CBLLog.mm @@ -191,7 +191,7 @@ - (instancetype) initWithDefault { C4LogDomain domain = c4log_getDomain(domainName, true); C4LogLevel level = string2level(defaults[key]); c4log_setLevel(domain, level); - os_log(log, "CouchbaseLite logging to %s domain at level %s", domainName, kLevelNames[callbackLogLevel]); + os_log(log, "CouchbaseLite logging to %s domain at level %s", domainName, kLevelNames[level]); } } #endif From a9066428f6a74cef07cf55cbfc3bc578edd1844a Mon Sep 17 00:00:00 2001 From: Vlad Velicu Date: Wed, 28 Aug 2024 15:49:38 +0100 Subject: [PATCH 03/10] change log to assert for inputWord --- Objective-C/Tests/Util/CBLWordEmbeddingModel.m | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Objective-C/Tests/Util/CBLWordEmbeddingModel.m b/Objective-C/Tests/Util/CBLWordEmbeddingModel.m index e891b4fc0..344fd219f 100644 --- a/Objective-C/Tests/Util/CBLWordEmbeddingModel.m +++ b/Objective-C/Tests/Util/CBLWordEmbeddingModel.m @@ -39,11 +39,7 @@ - (CBLArray*) vectorForWord: (NSString*)word collection: (NSString*)collection { - (CBLDictionary*) predict: (CBLDictionary*)input { NSString* inputWord = [input stringForKey: @"word"]; - if (!inputWord) { - os_log_t log = os_log_create("CouchbaseLite", "OSLogging"); - os_log(log, "No word input !!!"); - return nil; - } + assert(inputWord); CBLArray* result = [self vectorForWord: inputWord collection: @"words"]; if (!result) { From 6895ecdb301365373807c3f82794aeb8fb1472a2 Mon Sep 17 00:00:00 2001 From: Vlad Velicu Date: Wed, 4 Sep 2024 19:53:21 +0100 Subject: [PATCH 04/10] changed to match .NET --- CouchbaseLite.xcodeproj/project.pbxproj | 10 ------- Objective-C/CBLConsoleLogger.m | 40 +++++++++++++++++++++---- Objective-C/CBLDatabase.mm | 5 ++-- Objective-C/CBLLog.h | 1 - Objective-C/CBLLog.mm | 36 +++------------------- Objective-C/Internal/CBLLog+Admin.h | 36 ---------------------- Objective-C/Internal/CBLLog+Internal.h | 1 + 7 files changed, 42 insertions(+), 87 deletions(-) delete mode 100644 Objective-C/Internal/CBLLog+Admin.h diff --git a/CouchbaseLite.xcodeproj/project.pbxproj b/CouchbaseLite.xcodeproj/project.pbxproj index e5cfc2615..3d0c102e9 100644 --- a/CouchbaseLite.xcodeproj/project.pbxproj +++ b/CouchbaseLite.xcodeproj/project.pbxproj @@ -1479,10 +1479,6 @@ 9388CC3321C18672005CA66D /* CBLLog+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 93C50F0F21C068F300C7E980 /* CBLLog+Internal.h */; }; 9388CC3421C18673005CA66D /* CBLLog+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 93C50F0F21C068F300C7E980 /* CBLLog+Internal.h */; }; 9388CC3521C18674005CA66D /* CBLLog+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 93C50F0F21C068F300C7E980 /* CBLLog+Internal.h */; }; - 9388CC3621C186DD005CA66D /* CBLLog+Admin.h in Headers */ = {isa = PBXBuildFile; fileRef = 274D6C272011529D00DAB7DD /* CBLLog+Admin.h */; }; - 9388CC3721C186DE005CA66D /* CBLLog+Admin.h in Headers */ = {isa = PBXBuildFile; fileRef = 274D6C272011529D00DAB7DD /* CBLLog+Admin.h */; }; - 9388CC3821C186DF005CA66D /* CBLLog+Admin.h in Headers */ = {isa = PBXBuildFile; fileRef = 274D6C272011529D00DAB7DD /* CBLLog+Admin.h */; }; - 9388CC3921C186DF005CA66D /* CBLLog+Admin.h in Headers */ = {isa = PBXBuildFile; fileRef = 274D6C272011529D00DAB7DD /* CBLLog+Admin.h */; }; 9388CC3A21C18784005CA66D /* CBLLog.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9388CBE721BF7195005CA66D /* CBLLog.mm */; }; 9388CC3B21C18786005CA66D /* CBLLog.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9388CBE721BF7195005CA66D /* CBLLog.mm */; }; 9388CC3C21C18787005CA66D /* CBLLog.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9388CBE721BF7195005CA66D /* CBLLog.mm */; }; @@ -2224,7 +2220,6 @@ 270AB2BB2073EF57009A4596 /* CBLChangeNotifier.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CBLChangeNotifier.m; sourceTree = ""; }; 2728509C1E99CA4D009CA22F /* CBLReplicator+Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "CBLReplicator+Internal.h"; path = "../CBLReplicator+Internal.h"; sourceTree = ""; }; 27476651201912B5007B39D1 /* CBLErrors.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CBLErrors.h; sourceTree = ""; }; - 274D6C272011529D00DAB7DD /* CBLLog+Admin.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CBLLog+Admin.h"; sourceTree = ""; }; 275229C51E776BC100E630FA /* CBLReplicator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CBLReplicator.h; sourceTree = ""; }; 275229C61E776BC100E630FA /* CBLReplicator.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CBLReplicator.mm; sourceTree = ""; }; 2753AFF11EC39CA200C12E98 /* CBLHTTPLogic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CBLHTTPLogic.h; sourceTree = ""; }; @@ -3932,7 +3927,6 @@ 9388CC1021BF9E54005CA66D /* Log */ = { isa = PBXGroup; children = ( - 274D6C272011529D00DAB7DD /* CBLLog+Admin.h */, 93C50F0F21C068F300C7E980 /* CBLLog+Internal.h */, 934F4C9C1E241FB500F90659 /* CBLLog+Logging.h */, 9388CC5721C25FDE005CA66D /* CBLLog+Swift.h */, @@ -4419,7 +4413,6 @@ 1AAFB66C284A260A00878453 /* CBLCollectionChange.h in Headers */, 9388CC0621BF750E005CA66D /* CBLFileLogger.h in Headers */, 9381960B1EC112010032CC51 /* CBLMutableDictionary.h in Headers */, - 9388CC3721C186DE005CA66D /* CBLLog+Admin.h in Headers */, 9381960D1EC112130032CC51 /* CBLArray.h in Headers */, 93CED8D420488DC400E6F0A4 /* CBLBlob+Swift.h in Headers */, 9381961F1EC11A8C0032CC51 /* CBLDictionary+Swift.h in Headers */, @@ -4700,7 +4693,6 @@ 40FC1C0B2B928ADC00394276 /* CBLListenerPasswordAuthenticator+Internal.h in Headers */, 9343EFF7207D611600F19A89 /* CBLQueryCollation.h in Headers */, 9343EFF8207D611600F19A89 /* CBLArrayFragment.h in Headers */, - 9388CC3821C186DF005CA66D /* CBLLog+Admin.h in Headers */, 9343EFF9207D611600F19A89 /* CBLIndex.h in Headers */, 935A58D021AFAD31009A29CB /* CBLDocumentReplication+Internal.h in Headers */, 9343EFFB207D611600F19A89 /* CBLData.h in Headers */, @@ -4909,7 +4901,6 @@ 9343F116207D61AB00F19A89 /* CBLReplicator+Internal.h in Headers */, 9343F117207D61AB00F19A89 /* CBLC4Document.h in Headers */, 9343F118207D61AB00F19A89 /* CBLJSON.h in Headers */, - 9388CC3921C186DF005CA66D /* CBLLog+Admin.h in Headers */, 9343F119207D61AB00F19A89 /* CBLCoreBridge.h in Headers */, 935A58D121AFAD31009A29CB /* CBLDocumentReplication+Internal.h in Headers */, 1A3470EC266F69280042C6BA /* CBLIndexConfiguration+Internal.h in Headers */, @@ -5020,7 +5011,6 @@ 9388CC0521BF750E005CA66D /* CBLFileLogger.h in Headers */, 9398D9FF1E03531A00464432 /* CouchbaseLite.h in Headers */, 1A3470C1266F3E7C0042C6BA /* CBLIndexConfiguration.h in Headers */, - 9388CC3621C186DD005CA66D /* CBLLog+Admin.h in Headers */, 6932D48D2954640000D28C18 /* CBLQueryFullTextIndexExpression.h in Headers */, 937F01E11EFB269300060D64 /* CBLAuthenticator.h in Headers */, 934F4CB51E241FB500F90659 /* CBLPrefix.h in Headers */, diff --git a/Objective-C/CBLConsoleLogger.m b/Objective-C/CBLConsoleLogger.m index b948d4d8d..133cd491f 100644 --- a/Objective-C/CBLConsoleLogger.m +++ b/Objective-C/CBLConsoleLogger.m @@ -19,17 +19,19 @@ #import "CBLConsoleLogger.h" #import "CBLLog+Internal.h" -#import "CBLLog+Admin.h" @implementation CBLConsoleLogger @synthesize level=_level, domains=_domains; +static NSMutableDictionary* osLogDictionary; + - (instancetype) initWithLogLevel: (CBLLogLevel)level { self = [super init]; if (self) { _level = level; _domains = kCBLLogDomainAll; + [self initializeOSLogDomains]; } return self; } @@ -43,10 +45,38 @@ - (void) logWithLevel: (CBLLogLevel)level domain: (CBLLogDomain)domain message: if (self.level > level || (self.domains & domain) == 0) return; - NSString* levelName = CBLLog_GetLevelName(level); - NSString* domainName = CBLLog_GetDomainName(domain); - os_log_t log = os_log_create("CouchbaseLite", "OSDebug"); - os_log(log, "CouchbaseLite %@ %@: %@", domainName, levelName, message); + os_log_t osLogDomain = osLogDictionary[@(domain)]; + os_log_type_t osLogType = osLogTypeForLevel(level); + os_log_with_type(osLogDomain, osLogType, "%@", message); +} + +static os_log_type_t osLogTypeForLevel(CBLLogLevel level) { + switch (level) { + case kCBLLogLevelDebug: + return OS_LOG_TYPE_DEBUG; + case kCBLLogLevelVerbose: + return OS_LOG_TYPE_INFO; // Map verbose to info + case kCBLLogLevelInfo: + return OS_LOG_TYPE_INFO; + case kCBLLogLevelWarning: + return OS_LOG_TYPE_ERROR; // Map warning to error + case kCBLLogLevelError: + return OS_LOG_TYPE_ERROR; + default: + return OS_LOG_TYPE_DEFAULT; // Default log type + } } +- (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"); + + #ifdef COUCHBASE_ENTERPRISE + osLogDictionary[@(kCBLLogDomainListener)] = os_log_create("com.couchbase.lite.ios", "Listener"); + #endif +} @end diff --git a/Objective-C/CBLDatabase.mm b/Objective-C/CBLDatabase.mm index b9038a540..018fb6390 100644 --- a/Objective-C/CBLDatabase.mm +++ b/Objective-C/CBLDatabase.mm @@ -30,7 +30,6 @@ #import "CBLIndexConfiguration+Internal.h" #import "CBLIndexSpec.h" #import "CBLIndex+Internal.h" -#import "CBLLog+Admin.h" #import "CBLLog+Internal.h" #import "CBLMisc.h" #import "CBLQuery+Internal.h" @@ -115,8 +114,8 @@ 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 log = os_log_create("CouchbaseLite", "OSLogging"); - os_log(log, "%@", [CBLVersion userAgent]); + os_log_t logger = os_log_create("com.couchbase.lite.ios", "UserAgent"); + os_log(logger, "%@", [CBLVersion userAgent]); // Initialize logging CBLAssertNotNil(CBLLog.sharedInstance); } diff --git a/Objective-C/CBLLog.h b/Objective-C/CBLLog.h index 8a9cb0170..26e389c3b 100644 --- a/Objective-C/CBLLog.h +++ b/Objective-C/CBLLog.h @@ -18,7 +18,6 @@ // #import -#import @protocol CBLLogger; @class CBLConsoleLogger; diff --git a/Objective-C/CBLLog.mm b/Objective-C/CBLLog.mm index 5ea4d54a2..d8bb5b310 100644 --- a/Objective-C/CBLLog.mm +++ b/Objective-C/CBLLog.mm @@ -18,7 +18,6 @@ // #import "CBLLog.h" -#import "CBLLog+Admin.h" #import "CBLLog+Internal.h" #import "CBLLog+Logging.h" #import "CBLLog+Swift.h" @@ -44,6 +43,7 @@ - (instancetype) initWithLevel: (CBLLogLevel)level logger: (CBLCustomLoggerBlock @implementation CBLLog { CBLLogLevel _callbackLogLevel; + os_log_t oslogger; } @synthesize console=_console, file=_file, custom=_custom; @@ -155,12 +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"); + oslogger = os_log_create("com.couchbase.lite.ios", "DebugBuild"); if (userLogLevel) { callbackLogLevel = string2level(userLogLevel); } if (callbackLogLevel != kC4LogWarning) { - os_log(log, "CouchbaseLite minimum log level is %s", kLevelNames[callbackLogLevel]); + os_log(oslogger, "CouchbaseLite minimum log level is %s", kLevelNames[callbackLogLevel]); } #endif @@ -191,7 +191,7 @@ - (instancetype) initWithDefault { C4LogDomain domain = c4log_getDomain(domainName, true); C4LogLevel level = string2level(defaults[key]); c4log_setLevel(domain, level); - os_log(log, "CouchbaseLite logging to %s domain at level %s", domainName, kLevelNames[level]); + os_log(oslogger, "CouchbaseLite logging to %s domain at level %s", domainName, kLevelNames[level]); } } #endif @@ -284,34 +284,6 @@ void cblLog(C4LogDomain domain, C4LogLevel level, NSString *msg, ...) { sendToCallbackLogger(domain, level, nsmsg); } -NSString* CBLLog_GetLevelName(CBLLogLevel level) { - return [NSString stringWithUTF8String: kLevelNames[level]]; -} - -NSString* CBLLog_GetDomainName(CBLLogDomain domain) { - switch (domain) { - case kCBLLogDomainDatabase: - return @"Database"; - break; - case kCBLLogDomainQuery: - return @"Query"; - break; - case kCBLLogDomainReplicator: - return @"Replicator"; - break; - case kCBLLogDomainNetwork: - return @"Network"; - break; -#ifdef COUCHBASE_ENTERPRISE - case kCBLLogDomainListener: - return @"Listener"; - break; -#endif - default: - return @"Database"; - } -} - @implementation CBLCustomLogger { CBLLogLevel _level; CBLCustomLoggerBlock _logger; diff --git a/Objective-C/Internal/CBLLog+Admin.h b/Objective-C/Internal/CBLLog+Admin.h deleted file mode 100644 index ffc0e0351..000000000 --- a/Objective-C/Internal/CBLLog+Admin.h +++ /dev/null @@ -1,36 +0,0 @@ -// -// CBLLog+Admin.h -// CouchbaseLite -// -// Copyright (c) 2024 Couchbase, Inc All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#import "CBLLogger.h" - -#ifdef __cplusplus -extern "C" { -#endif - -NS_ASSUME_NONNULL_BEGIN - -NSString* CBLLog_GetLevelName(CBLLogLevel level); - -NSString* CBLLog_GetDomainName(CBLLogDomain domain); - -NS_ASSUME_NONNULL_END - -#ifdef __cplusplus -} -#endif diff --git a/Objective-C/Internal/CBLLog+Internal.h b/Objective-C/Internal/CBLLog+Internal.h index 616e5bcf9..a3d64d6ad 100644 --- a/Objective-C/Internal/CBLLog+Internal.h +++ b/Objective-C/Internal/CBLLog+Internal.h @@ -17,6 +17,7 @@ // limitations under the License. // +#import #import "CBLLog.h" #import "CBLConsoleLogger.h" #import "CBLFileLogger.h" From c13966218d3e9c81ac72c048fe9758dfa0764bfe Mon Sep 17 00:00:00 2001 From: Vlad Velicu Date: Fri, 13 Sep 2024 17:12:56 +0100 Subject: [PATCH 05/10] Create generic internal logger for ConsoleLog to be used with any additional in-code logging --- Objective-C/CBLConsoleLogger.m | 14 ++++++++++++++ Objective-C/CBLDatabase.mm | 3 +-- Objective-C/CBLLog.mm | 4 ++-- Objective-C/Internal/CBLLog+Internal.h | 4 ++++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Objective-C/CBLConsoleLogger.m b/Objective-C/CBLConsoleLogger.m index 133cd491f..62aa3dbf9 100644 --- a/Objective-C/CBLConsoleLogger.m +++ b/Objective-C/CBLConsoleLogger.m @@ -25,6 +25,7 @@ @implementation CBLConsoleLogger @synthesize level=_level, domains=_domains; static NSMutableDictionary* osLogDictionary; +static os_log_t logger; - (instancetype) initWithLogLevel: (CBLLogLevel)level { self = [super init]; @@ -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"); + } + return logger; +} + ++ (void) logWithInternal: (NSString*)message { + logger = [self internalLogger]; + os_log(logger, "%@", message); +} + @end diff --git a/Objective-C/CBLDatabase.mm b/Objective-C/CBLDatabase.mm index 018fb6390..de7284eec 100644 --- a/Objective-C/CBLDatabase.mm +++ b/Objective-C/CBLDatabase.mm @@ -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); } diff --git a/Objective-C/CBLLog.mm b/Objective-C/CBLLog.mm index d8bb5b310..26189d186 100644 --- a/Objective-C/CBLLog.mm +++ b/Objective-C/CBLLog.mm @@ -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 diff --git a/Objective-C/Internal/CBLLog+Internal.h b/Objective-C/Internal/CBLLog+Internal.h index a3d64d6ad..aea668643 100644 --- a/Objective-C/Internal/CBLLog+Internal.h +++ b/Objective-C/Internal/CBLLog+Internal.h @@ -36,6 +36,10 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype) initWithLogLevel: (CBLLogLevel)level; ++ (os_log_t) internalLogger; + ++ (void) logWithInternal: (nonnull NSString*)message; + @end @interface CBLFileLogger () From 4e50ac7667d465fb57e6569ad0989e9ac44a6cbd Mon Sep 17 00:00:00 2001 From: Vlad Velicu Date: Fri, 4 Oct 2024 16:49:10 +0100 Subject: [PATCH 06/10] feedback --- Objective-C/CBLConsoleLogger.m | 22 ++++++++++++---------- Objective-C/CBLDatabase.mm | 2 +- Objective-C/Internal/CBLLog+Internal.h | 2 ++ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Objective-C/CBLConsoleLogger.m b/Objective-C/CBLConsoleLogger.m index 62aa3dbf9..bbc99e820 100644 --- a/Objective-C/CBLConsoleLogger.m +++ b/Objective-C/CBLConsoleLogger.m @@ -22,7 +22,7 @@ @implementation CBLConsoleLogger -@synthesize level=_level, domains=_domains; +@synthesize level=_level, domains=_domains, sysID=_sysID; static NSMutableDictionary* osLogDictionary; static os_log_t logger; @@ -32,6 +32,7 @@ - (instancetype) initWithLogLevel: (CBLLogLevel)level { if (self) { _level = level; _domains = kCBLLogDomainAll; + _sysID = [[NSBundle mainBundle] bundleIdentifier]; [self initializeOSLogDomains]; } return self; @@ -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"); + }); return logger; } diff --git a/Objective-C/CBLDatabase.mm b/Objective-C/CBLDatabase.mm index de7284eec..e9666f7fb 100644 --- a/Objective-C/CBLDatabase.mm +++ b/Objective-C/CBLDatabase.mm @@ -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); } @@ -124,6 +123,7 @@ + (void) initialize { + (void) CBLInit { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ + [CBLConsoleLogger logWithInternal:[CBLVersion userAgent]]; [self checkFileLogging]; }); } diff --git a/Objective-C/Internal/CBLLog+Internal.h b/Objective-C/Internal/CBLLog+Internal.h index aea668643..6133080e8 100644 --- a/Objective-C/Internal/CBLLog+Internal.h +++ b/Objective-C/Internal/CBLLog+Internal.h @@ -34,6 +34,8 @@ NS_ASSUME_NONNULL_BEGIN @interface CBLConsoleLogger () +@property (nonatomic, readonly) NSString* sysID; + - (instancetype) initWithLogLevel: (CBLLogLevel)level; + (os_log_t) internalLogger; From 90a540aea2f48a751394166e5b33f03383008192 Mon Sep 17 00:00:00 2001 From: Vlad Velicu Date: Fri, 4 Oct 2024 16:49:17 +0100 Subject: [PATCH 07/10] typo fix --- Objective-C/Internal/Replicator/CBLHTTPLogic.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Objective-C/Internal/Replicator/CBLHTTPLogic.m b/Objective-C/Internal/Replicator/CBLHTTPLogic.m index 6cc7393c3..f23a19ca8 100644 --- a/Objective-C/Internal/Replicator/CBLHTTPLogic.m +++ b/Objective-C/Internal/Replicator/CBLHTTPLogic.m @@ -105,7 +105,7 @@ + (NSString*) userAgent { #if TARGET_OS_IPHONE @"iOS", #else - @"Mac OS X", + @"macOS", #endif process.operatingSystemVersionString]; } From e7defe899a37d21db5e1485700146efbdd3314d6 Mon Sep 17 00:00:00 2001 From: Vlad Velicu Date: Thu, 17 Oct 2024 16:20:37 +0100 Subject: [PATCH 08/10] fix framework id --- Objective-C/CBLConsoleLogger.m | 17 +++++++++-------- Objective-C/Internal/CBLLog+Internal.h | 2 -- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Objective-C/CBLConsoleLogger.m b/Objective-C/CBLConsoleLogger.m index bbc99e820..345a53b18 100644 --- a/Objective-C/CBLConsoleLogger.m +++ b/Objective-C/CBLConsoleLogger.m @@ -22,17 +22,18 @@ @implementation CBLConsoleLogger -@synthesize level=_level, domains=_domains, sysID=_sysID; +@synthesize level=_level, domains=_domains; static NSMutableDictionary* osLogDictionary; static os_log_t logger; +static NSString* _sysID; - (instancetype) initWithLogLevel: (CBLLogLevel)level { self = [super init]; if (self) { _level = level; _domains = kCBLLogDomainAll; - _sysID = [[NSBundle mainBundle] bundleIdentifier]; + _sysID = [[NSBundle bundleForClass:[self class]] bundleIdentifier]; [self initializeOSLogDomains]; } return self; @@ -72,20 +73,20 @@ static os_log_type_t osLogTypeForLevel(CBLLogLevel level) { - (void) initializeOSLogDomains { osLogDictionary = [NSMutableDictionary dictionary]; - 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"); + osLogDictionary[@(kCBLLogDomainDatabase)] = os_log_create([_sysID UTF8String], "Database"); + osLogDictionary[@(kCBLLogDomainQuery)] = os_log_create([_sysID UTF8String], "Query"); + osLogDictionary[@(kCBLLogDomainReplicator)] = os_log_create([_sysID UTF8String], "Replicator"); + osLogDictionary[@(kCBLLogDomainNetwork)] = os_log_create([_sysID UTF8String], "Network"); #ifdef COUCHBASE_ENTERPRISE - osLogDictionary[@(kCBLLogDomainListener)] = os_log_create([self.sysID UTF8String], "Listener"); + osLogDictionary[@(kCBLLogDomainListener)] = os_log_create([_sysID UTF8String], "Listener"); #endif } + (os_log_t) internalLogger { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - logger = os_log_create("com.couchbase.lite.ios", "Internal"); + logger = os_log_create([_sysID UTF8String], "Internal"); }); return logger; } diff --git a/Objective-C/Internal/CBLLog+Internal.h b/Objective-C/Internal/CBLLog+Internal.h index 6133080e8..aea668643 100644 --- a/Objective-C/Internal/CBLLog+Internal.h +++ b/Objective-C/Internal/CBLLog+Internal.h @@ -34,8 +34,6 @@ NS_ASSUME_NONNULL_BEGIN @interface CBLConsoleLogger () -@property (nonatomic, readonly) NSString* sysID; - - (instancetype) initWithLogLevel: (CBLLogLevel)level; + (os_log_t) internalLogger; From 96a48a5c49eb87dd2151a0984db5655e380be106 Mon Sep 17 00:00:00 2001 From: Vlad Velicu Date: Tue, 22 Oct 2024 13:49:31 +0100 Subject: [PATCH 09/10] log under Database using specific call --- Objective-C/CBLConsoleLogger.m | 14 ++------------ Objective-C/CBLDatabase.mm | 2 +- Objective-C/CBLLog.mm | 2 +- Objective-C/Internal/CBLLog+Internal.h | 4 +--- 4 files changed, 5 insertions(+), 17 deletions(-) diff --git a/Objective-C/CBLConsoleLogger.m b/Objective-C/CBLConsoleLogger.m index 345a53b18..1c7897bf7 100644 --- a/Objective-C/CBLConsoleLogger.m +++ b/Objective-C/CBLConsoleLogger.m @@ -25,7 +25,6 @@ @implementation CBLConsoleLogger @synthesize level=_level, domains=_domains; static NSMutableDictionary* osLogDictionary; -static os_log_t logger; static NSString* _sysID; - (instancetype) initWithLogLevel: (CBLLogLevel)level { @@ -83,17 +82,8 @@ - (void) initializeOSLogDomains { #endif } -+ (os_log_t) internalLogger { - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - logger = os_log_create([_sysID UTF8String], "Internal"); - }); - return logger; -} - -+ (void) logWithInternal: (NSString*)message { - logger = [self internalLogger]; - os_log(logger, "%@", message); ++ (void) logAlways: (NSString*)message { + os_log(osLogDictionary[@(kCBLLogDomainDatabase)], "%@", message); } @end diff --git a/Objective-C/CBLDatabase.mm b/Objective-C/CBLDatabase.mm index e9666f7fb..7439c753e 100644 --- a/Objective-C/CBLDatabase.mm +++ b/Objective-C/CBLDatabase.mm @@ -123,7 +123,7 @@ + (void) initialize { + (void) CBLInit { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - [CBLConsoleLogger logWithInternal:[CBLVersion userAgent]]; + [CBLConsoleLogger logAlways:[CBLVersion userAgent]]; [self checkFileLogging]; }); } diff --git a/Objective-C/CBLLog.mm b/Objective-C/CBLLog.mm index 26189d186..523e3f5af 100644 --- a/Objective-C/CBLLog.mm +++ b/Objective-C/CBLLog.mm @@ -160,7 +160,7 @@ - (instancetype) initWithDefault { } if (callbackLogLevel != kC4LogWarning) { NSString* message = [NSString stringWithFormat: @"CouchbaseLite minimum log level is %s", kLevelNames[callbackLogLevel]]; - [CBLConsoleLogger logWithInternal: message]; + [CBLConsoleLogger logAlways: message]; } #endif diff --git a/Objective-C/Internal/CBLLog+Internal.h b/Objective-C/Internal/CBLLog+Internal.h index aea668643..8ca71ce06 100644 --- a/Objective-C/Internal/CBLLog+Internal.h +++ b/Objective-C/Internal/CBLLog+Internal.h @@ -36,9 +36,7 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype) initWithLogLevel: (CBLLogLevel)level; -+ (os_log_t) internalLogger; - -+ (void) logWithInternal: (nonnull NSString*)message; ++ (void) logAlways: (nonnull NSString*)message; @end From 04526caa57bdf8465ee537929f7c4f770b36004f Mon Sep 17 00:00:00 2001 From: Vlad Velicu Date: Tue, 22 Oct 2024 17:28:37 +0100 Subject: [PATCH 10/10] plus 1 --- Objective-C/CBLLog.mm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Objective-C/CBLLog.mm b/Objective-C/CBLLog.mm index 523e3f5af..c40632037 100644 --- a/Objective-C/CBLLog.mm +++ b/Objective-C/CBLLog.mm @@ -191,7 +191,8 @@ - (instancetype) initWithDefault { C4LogDomain domain = c4log_getDomain(domainName, true); C4LogLevel level = string2level(defaults[key]); c4log_setLevel(domain, level); - os_log(oslogger, "CouchbaseLite logging to %s domain at level %s", domainName, kLevelNames[level]); + NSString* message = [NSString stringWithFormat: @"CouchbaseLite logging to %s domain at level %s", domainName, kLevelNames[level]]; + [CBLConsoleLogger logAlways: message]; } } #endif