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

Minor update to the log functions API #23637

Merged
merged 3 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions WordPress/Classes/Extensions/UIImageView+SiteIcon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ extension UIImageView {
if case .requestCancelled = error {
// Do not log intentionally cancelled requests as errors.
} else {
DDLogError(error.localizedDescription)
DDLogError("\(error.localizedDescription)")
}
}
})
Expand Down Expand Up @@ -123,7 +123,7 @@ extension UIImageView {

let host = MediaHost(with: blog) { error in
// We'll log the error, so we know it's there, but we won't halt execution.
DDLogError(error.localizedDescription)
DDLogError("\(error.localizedDescription)")
}

let mediaRequestAuthenticator = MediaRequestAuthenticator()
Expand All @@ -133,7 +133,7 @@ extension UIImageView {
onComplete: { [weak self] request in
self?.downloadSiteIcon(with: request, imageSize: imageSize, placeholderImage: placeholderImage)
}) { error in
DDLogError(error.localizedDescription)
DDLogError("\(error.localizedDescription)")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/Services/CommentService+Likes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ extension CommentService {
success(users, totalLikes.intValue, count)
}
}, failure: { error in
DDLogError(String(describing: error))
DDLogError("\(String(describing: error))")
failure(error)
})
}
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/Services/Domains/DomainsService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ struct DomainsService {
guard let blog = try? Blog.lookup(withID: siteID, in: context) else {
let error = "Tried to obtain a Blog for a non-existing site (ID: \(siteID))"
assertionFailure(error)
DDLogError(error)
DDLogError("\(error)")
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/Services/GravatarService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class GravatarService {
onCompletion(profile)

}, failure: { error in
DDLogError(error.debugDescription)
DDLogError("\(error.debugDescription)")
onCompletion(nil)
})
}
Expand Down
6 changes: 3 additions & 3 deletions WordPress/Classes/Services/PeopleService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct PeopleService {
success(users.count, hasMore)
}, on: .main)
}, failure: { error in
DDLogError(String(describing: error))
DDLogError("\(String(describing: error))")
failure?(error)
})
}
Expand All @@ -70,7 +70,7 @@ struct PeopleService {
success(followers.count, hasMore)
}, on: .main)
}, failure: { error in
DDLogError(String(describing: error))
DDLogError("\(String(describing: error))")
failure?(error)
})
}
Expand All @@ -91,7 +91,7 @@ struct PeopleService {
success(viewers.count, hasMore)
}, on: .main)
}, failure: { error in
DDLogError(String(describing: error))
DDLogError("\(String(describing: error))")
failure?(error)
})
}
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/Services/PlanService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ private struct PlanStorage {
guard let blogInContext = try? context.existingObject(with: blog.objectID) as? Blog else {
let error = "Tried to update a plan for a non-existing site"
assertionFailure(error)
DDLogError(error)
DDLogError("\(error)")
return
}
if blogInContext.hasDomainCredit != hasDomainCredit {
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/Services/PostService+Likes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extension PostService {
success(users, totalLikes.intValue, count)
}
}, failure: { error in
DDLogError(String(describing: error))
DDLogError("\(String(describing: error))")
failure(error)
})
}
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/Services/UsersService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ open class UsersService {
onCompletion(profile)

}, failure: { error in
DDLogError(error.debugDescription)
DDLogError("\(error.debugDescription)")
onCompletion(nil)
})
}
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/Stores/ActivityStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class ActivityStore: QueryStore<ActivityStoreState, ActivityQuery> {
}

override func logError(_ error: String) {
DDLogError(error)
DDLogError("\(error)")
}

func processQueries() {
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/Stores/PluginStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class PluginStore: QueryStore<PluginStoreState, PluginQuery> {
}

override func logError(_ error: String) {
DDLogError(error)
DDLogError("\(error)")
}

func processQueries() {
Expand Down
3 changes: 1 addition & 2 deletions WordPress/Classes/Utility/AccountHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ import Foundation
}).joined(separator: "\n")
let blogTreeDescription = !blogsByAccount.isEmpty ? blogTree : "No account/blogs configured on device"

let result = accountsDescription + "\nAll accounts and blogs:\n" + blogTreeDescription
DDLogInfo(result)
DDLogInfo("\(accountsDescription)\nAll accounts and blogs:\n\(blogTreeDescription)")
}

static func logOutDefaultWordPressComAccount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ class BloggingRemindersScheduler {

notificationScheduler.add(request) { (error) in
if let error = error {
DDLogError(error.localizedDescription)
DDLogError("\(error)")
}
}

Expand Down
20 changes: 10 additions & 10 deletions WordPress/Classes/Utility/Logging/CocoaLumberjack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ import Foundation
import CocoaLumberjackSwift

@inlinable
public func DDLogVerbose(_ message: @autoclosure () -> Any, file: StaticString = #file, function: StaticString = #function, line: UInt = #line) {
CocoaLumberjackSwift.DDLogVerbose("\(message())", file: file, function: function, line: line)
public func DDLogVerbose(_ message: @autoclosure () -> DDLogMessageFormat, file: StaticString = #file, function: StaticString = #function, line: UInt = #line) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason we are redefining these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the purpose is making the logging functions available to all files in the project. Otherwise, we'll need to add import CocoaLumberjackSwift in every file that logs thing.

CocoaLumberjackSwift.DDLogVerbose(message(), file: file, function: function, line: line)
}

@inlinable
public func DDLogDebug(_ message: @autoclosure () -> Any, file: StaticString = #file, function: StaticString = #function, line: UInt = #line) {
CocoaLumberjackSwift.DDLogDebug("\(message())", file: file, function: function, line: line)
public func DDLogDebug(_ message: @autoclosure () -> DDLogMessageFormat, file: StaticString = #file, function: StaticString = #function, line: UInt = #line) {
CocoaLumberjackSwift.DDLogDebug(message(), file: file, function: function, line: line)
}

@inlinable
public func DDLogInfo(_ message: @autoclosure () -> Any, file: StaticString = #file, function: StaticString = #function, line: UInt = #line) {
CocoaLumberjackSwift.DDLogInfo("\(message())", file: file, function: function, line: line)
public func DDLogInfo(_ message: @autoclosure () -> DDLogMessageFormat, file: StaticString = #file, function: StaticString = #function, line: UInt = #line) {
CocoaLumberjackSwift.DDLogInfo(message(), file: file, function: function, line: line)
}

@inlinable
public func DDLogWarn(_ message: @autoclosure () -> Any, file: StaticString = #file, function: StaticString = #function, line: UInt = #line) {
CocoaLumberjackSwift.DDLogWarn("\(message())", file: file, function: function, line: line)
public func DDLogWarn(_ message: @autoclosure () -> DDLogMessageFormat, file: StaticString = #file, function: StaticString = #function, line: UInt = #line) {
CocoaLumberjackSwift.DDLogWarn(message(), file: file, function: function, line: line)
}

@inlinable
public func DDLogError(_ message: @autoclosure () -> Any, file: StaticString = #file, function: StaticString = #function, line: UInt = #line) {
CocoaLumberjackSwift.DDLogError("\(message())", file: file, function: function, line: line)
public func DDLogError(_ message: @autoclosure () -> DDLogMessageFormat, file: StaticString = #file, function: StaticString = #function, line: UInt = #line) {
CocoaLumberjackSwift.DDLogError(message(), file: file, function: function, line: line)
}
10 changes: 5 additions & 5 deletions WordPress/Classes/Utility/Logging/WordPressLibraryLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ import WordPressKit
class WordPressLibraryLogger: NSObject, TracksLoggingDelegate, WordPressLoggingDelegate, WordPressKitLoggingDelegate {

func logError(_ str: String) {
DDLogError(str)
DDLogError("\(str)")
}

func logWarning(_ str: String) {
DDLogWarn(str)
DDLogWarn("\(str)")
}

func logInfo(_ str: String) {
DDLogInfo(str)
DDLogInfo("\(str)")
}

func logDebug(_ str: String) {
DDLogDebug(str)
DDLogDebug("\(str)")
}

func logVerbose(_ str: String) {
DDLogVerbose(str)
DDLogVerbose("\(str)")
}
}
2 changes: 1 addition & 1 deletion WordPress/Classes/Utility/PingHubManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ extension PingHubManager: PinghubClientDelegate {
}

func pinghub(_ client: PinghubClient, unexpected message: PinghubClient.Unexpected) {
DDLogError(message.description)
DDLogError("\(message.description)")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private extension RootViewPresenter {
}
completion(topic)
}, failure: { error in
DDLogError("Reader: Error retriving site topic - " + (error?.localizedDescription ?? "unknown failure reason"))
DDLogError("Reader: Error retriving site topic - \(error?.localizedDescription ?? "unknown failure reason")")
completion(nil)
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ import WordPressShared
},
failure: { [weak self] (error: Error) in
let error = error as NSError
DDLogError(error.description)
DDLogError("\(error.description)")
self?.showErrorSyncingMessage(error)
})
}
Expand All @@ -558,7 +558,7 @@ import WordPressShared
self?.reloadButtons()
},
failure: { (error: NSError?) in
DDLogError((error?.description)!)
DDLogError("\(String(describing: error))")
})
}

Expand All @@ -572,7 +572,7 @@ import WordPressShared
},
failure: { (error: Error) in
let error = error as NSError
DDLogError(error.description)
DDLogError("\(error.description)")
})
}

Expand Down Expand Up @@ -658,7 +658,7 @@ import WordPressShared
}
},
failure: { [weak self] (error: NSError?) in
DDLogError((error?.description)!)
DDLogError("\(String(describing: error))")
self?.showErrorSyncingMessage(error)
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -881,15 +881,15 @@ extension GutenbergViewController: GutenbergBridgeDelegate {
func gutenbergDidEmitLog(message: String, logLevel: LogLevel) {
switch logLevel {
case .trace:
DDLogDebug(message)
DDLogDebug("\(message)")
case .info:
DDLogInfo(message)
DDLogInfo("\(message)")
case .warn:
DDLogWarn(message)
DDLogWarn("\(message)")
case .error, .fatal:
DDLogError(message)
DDLogError("\(message)")
@unknown default:
fatalError()
DDLogInfo("\(message)")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ extension GutenbergWebNavigationController: GutenbergWebDelegate {
}

func webController(controller: GutenbergWebSingleBlockViewController, didLog log: String) {
DDLogVerbose(log)
DDLogVerbose("\(log)")
}

private func dismiss(webController: GutenbergWebSingleBlockViewController) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ private extension JetpackConnectionWebViewController {
guard enabled else {
return
}
DDLogDebug(message)
DDLogDebug("\(message)")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class MeViewController: UITableViewController {
guard let account = self.defaultAccount() else {
let error = "Tried to push My Profile without a default account. This shouldn't happen"
assertionFailure(error)
DDLogError(error)
DDLogError("\(error)")
return nil
}

Expand Down Expand Up @@ -500,7 +500,7 @@ class MeViewController: UITableViewController {
let _ = try await [refreshDetails, refreshSettings]
self.reloadViewModel()
} catch let error {
DDLogError(error.localizedDescription)
DDLogError("\(error.localizedDescription)")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ final class PlanListViewController: UITableViewController, ImmuTablePresenter {
self?.updateViewModel()

}, failure: { error in
DDLogInfo(error.debugDescription)
DDLogInfo("\(error.debugDescription)")
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ extension ReaderTagTopic {
}
completion(.success(topics))
} catch {
DDLogError("There was a problem fetching followed tags." + error.localizedDescription)
DDLogError("There was a problem fetching followed tags. \(error.localizedDescription)")
completion(.failure(error))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct ReaderActionHelpers {
do {
return (try context.existingObject(with: objectID)) as? T
} catch let error as NSError {
DDLogError(error.localizedDescription)
DDLogError("\(error.localizedDescription)")
return nil
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ struct ReaderPostCardCellViewModel {
let request = try await mediaRequestAuthenticator.authenticatedRequest(for: url, host: host)
await imageView.downloadImage(usingRequest: request)
} catch {
DDLogError(error)
DDLogError("\(error)")
}
}
}
Expand All @@ -172,7 +172,7 @@ struct ReaderPostCardCellViewModel {
}
let imageSize = featuredImageIdealSize ?? size
let host = MediaHost(with: contentProvider, failure: { error in
DDLogError(error)
DDLogError("\(error)")
})
imageLoader.loadImage(with: url, from: host, preferredSize: imageSize)
}
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/ViewRelated/Reader/ReaderTagCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private extension ReaderTagCell {
let imageSize = CGSize(width: featuredImageView.frame.width,
height: featuredImageView.frame.height)
let host = MediaHost(with: post, failure: { error in
DDLogError(error)
DDLogError("\(error)")
})
imageLoader.loadImage(with: url, from: host, preferredSize: imageSize)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ extension ReaderTabItemsStore {
let items = ReaderHelpers.rearrange(items: topics.map { ReaderTabItem(ReaderContent(topic: $0)) })
self.state = .ready(items)
} catch {
DDLogError(ReaderTopicsConstants.fetchRequestError + error.localizedDescription)
DDLogError("\(ReaderTopicsConstants.fetchRequestError)\(error.localizedDescription)")
self.state = .error(error)
}
}
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Jetpack/Classes/Utility/DataMigrator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private extension DataMigrator {

private func log(error: DataMigrationError, userInfo: [String: Any] = [:]) {
let userInfo = userInfo.merging(self.userInfo(for: error)) { $1 }
DDLogError(error)
DDLogError("\(error)")
crashLogger.logError(error, userInfo: userInfo, level: .error)
}

Expand Down
Loading