Skip to content

Commit 60760a6

Browse files
committed
Introduced OSLogFormatter
1 parent 13a81f9 commit 60760a6

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// Glider
3+
// Fast, Lightweight yet powerful logging system for Swift.
4+
//
5+
// Created & Maintained by Mobile Platforms Team @ ImmobiliareLabs.it
6+
// Email: mobile@immobiliare.it
7+
// Web: http://labs.immobiliare.it
8+
//
9+
// Authors:
10+
// - Daniele Margutti <hello@danielemargutti.com>
11+
//
12+
// Copyright ©2022 Immobiliare.it SpA.
13+
// Licensed under MIT License.
14+
//
15+
16+
import Foundation
17+
18+
/// The`OSLogFormatter` is used to print messages directly on XCode debug console with OSLog.
19+
open class OSLogFormatter: FieldsFormatter {
20+
21+
// MARK: - Initialization
22+
23+
public init() {
24+
super.init(fields: Self.defaultFields())
25+
}
26+
27+
/// Return the default fields of the default `TerminalFormatter` configuration.
28+
///
29+
/// - Parameters:
30+
/// - colorize: colorize mode.
31+
/// - colorizeFields: colorized fields.
32+
/// - Returns: `[FieldsFormatter.Field]`
33+
open class func defaultFields() -> [FieldsFormatter.Field] {
34+
[
35+
.timestamp(style: .iso8601),
36+
.literal(" "),
37+
.message()
38+
].compactMap({ $0 })
39+
}
40+
41+
@available(*, unavailable)
42+
public override init(fields: [FieldsFormatter.Field]) {
43+
fatalError("Use init(options:) for JSONFormatter")
44+
}
45+
46+
}

Glider/Sources/Transports/Console/OSLogTransport.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ extension OSLogTransport {
131131
/// - Parameters:
132132
/// - formatters: formatters to use. Ignore to use the default `XCodeFormatter`.
133133
/// - builder: builder configuration function.
134-
public init(formatters: [EventMessageFormatter] = [XCodeFormatter.init()],
134+
public init(formatters: [EventMessageFormatter] = [OSLogFormatter.init()],
135135
_ builder: ((inout Configuration) -> Void)?) {
136136
self.formatters = formatters
137137
self.queue = DispatchQueue(label: String(describing: type(of: self)), attributes: [])

0 commit comments

Comments
 (0)