Skip to content

Commit

Permalink
Introduced OSLogFormatter
Browse files Browse the repository at this point in the history
  • Loading branch information
malcommac committed Jul 11, 2023
1 parent 13a81f9 commit 60760a6
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
46 changes: 46 additions & 0 deletions Glider/Sources/Formatters/OSLogFormatter/OSLogFormatter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// Glider
// Fast, Lightweight yet powerful logging system for Swift.
//
// Created & Maintained by Mobile Platforms Team @ ImmobiliareLabs.it
// Email: mobile@immobiliare.it
// Web: http://labs.immobiliare.it
//
// Authors:
// - Daniele Margutti <hello@danielemargutti.com>
//
// Copyright ©2022 Immobiliare.it SpA.
// Licensed under MIT License.
//

import Foundation

/// The`OSLogFormatter` is used to print messages directly on XCode debug console with OSLog.
open class OSLogFormatter: FieldsFormatter {

// MARK: - Initialization

public init() {
super.init(fields: Self.defaultFields())
}

/// Return the default fields of the default `TerminalFormatter` configuration.
///
/// - Parameters:
/// - colorize: colorize mode.
/// - colorizeFields: colorized fields.
/// - Returns: `[FieldsFormatter.Field]`
open class func defaultFields() -> [FieldsFormatter.Field] {
[
.timestamp(style: .iso8601),
.literal(" "),
.message()
].compactMap({ $0 })
}

@available(*, unavailable)
public override init(fields: [FieldsFormatter.Field]) {
fatalError("Use init(options:) for JSONFormatter")
}

}
2 changes: 1 addition & 1 deletion Glider/Sources/Transports/Console/OSLogTransport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ extension OSLogTransport {
/// - Parameters:
/// - formatters: formatters to use. Ignore to use the default `XCodeFormatter`.
/// - builder: builder configuration function.
public init(formatters: [EventMessageFormatter] = [XCodeFormatter.init()],
public init(formatters: [EventMessageFormatter] = [OSLogFormatter.init()],
_ builder: ((inout Configuration) -> Void)?) {
self.formatters = formatters
self.queue = DispatchQueue(label: String(describing: type(of: self)), attributes: [])
Expand Down

0 comments on commit 60760a6

Please sign in to comment.