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 eef775304..1c7897bf7 100644 --- a/Objective-C/CBLConsoleLogger.m +++ b/Objective-C/CBLConsoleLogger.m @@ -19,17 +19,21 @@ #import "CBLConsoleLogger.h" #import "CBLLog+Internal.h" -#import "CBLLog+Admin.h" @implementation CBLConsoleLogger @synthesize level=_level, domains=_domains; +static NSMutableDictionary* osLogDictionary; +static NSString* _sysID; + - (instancetype) initWithLogLevel: (CBLLogLevel)level { self = [super init]; if (self) { _level = level; _domains = kCBLLogDomainAll; + _sysID = [[NSBundle bundleForClass:[self class]] bundleIdentifier]; + [self initializeOSLogDomains]; } return self; } @@ -43,9 +47,43 @@ - (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); - NSLog(@"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([_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([_sysID UTF8String], "Listener"); + #endif +} + ++ (void) logAlways: (NSString*)message { + os_log(osLogDictionary[@(kCBLLogDomainDatabase)], "%@", message); } @end diff --git a/Objective-C/CBLDatabase.mm b/Objective-C/CBLDatabase.mm index 8cfc9b42f..7439c753e 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,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]) { - NSLog(@"%@", [CBLVersion userAgent]); // Initialize logging CBLAssertNotNil(CBLLog.sharedInstance); } @@ -125,6 +123,7 @@ + (void) initialize { + (void) CBLInit { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ + [CBLConsoleLogger logAlways:[CBLVersion userAgent]]; [self checkFileLogging]; }); } diff --git a/Objective-C/CBLLog.mm b/Objective-C/CBLLog.mm index c78c41b9b..c40632037 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; @@ -159,7 +159,8 @@ - (instancetype) initWithDefault { callbackLogLevel = string2level(userLogLevel); } if (callbackLogLevel != kC4LogWarning) { - NSLog(@"CouchbaseLite minimum log level is %s", kLevelNames[callbackLogLevel]); + NSString* message = [NSString stringWithFormat: @"CouchbaseLite minimum log level is %s", kLevelNames[callbackLogLevel]]; + [CBLConsoleLogger logAlways: message]; } #endif @@ -190,7 +191,8 @@ - (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]); + NSString* message = [NSString stringWithFormat: @"CouchbaseLite logging to %s domain at level %s", domainName, kLevelNames[level]]; + [CBLConsoleLogger logAlways: message]; } } #endif @@ -283,34 +285,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..8ca71ce06 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" @@ -35,6 +36,8 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype) initWithLogLevel: (CBLLogLevel)level; ++ (void) logAlways: (nonnull NSString*)message; + @end @interface CBLFileLogger () 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]; } diff --git a/Objective-C/Tests/Util/CBLWordEmbeddingModel.m b/Objective-C/Tests/Util/CBLWordEmbeddingModel.m index b01e3d4c4..344fd219f 100644 --- a/Objective-C/Tests/Util/CBLWordEmbeddingModel.m +++ b/Objective-C/Tests/Util/CBLWordEmbeddingModel.m @@ -39,10 +39,7 @@ - (CBLArray*) vectorForWord: (NSString*)word collection: (NSString*)collection { - (CBLDictionary*) predict: (CBLDictionary*)input { NSString* inputWord = [input stringForKey: @"word"]; - if (!inputWord) { - NSLog(@"No word input !!!"); - return nil; - } + assert(inputWord); CBLArray* result = [self vectorForWord: inputWord collection: @"words"]; if (!result) {