Skip to content
Open
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
36 changes: 33 additions & 3 deletions Sources/Logging/LogHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,20 @@ public protocol LogHandler: _SwiftLogSendableLogHandler {
/// - file: The file the log message was emitted from.
/// - function: The function the log line was emitted from.
/// - line: The line the log message was emitted from.
func log(
level: Logger.Level,
message: Logger.Message,
error: Error?,
metadata: Logger.Metadata?,
source: String,
file: String,
function: String,
line: UInt
)

/// SwiftLog 1.6 compatibility method. Please do _not_ implement, implement
/// `log(level:message:error:metadata:source:file:function:line:)` instead.
@available(*, deprecated, renamed: "log(level:message:error:metadata:source:file:function:line:)")
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we deprecating this and making error a standardised parameter in all log messages?

Copy link
Author

Choose a reason for hiding this comment

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

My reasoning was that a LogHandler should not have to implement two separate methods - one with errors and one without. But still the error parameter is optional, so it’s not expected to be included in all log post, just that a LogHandler should decide how to include the error in the resulting log post, if passed to the log method.
Of course this is dependent on the other discussion in this PR, whether or not we want the argument to be passed to the handler at all.

func log(
level: Logger.Level,
message: Logger.Message,
Expand All @@ -147,8 +161,8 @@ public protocol LogHandler: _SwiftLogSendableLogHandler {
)

/// SwiftLog 1.0 compatibility method. Please do _not_ implement, implement
/// `log(level:message:metadata:source:file:function:line:)` instead.
@available(*, deprecated, renamed: "log(level:message:metadata:source:file:function:line:)")
/// `log(level:message:error:metadata:source:file:function:line:)` instead.
@available(*, deprecated, renamed: "log(level:message:error:metadata:source:file:function:line:)")
func log(
level: Logging.Logger.Level,
message: Logging.Logger.Message,
Expand Down Expand Up @@ -196,6 +210,7 @@ extension LogHandler {
level: .warning,
message:
"Attempted to set metadataProvider on \(Self.self) that did not implement support for them. Please contact the log handler maintainer to implement metadata provider support.",
error: nil,
metadata: nil,
source: "Logging",
file: #file,
Expand All @@ -210,6 +225,20 @@ extension LogHandler {

extension LogHandler {
@available(*, deprecated, message: "You should implement this method instead of using the default implementation")
public func log(
level: Logger.Level,
message: Logger.Message,
error: Error?,
metadata: Logger.Metadata?,
source: String,
file: String,
function: String,
line: UInt
) {
self.log(level: level, message: message, metadata: metadata, source: source, file: file, function: function, line: line)
}

@available(*, deprecated, renamed: "log(level:message:error:metadata:source:file:function:line:)")
public func log(
level: Logger.Level,
message: Logger.Message,
Expand All @@ -222,7 +251,7 @@ extension LogHandler {
self.log(level: level, message: message, metadata: metadata, file: file, function: function, line: line)
}

@available(*, deprecated, renamed: "log(level:message:metadata:source:file:function:line:)")
@available(*, deprecated, renamed: "log(level:message:error:metadata:source:file:function:line:)")
public func log(
level: Logging.Logger.Level,
message: Logging.Logger.Message,
Expand All @@ -234,6 +263,7 @@ extension LogHandler {
self.log(
level: level,
message: message,
error: nil,
metadata: metadata,
source: Logger.currentModule(filePath: file),
file: file,
Expand Down
Loading