Jelajahi Sumber

Fix deprecations

Florian Friedrich 2 tahun lalu
induk
melakukan
80e3a0df30

+ 7 - 0
Demos/Benchmark/Desktop/BenchmarkMac.xcodeproj/project.xcworkspace/contents.xcworkspacedata

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Workspace
+   version = "1.0">
+   <FileRef
+      location = "self:">
+   </FileRef>
+</Workspace>

+ 8 - 0
Demos/Benchmark/Desktop/BenchmarkMac.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>IDEDidComputeMac32BitWarning</key>
+	<true/>
+</dict>
+</plist>

+ 8 - 0
Demos/CLI/CLI.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>IDEDidComputeMac32BitWarning</key>
+	<true/>
+</dict>
+</plist>

+ 1 - 1
Demos/GlobalLogLevel/GlobalLogLevelAppDelegate.m

@@ -14,7 +14,7 @@ DDLogLevel ddLogLevel;
 @implementation GlobalLogLevelAppDelegate
 @synthesize window;
 
-static void someFunction()
+static void someFunction(void)
 {
     DDLogError(@"%@: C_Error", THIS_FILE);
     DDLogWarn(@"%@: C_Warn", THIS_FILE);

+ 2 - 2
Integration/Sources/ViewController.m

@@ -34,7 +34,7 @@ static const DDLogLevel ddLogLevel = DDLogLevelVerbose;
     if (@available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)) {
         [DDLog addLogger:[DDOSLogger sharedInstance]];
     } else {
-        [DDLog addLogger:[DDTTYLogger sharedInstance]];
+        [DDLog addLogger:(DDTTYLogger *)[DDTTYLogger sharedInstance]];
     }
     
     DDLogVerbose(@"Verbose");
@@ -46,7 +46,7 @@ static const DDLogLevel ddLogLevel = DDLogLevelVerbose;
     if (@available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)) {
         [aDDLogInstance addLogger:[DDOSLogger sharedInstance]];
     } else {
-        [aDDLogInstance addLogger:[DDTTYLogger sharedInstance]];
+        [aDDLogInstance addLogger:(DDTTYLogger *)[DDTTYLogger sharedInstance]];
     }
     
     DDLogVerboseToDDLog(aDDLogInstance, @"Verbose from aDDLogInstance");

+ 20 - 49
Sources/CocoaLumberjack/Extensions/DDDispatchQueueLogFormatter.m

@@ -134,98 +134,69 @@ static DDQualityOfServiceName _qos_name(NSUInteger qos) {
 - (NSString *)queueThreadLabelForLogMessage:(DDLogMessage *)logMessage {
     // As per the DDLogFormatter contract, this method is always invoked on the same thread/dispatch_queue
 
-    NSUInteger minQueueLength = self.minQueueLength;
-    NSUInteger maxQueueLength = self.maxQueueLength;
-
-    // Get the name of the queue, thread, or machID (whichever we are to use).
-
-    NSString *queueThreadLabel = nil;
-
-    BOOL useQueueLabel = YES;
-    BOOL useThreadName = NO;
-
+    BOOL useQueueLabel = NO;
     if (logMessage->_queueLabel) {
+        useQueueLabel = YES;
+
         // If you manually create a thread, it's dispatch_queue will have one of the thread names below.
         // Since all such threads have the same name, we'd prefer to use the threadName or the machThreadID.
-
-        NSArray *names = @[
+        const NSArray *names = @[
             @"com.apple.root.low-priority",
             @"com.apple.root.default-priority",
             @"com.apple.root.high-priority",
             @"com.apple.root.low-overcommit-priority",
             @"com.apple.root.default-overcommit-priority",
             @"com.apple.root.high-overcommit-priority",
-            @"com.apple.root.default-qos.overcommit"
+            @"com.apple.root.default-qos.overcommit",
         ];
-
-        for (NSString * name in names) {
+        for (NSString *name in names) {
             if ([logMessage->_queueLabel isEqualToString:name]) {
                 useQueueLabel = NO;
-                useThreadName = [logMessage->_threadName length] > 0;
                 break;
             }
         }
-    } else {
-        useQueueLabel = NO;
-        useThreadName = [logMessage->_threadName length] > 0;
     }
 
-    if (useQueueLabel || useThreadName) {
-        NSString *fullLabel;
-        NSString *abrvLabel;
-
-        if (useQueueLabel) {
-            fullLabel = logMessage->_queueLabel;
-        } else {
-            fullLabel = logMessage->_threadName;
-        }
+    // Get the name of the queue, thread, or machID (whichever we are to use).
+    NSString *queueThreadLabel;
+    if (useQueueLabel || [logMessage->_threadName length] > 0) {
+        NSString *fullLabel = useQueueLabel ? logMessage->_queueLabel : logMessage->_threadName;
 
+        NSString *abrvLabel;
         pthread_mutex_lock(&_mutex);
         {
             abrvLabel = _replacements[fullLabel];
         }
         pthread_mutex_unlock(&_mutex);
 
-        if (abrvLabel) {
-            queueThreadLabel = abrvLabel;
-        } else {
-            queueThreadLabel = fullLabel;
-        }
+        queueThreadLabel = abrvLabel ?: fullLabel;
     } else {
         queueThreadLabel = logMessage->_threadID;
     }
 
     // Now use the thread label in the output
-
-    NSUInteger labelLength = [queueThreadLabel length];
-
     // labelLength > maxQueueLength : truncate
     // labelLength < minQueueLength : padding
     //                              : exact
-
-    if ((maxQueueLength > 0) && (labelLength > maxQueueLength)) {
+    NSUInteger minQueueLength = self.minQueueLength;
+    NSUInteger maxQueueLength = self.maxQueueLength;
+    NSUInteger labelLength = [queueThreadLabel length];
+    if (maxQueueLength > 0 && labelLength > maxQueueLength) {
         // Truncate
-
         return [queueThreadLabel substringToIndex:maxQueueLength];
     } else if (labelLength < minQueueLength) {
         // Padding
-
-        NSUInteger numSpaces = minQueueLength - labelLength;
-
-        char spaces[numSpaces + 1];
-        memset(spaces, ' ', numSpaces);
-        spaces[numSpaces] = '\0';
-
-        return [queueThreadLabel stringByAppendingString:@(spaces)];
+        return [queueThreadLabel stringByPaddingToLength:minQueueLength
+                                              withString:@" "
+                                         startingAtIndex:0];
     } else {
         // Exact
-
         return queueThreadLabel;
     }
 }
 
 - (NSString *)formatLogMessage:(DDLogMessage *)logMessage {
-    NSString *timestamp = [self stringFromDate:(logMessage->_timestamp)];
+    NSString *timestamp = [self stringFromDate:logMessage->_timestamp];
     NSString *queueThreadLabel = [self queueThreadLabelForLogMessage:logMessage];
 
     return [NSString stringWithFormat:@"%@ [%@ (QOS:%@)] %@", timestamp, queueThreadLabel, _qos_name(logMessage->_qos), logMessage->_message];

+ 1 - 1
Tests/CocoaLumberjackTests/DDContextFilterLogFormatter+DeprecatedTests.m

@@ -16,7 +16,7 @@
 #import <XCTest/XCTest.h>
 #import <CocoaLumberjack/DDContextFilterLogFormatter+Deprecated.h>
 
-static DDLogMessage *testLogMessage() {
+static DDLogMessage *testLogMessage(void) {
     return [[DDLogMessage alloc] initWithFormat:@"test log message"
                                       formatted:@"test log message"
                                            level:DDLogLevelDebug

+ 1 - 1
Tests/CocoaLumberjackTests/DDContextFilterLogFormatterTests.m

@@ -16,7 +16,7 @@
 #import <XCTest/XCTest.h>
 #import <CocoaLumberjack/DDContextFilterLogFormatter.h>
 
-static DDLogMessage *testLogMessage() {
+static DDLogMessage *testLogMessage(void) {
     return [[DDLogMessage alloc] initWithFormat:@"test log message"
                                       formatted:@"test log message"
                                            level:DDLogLevelDebug