Skip to content
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
2 changes: 1 addition & 1 deletion .swiftformat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Compiler
--languagemode 5
--swiftversion 5.9
--swiftversion 6.2

# Options
--exclude derivedData
Expand Down
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ let package = Package(
.product(name: "StatementSQLite", package: "Statement"),
.product(name: "SQLite", package: "SQLite.swift"),
.product(name: "Mutex", package: "swift-mutex"),
]
],
),
.testTarget(
name: "OccurrenceTests",
dependencies: [
.product(name: "Logging", package: "swift-log"),
"Occurrence",
]
],
),
]
],
)

for target in package.targets {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Occurrence/CoreData/CoreDataLogProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ final class CoreDataLogProvider: LogProvider {
ofType: NSSQLiteStoreType,
configurationName: coordinator.name,
at: storeUrl,
options: options
options: options,
)
try coordinator.remove(store)
} catch {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Occurrence/CoreData/ManagedEntry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ extension ManagedEntry {
source: source,
file: file,
function: function,
line: UInt(line)
line: UInt(line),
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Occurrence/Extensions/Logger+Entry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public extension Logger {
source: String,
file: String = #fileID,
function: String = #function,
line: UInt = #line
line: UInt = #line,
) {
self.date = date
self.subsystem = subsystem
Expand Down
12 changes: 6 additions & 6 deletions Sources/Occurrence/Extensions/Logger+Occurrence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public extension Logger {
source: @autoclosure () -> String? = nil,
file: String = #file,
function: String = #function,
line: UInt = #line
line: UInt = #line,
) -> T {
log(
level: level,
Expand All @@ -31,7 +31,7 @@ public extension Logger {
source: source(),
file: file,
function: function,
line: line
line: line,
)

return error
Expand All @@ -56,7 +56,7 @@ public extension Logger {
source: @autoclosure () -> String? = nil,
file: String = #file,
function: String = #function,
line: UInt = #line
line: UInt = #line,
) {
log(
level: level,
Expand All @@ -65,7 +65,7 @@ public extension Logger {
source: source(),
file: file,
function: function,
line: line
line: line,
)
}

Expand All @@ -88,7 +88,7 @@ public extension Logger {
source: @autoclosure () -> String? = nil,
file: String = #file,
function: String = #function,
line: UInt = #line
line: UInt = #line,
) {
guard let jsonObject = try? JSONSerialization.jsonObject(with: data) else {
log(level: level, message(), source: source(), file: file, function: function, line: line)
Expand Down Expand Up @@ -127,7 +127,7 @@ public extension Logger {
source: @autoclosure () -> String? = nil,
file: String = #file,
function: String = #function,
line: UInt = #line
line: UInt = #line,
) {
guard let data = try? JSONEncoder().encode(encodable) else {
log(level: level, message(), source: source(), file: file, function: function, line: line)
Expand Down
12 changes: 10 additions & 2 deletions Sources/Occurrence/Occurrence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,15 @@ public struct Occurrence: LogHandler {
}
}

public func log(level: Logger.Level, message: Logger.Message, metadata: Logger.Metadata?, source: String, file: String, function: String, line: UInt) {
public func log(
level: Logger.Level,
message: Logger.Message,
metadata: Logger.Metadata?,
source: String,
file: String,
function: String,
line: UInt,
) {
let joinedMetadata: Logger.Metadata? = switch (metadata, metadataProvider?.get()) {
case (.some(let instance), .some(let context)):
instance.merging(context, uniquingKeysWith: { instanceValue, _ in instanceValue })
Expand All @@ -93,7 +101,7 @@ public struct Occurrence: LogHandler {
source: source,
file: file,
function: function,
line: line
line: line,
)

if Self.configuration.outputToConsole {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Occurrence/SQLite/Logger.Filter+Where.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ extension Logger.Filter {
[
.AND(
.column(SQLiteEntry.date, op: .greaterThanEqualTo, value: start),
.column(SQLiteEntry.date, op: .lessThanEqualTo, value: end)
.column(SQLiteEntry.date, op: .lessThanEqualTo, value: end),
),
]
case .and(let filters):
Expand Down Expand Up @@ -74,7 +74,7 @@ extension Logger.Filter {
[
.AND(
.column(SQLiteEntry.date, op: .lessThan, value: start),
.column(SQLiteEntry.date, op: .greaterThan, value: end)
.column(SQLiteEntry.date, op: .greaterThan, value: end),
),
]
case .and(let filters):
Expand Down
46 changes: 23 additions & 23 deletions Sources/Occurrence/SQLite/SQLiteLogProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class SQLiteLogProvider: LogProvider {
.column(SQLiteEntry.source),
.column(SQLiteEntry.file),
.column(SQLiteEntry.function),
.column(SQLiteEntry.line)
.column(SQLiteEntry.line),
),
.VALUES(
.value(sqlEntry.date),
Expand All @@ -45,8 +45,8 @@ final class SQLiteLogProvider: LogProvider {
.value(sqlEntry.source),
.value(sqlEntry.file),
.value(sqlEntry.function),
.value(sqlEntry.line)
)
.value(sqlEntry.line),
),
).render()

do {
Expand All @@ -61,9 +61,9 @@ final class SQLiteLogProvider: LogProvider {

let statement = SQLiteStatement(
.SELECT_DISTINCT(
.column(SQLiteEntry.subsystem)
.column(SQLiteEntry.subsystem),
),
.FROM_TABLE(SQLiteEntry.self)
.FROM_TABLE(SQLiteEntry.self),
)

let sql = statement.render()
Expand Down Expand Up @@ -97,14 +97,14 @@ final class SQLiteLogProvider: LogProvider {
.column(SQLiteEntry.source),
.column(SQLiteEntry.file),
.column(SQLiteEntry.function),
.column(SQLiteEntry.line)
.column(SQLiteEntry.line),
),
.FROM_TABLE(SQLiteEntry.self),
.WHERE(loggerFilter.whereClause),
.ORDER_BY(
.column(SQLiteEntry.date, op: ascending ? .asc : .desc)
.column(SQLiteEntry.date, op: ascending ? .asc : .desc),
),
.LIMIT(Int(x))
.LIMIT(Int(x)),
)
case (.some(let loggerFilter), let x) where x == 0:
SQLiteStatement(
Expand All @@ -118,13 +118,13 @@ final class SQLiteLogProvider: LogProvider {
.column(SQLiteEntry.source),
.column(SQLiteEntry.file),
.column(SQLiteEntry.function),
.column(SQLiteEntry.line)
.column(SQLiteEntry.line),
),
.FROM_TABLE(SQLiteEntry.self),
.WHERE(loggerFilter.whereClause),
.ORDER_BY(
.column(SQLiteEntry.date, op: ascending ? .asc : .desc)
)
.column(SQLiteEntry.date, op: ascending ? .asc : .desc),
),
)
case (.none, let x) where x > 0:
SQLiteStatement(
Expand All @@ -138,13 +138,13 @@ final class SQLiteLogProvider: LogProvider {
.column(SQLiteEntry.source),
.column(SQLiteEntry.file),
.column(SQLiteEntry.function),
.column(SQLiteEntry.line)
.column(SQLiteEntry.line),
),
.FROM_TABLE(SQLiteEntry.self),
.ORDER_BY(
.column(SQLiteEntry.date, op: ascending ? .asc : .desc)
.column(SQLiteEntry.date, op: ascending ? .asc : .desc),
),
.LIMIT(Int(x))
.LIMIT(Int(x)),
)
default:
SQLiteStatement(
Expand All @@ -158,12 +158,12 @@ final class SQLiteLogProvider: LogProvider {
.column(SQLiteEntry.source),
.column(SQLiteEntry.file),
.column(SQLiteEntry.function),
.column(SQLiteEntry.line)
.column(SQLiteEntry.line),
),
.FROM_TABLE(SQLiteEntry.self),
.ORDER_BY(
.column(SQLiteEntry.date, op: ascending ? .asc : .desc)
)
.column(SQLiteEntry.date, op: ascending ? .asc : .desc),
),
)
}

Expand All @@ -190,7 +190,7 @@ final class SQLiteLogProvider: LogProvider {
source: row[6] as! String,
file: row[7] as! String,
function: row[8] as! String,
line: Int(row[9] as! Int64)
line: Int(row[9] as! Int64),
)

entries.append(Logger.Entry(entry))
Expand All @@ -207,12 +207,12 @@ final class SQLiteLogProvider: LogProvider {
SQLiteStatement(
.DELETE_FROM(SQLiteEntry.self),
.WHERE(
filter.whereClause
)
filter.whereClause,
),
)
} else {
SQLiteStatement(
.DELETE_FROM(SQLiteEntry.self)
.DELETE_FROM(SQLiteEntry.self),
)
}

Expand All @@ -235,8 +235,8 @@ extension Connection {

let sql = SQLiteStatement(
.CREATE(
.SCHEMA(SQLiteEntry.instance, ifNotExists: true)
)
.SCHEMA(SQLiteEntry.instance, ifNotExists: true),
),
).render()

do {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Occurrence/SwiftUI/LogView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public struct LogView: View {
/// - exportAction: Handler to be called when log entries are exported.
public init(
allowManagement: Bool = true,
exportAction: (([Logger.Entry]) -> Void)? = nil
exportAction: (([Logger.Entry]) -> Void)? = nil,
) {
_allowManagement = State(wrappedValue: allowManagement)
self.exportAction = exportAction
Expand Down
8 changes: 4 additions & 4 deletions Sources/Occurrence/SwiftUI/PreviewLogProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ extension Logger.Entry {
source: "",
file: "PermissionManager.swift",
function: "requestPermissions()",
line: 169
line: 169,
)

static let two = Logger.Entry(
Expand All @@ -54,7 +54,7 @@ extension Logger.Entry {
source: "",
file: "AuthenticationManager.swift",
function: "checkAuthenticationState()",
line: 65
line: 65,
)

static let three = Logger.Entry(
Expand All @@ -72,7 +72,7 @@ extension Logger.Entry {
source: "",
file: "AppDelegate.swift",
function: "application(_:didFinishLaunchingWithOptions:)",
line: 24
line: 24,
)

static let four = Logger.Entry(
Expand All @@ -84,6 +84,6 @@ extension Logger.Entry {
source: "",
file: "NetworkManager.swift",
function: "get(request:)",
line: 402
line: 402,
)
}
2 changes: 1 addition & 1 deletion Tests/OccurrenceTests/LogProviderTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class LogProviderTestCase: XCTestCase {
day: 1,
hour: 15,
minute: 30,
second: 0
second: 0,
)

january1st_1530 = try XCTUnwrap(gregorian.date(from: components))
Expand Down
4 changes: 2 additions & 2 deletions Tests/OccurrenceTests/LoggableErrorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ final class LoggableErrorTests: XCTestCase {

let context = EncodingError.Context(
codingPath: [Logger.MetadataKey.description, Logger.MetadataKey.file],
debugDescription: "Bad data."
debugDescription: "Bad data.",
)
let error = EncodingError.invalidValue(FileRef(), context)
let metadata = error.metadata
Expand All @@ -112,7 +112,7 @@ final class LoggableErrorTests: XCTestCase {
func testDecodingErrorConformance() throws {
let context = DecodingError.Context(
codingPath: [Logger.MetadataKey.code],
debugDescription: "Unexpected type."
debugDescription: "Unexpected type.",
)
let error = DecodingError.typeMismatch(Int.self, context)
let metadata = error.metadata
Expand Down