Skip to content

Commit

Permalink
Logging: publish all LogSinks, so they can be used as overrides.
Browse files Browse the repository at this point in the history
  • Loading branch information
mickeyl committed Aug 23, 2024
1 parent c4b3ee1 commit b6797fe
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions Sources/CornucopiaCore/Logging/OSLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ import OSLog
extension Cornucopia.Core {

/// A `LogSink` that sends all logs to the Apple `OSLog`.
struct OSLogger: LogSink {
public struct OSLogger: LogSink {

private var loggers: [String: os.Logger] = [:]

init(url: URL = "os://") { }
public init(url: URL = "os://") { }

public static let timeFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss.SSS"
return formatter
}()

func log(_ entry: LogEntry) {
public func log(_ entry: LogEntry) {

let subsystemAndCategory = "\(entry.subsystem)+\(entry.category)"
let logger = self.loggers[subsystemAndCategory, default: .init(subsystem: entry.subsystem, category: entry.category)]
Expand Down
6 changes: 3 additions & 3 deletions Sources/CornucopiaCore/Logging/PrintLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import Foundation
extension Cornucopia.Core {

/// A `LogSink` that sends all logs to `stderr` via print.
struct PrintLogger: LogSink {
public struct PrintLogger: LogSink {

init(url: URL = "print://") { }
public init(url: URL = "print://") { }

public static let timeFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss.SSS"
return formatter
}()

func log(_ entry: LogEntry) {
public func log(_ entry: LogEntry) {
let timestamp = Self.timeFormatter.string(from: entry.timestamp)
let string = "\(timestamp) [\(entry.subsystem):\(entry.category)] <\(entry.thread)> (\(entry.level.character)) \(entry.message)\n"
FileHandle.standardError.write(string)
Expand Down
4 changes: 2 additions & 2 deletions Sources/CornucopiaCore/Logging/SysLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Foundation
extension Cornucopia.Core {

/// A `LogSink` that sends all logs in syslog (via RFC5424) to a given IPv4 host.
final class SysLogger: LogSink {
public final class SysLogger: LogSink {

var sockFd: Int32 = -1
var udp: Bool
Expand All @@ -15,7 +15,7 @@ extension Cornucopia.Core {
lazy var hostname = Device.current.uuid.uuidString
lazy var appname = "\(Bundle.main.CC_cfBundleName)/\(Bundle.main.CC_cfBundleShortVersion).\(Bundle.main.CC_cfBundleVersion)"

init(url: URL) {
public init(url: URL) {

signal(SIGPIPE, SIG_IGN) // Ignore SIGPIPE

Expand Down

0 comments on commit b6797fe

Please sign in to comment.