85 lines
2.0 KiB
Swift
85 lines
2.0 KiB
Swift
//
|
|
// Swiftfin is subject to the terms of the Mozilla Public
|
|
// License, v2.0. If a copy of the MPL was not distributed with this
|
|
// file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
|
//
|
|
// Copyright (c) 2025 Jellyfin & Jellyfin Contributors
|
|
//
|
|
|
|
import CoreStore
|
|
import Logging
|
|
|
|
struct SwiftfinCorestoreLogger: CoreStoreLogger {
|
|
|
|
private let logger = Logger.swiftfin()
|
|
|
|
func log(
|
|
error: CoreStoreError,
|
|
message: String,
|
|
fileName: StaticString,
|
|
lineNumber: Int,
|
|
functionName: StaticString
|
|
) {
|
|
logger.error(
|
|
"\(message)",
|
|
metadata: nil,
|
|
source: "Corestore",
|
|
file: fileName.description,
|
|
function: functionName.description,
|
|
line: UInt(lineNumber)
|
|
)
|
|
}
|
|
|
|
func log(
|
|
level: LogLevel,
|
|
message: String,
|
|
fileName: StaticString,
|
|
lineNumber: Int,
|
|
functionName: StaticString
|
|
) {
|
|
logger.log(
|
|
level: level.asSwiftLog,
|
|
"\(message)",
|
|
metadata: nil,
|
|
source: "Corestore",
|
|
file: fileName.description,
|
|
function: functionName.description,
|
|
line: UInt(lineNumber)
|
|
)
|
|
}
|
|
|
|
func assert(
|
|
_ condition: @autoclosure () -> Bool,
|
|
message: @autoclosure () -> String,
|
|
fileName: StaticString,
|
|
lineNumber: Int,
|
|
functionName: StaticString
|
|
) {
|
|
guard !condition() else { return }
|
|
logger.critical(
|
|
"\(message())",
|
|
metadata: nil,
|
|
source: "Corestore",
|
|
file: fileName.description,
|
|
function: functionName.description,
|
|
line: UInt(lineNumber)
|
|
)
|
|
}
|
|
}
|
|
|
|
extension CoreStore.LogLevel {
|
|
|
|
var asSwiftLog: Logger.Level {
|
|
switch self {
|
|
case .trace:
|
|
return .trace
|
|
case .notice:
|
|
return .debug
|
|
case .warning:
|
|
return .warning
|
|
case .fatal:
|
|
return .critical
|
|
}
|
|
}
|
|
}
|