Skip to content

Commit

Permalink
Merge pull request #325 from wordpress-mobile/delete-cocoalumberjack
Browse files Browse the repository at this point in the history
Delete CocoaLumberjack
  • Loading branch information
crazytonyli authored Nov 27, 2022
2 parents fb2b1ab + 31531b2 commit 280127f
Show file tree
Hide file tree
Showing 17 changed files with 248 additions and 170 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ _None._
### New Features

- Add Swift Package Manager support [#321]
- Remove CocoaLumberjack. The app needs to provide a `WordPressLoggingDelegate` implementation [#325]

### Bug Fixes

Expand Down
18 changes: 0 additions & 18 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
{
"object": {
"pins": [
{
"package": "CocoaLumberjack",
"repositoryURL": "https://github.com/CocoaLumberjack/CocoaLumberjack.git",
"state": {
"branch": null,
"revision": "0188d31089b5881a269e01777be74c7316924346",
"version": "3.8.0"
}
},
{
"package": "OCMock",
"repositoryURL": "https://github.com/erikdoe/ocmock",
Expand Down Expand Up @@ -37,15 +28,6 @@
"version": "6.0.0"
}
},
{
"package": "swift-log",
"repositoryURL": "https://github.com/apple/swift-log.git",
"state": {
"branch": null,
"revision": "6fe203dc33195667ce1759bf0182975e4653ba1c",
"version": "1.4.4"
}
},
{
"package": "BuildkiteTestCollector",
"repositoryURL": "https://github.com/buildkite/test-collector-swift",
Expand Down
5 changes: 0 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/buildkite/test-collector-swift", from: "0.3.0"),
.package(url: "https://github.com/CocoaLumberjack/CocoaLumberjack", from: "3.8.0"),
.package(url: "https://github.com/AliSoftware/OHHTTPStubs", from: "9.1.0"),
// See https://github.com/erikdoe/ocmock/issues/500#issuecomment-1002700625
.package(url: "https://github.com/erikdoe/ocmock", revision: "afd2c6924e8a36cb872bc475248b978f743c6050"),
Expand All @@ -19,16 +18,12 @@ let package = Package(
targets: [
.target(
name: "WordPressSharedObjC",
dependencies: [
.product(name: "CocoaLumberjack", package: "CocoaLumberjack"),
],
resources: [.process("Resources")]
),
.target(
name: "WordPressShared",
dependencies: [
.target(name: "WordPressSharedObjC"),
.product(name: "CocoaLumberjackSwift", package: "CocoaLumberjack"),
],
resources: [.process("Resources")]
),
Expand Down
111 changes: 0 additions & 111 deletions Sources/WordPressShared/Logging/CocoaLumberjack.swift

This file was deleted.

4 changes: 2 additions & 2 deletions Sources/WordPressShared/Utility/String+RemovingMatches.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

#if SWIFT_PACKAGE
import CocoaLumberjackSwift
import WordPressSharedObjC
#endif

extension String {
Expand All @@ -15,7 +15,7 @@ extension String {
do {
regex = try NSRegularExpression(pattern: pattern, options: options)
} catch {
DDLogError(("Error parsing regex: \(error)"))
WPSharedLogError("Error parsing regex: \(error)")
return self
}

Expand Down
20 changes: 20 additions & 0 deletions Sources/WordPressShared/WordPressShared.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,23 @@
@_exported import WordPressSharedObjC

#endif

func WPSharedLogError(_ format: String, _ arguments: CVarArg...) {
withVaList(arguments) { WPSharedLogvError(format, $0) }
}

func WPSharedLogWarning(_ format: String, _ arguments: CVarArg...) {
withVaList(arguments) { WPSharedLogvWarning(format, $0) }
}

func WPSharedLogInfo(_ format: String, _ arguments: CVarArg...) {
withVaList(arguments) { WPSharedLogvInfo(format, $0) }
}

func WPSharedLogDebug(_ format: String, _ arguments: CVarArg...) {
withVaList(arguments) { WPSharedLogvDebug(format, $0) }
}

func WPSharedLogVerbose(_ format: String, _ arguments: CVarArg...) {
withVaList(arguments) { WPSharedLogvVerbose(format, $0) }
}
23 changes: 20 additions & 3 deletions Sources/WordPressSharedObjC/Logging/WPSharedLogging.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
@import CocoaLumberjack;
#import <Foundation/Foundation.h>
#import "WordPressLoggingDelegate.h"

DDLogLevel WPSharedGetLoggingLevel(void);
void WPSharedSetLoggingLevel(DDLogLevel level);
NS_ASSUME_NONNULL_BEGIN

FOUNDATION_EXTERN id<WordPressLoggingDelegate> _Nullable WPSharedGetLoggingDelegate(void);
FOUNDATION_EXTERN void WPSharedSetLoggingDelegate(id<WordPressLoggingDelegate> _Nullable logger);

FOUNDATION_EXTERN void WPSharedLogError(NSString *str, ...) NS_FORMAT_FUNCTION(1, 2);
FOUNDATION_EXTERN void WPSharedLogWarning(NSString *str, ...) NS_FORMAT_FUNCTION(1, 2);
FOUNDATION_EXTERN void WPSharedLogInfo(NSString *str, ...) NS_FORMAT_FUNCTION(1, 2);
FOUNDATION_EXTERN void WPSharedLogDebug(NSString *str, ...) NS_FORMAT_FUNCTION(1, 2);
FOUNDATION_EXTERN void WPSharedLogVerbose(NSString *str, ...) NS_FORMAT_FUNCTION(1, 2);

FOUNDATION_EXTERN void WPSharedLogvError(NSString *str, va_list args) NS_FORMAT_FUNCTION(1, 0);
FOUNDATION_EXTERN void WPSharedLogvWarning(NSString *str, va_list args) NS_FORMAT_FUNCTION(1, 0);
FOUNDATION_EXTERN void WPSharedLogvInfo(NSString *str, va_list args) NS_FORMAT_FUNCTION(1, 0);
FOUNDATION_EXTERN void WPSharedLogvDebug(NSString *str, va_list args) NS_FORMAT_FUNCTION(1, 0);
FOUNDATION_EXTERN void WPSharedLogvVerbose(NSString *str, va_list args) NS_FORMAT_FUNCTION(1, 0);

NS_ASSUME_NONNULL_END
52 changes: 42 additions & 10 deletions Sources/WordPressSharedObjC/Logging/WPSharedLogging.m
Original file line number Diff line number Diff line change
@@ -1,15 +1,47 @@
#import "WPSharedLogging.h"

#if SWIFT_PACKAGE
#import "../Private/WPSharedLoggingPrivate.h"
#else
#import "WPSharedLoggingPrivate.h"
#endif

DDLogLevel WPSharedGetLoggingLevel() {
return ddLogLevel;
static id<WordPressLoggingDelegate> wordPressSharedLogger = nil;

id<WordPressLoggingDelegate> _Nullable WPSharedGetLoggingDelegate(void)
{
return wordPressSharedLogger;
}

void WPSharedSetLoggingLevel(DDLogLevel level) {
ddLogLevel = level;
void WPSharedSetLoggingDelegate(id<WordPressLoggingDelegate> _Nullable logger)
{
wordPressSharedLogger = logger;
}

#define WPSharedLogv(logFunc) \
({ \
id<WordPressLoggingDelegate> logger = WPSharedGetLoggingDelegate(); \
if (logger == NULL) { \
NSLog(@"[WordPress-Shared] Warning: please call `WPSharedSetLoggingDelegate` to set a error logger."); \
return; \
} \
if (![logger respondsToSelector:@selector(logFunc)]) { \
NSLog(@"[WordPress-Shared] Warning: %@ does not implement " #logFunc, logger); \
return; \
} \
[logger performSelector:@selector(logFunc) withObject:[[NSString alloc] initWithFormat:str arguments:args]]; \
})

#define WPSharedLog(logFunc) \
({ \
va_list args; \
va_start(args, str); \
WPSharedLogv(logFunc); \
va_end(args); \
})

void WPSharedLogError(NSString *str, ...) { WPSharedLog(logError:); }
void WPSharedLogWarning(NSString *str, ...) { WPSharedLog(logWarning:); }
void WPSharedLogInfo(NSString *str, ...) { WPSharedLog(logInfo:); }
void WPSharedLogDebug(NSString *str, ...) { WPSharedLog(logDebug:); }
void WPSharedLogVerbose(NSString *str, ...) { WPSharedLog(logVerbose:); }

void WPSharedLogvError(NSString *str, va_list args) { WPSharedLogv(logError:); }
void WPSharedLogvWarning(NSString *str, va_list args) { WPSharedLogv(logWarning:); }
void WPSharedLogvInfo(NSString *str, va_list args) { WPSharedLogv(logInfo:); }
void WPSharedLogvDebug(NSString *str, va_list args) { WPSharedLogv(logDebug:); }
void WPSharedLogvVerbose(NSString *str, va_list args) { WPSharedLogv(logVerbose:); }
15 changes: 15 additions & 0 deletions Sources/WordPressSharedObjC/Logging/WordPressLoggingDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@protocol WordPressLoggingDelegate <NSObject>

- (void)logError:(NSString *)str;
- (void)logWarning:(NSString *)str;
- (void)logInfo:(NSString *)str;
- (void)logDebug:(NSString *)str;
- (void)logVerbose:(NSString *)str;

@end

NS_ASSUME_NONNULL_END
2 changes: 0 additions & 2 deletions Sources/WordPressSharedObjC/Private/WPSharedLoggingPrivate.h

This file was deleted.

2 changes: 0 additions & 2 deletions Sources/WordPressSharedObjC/Private/WPSharedLoggingPrivate.m

This file was deleted.

11 changes: 3 additions & 8 deletions Sources/WordPressSharedObjC/Utility/NSString+Helpers.m
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
#import "NSString+Helpers.h"
#import <CommonCrypto/CommonDigest.h>
#import "NSString+XMLExtensions.h"

#if SWIFT_PACKAGE
#import "../Private/WPSharedLoggingPrivate.h"
#else
#import "WPSharedLoggingPrivate.h"
#endif
#import "WPSharedLogging.h"

static NSString *const Ellipsis = @"\u2026";

Expand All @@ -20,7 +15,7 @@ @implementation NSString (Helpers)
+ (NSString *)emojiFromCoreEmojiImageTag:(NSString *)tag
{
if ([tag rangeOfString:@"<img"].location == NSNotFound || [tag rangeOfString:@"/images/core/emoji/"].location == NSNotFound) {
DDLogError(@"Tried to extract emoji from a string that was not a core emoji image tag.");
WPSharedLogError(@"Tried to extract emoji from a string that was not a core emoji image tag.");
return nil;
}

Expand Down Expand Up @@ -100,7 +95,7 @@ + (NSString *)stripShortcodesFromString:(NSString *)string
NSString *pattern = @"\\[[^\\]]+\\]";
regex = [[NSRegularExpression alloc] initWithPattern:pattern options:NSRegularExpressionCaseInsensitive error:&error];
if (error) {
DDLogError(@"Error parsing regex: %@", error);
WPSharedLogError(@"Error parsing regex: %@", error);
}
});
NSRange range = NSMakeRange(0, [string length]);
Expand Down
9 changes: 2 additions & 7 deletions Sources/WordPressSharedObjC/Utility/WPImageSource.m
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#import "WPImageSource.h"

#if SWIFT_PACKAGE
#import "../Private/WPSharedLoggingPrivate.h"
#else
#import "WPSharedLoggingPrivate.h"
#endif
#import "WPSharedLogging.h"

NSString * const WPImageSourceErrorDomain = @"WPImageSourceErrorDomain";

Expand Down Expand Up @@ -137,7 +132,7 @@ - (void)downloadSucceededWithNilImageForURL:(NSURL *)url response:(NSURLResponse
{
if ([response isKindOfClass:[NSHTTPURLResponse class]]){
NSHTTPURLResponse *httpURLResponse = (NSHTTPURLResponse *)response;
DDLogError(@"WPImageSource download completed sucessfully but the image was nil. Headers: %@", [httpURLResponse allHeaderFields]);
WPSharedLogError(@"WPImageSource download completed sucessfully but the image was nil. Headers: %@", [httpURLResponse allHeaderFields]);
}
NSString *description = [NSString stringWithFormat:@"A download request ended successfully but the image was nil. URL: %@", [url absoluteString]];
NSError *error = [NSError errorWithDomain:WPImageSourceErrorDomain
Expand Down
Loading

0 comments on commit 280127f

Please sign in to comment.