Skip to content

Commit

Permalink
Add terminator property for print logger
Browse files Browse the repository at this point in the history
  • Loading branch information
jnewc committed May 19, 2020
1 parent 4901565 commit 5a75928
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions Sources/Cosmic/Loggers/PrintLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,22 @@ public class PrintLogger: Logger {

public var formatters: [LogFormatter] = []

/// An optional prefix for each message logged.
/// Defaults to an empty string.
public var prefix: String = ""

/// An optional suffix for each message logged.
/// Defaults to an empty string.
public var suffix: String = ""

/// The terminator for each line printed
/// This is used as the `terminator` argument for the `print` function.
public var terminator: String = "\n"

internal var stream: LogOutputStream = StandardOutputStream()

internal var errorStream: LogOutputStream = StandardErrorStream()


public required init() { }

public func log(_ message: String, logLevel: LogLevel, metadata: LogMetadata) {
Expand All @@ -33,9 +40,9 @@ public class PrintLogger: Logger {
let message = "\(prefix)\(line)\(suffix)"

if logLevel == .error {
print(message, to: &errorStream)
print(message, terminator: terminator, to: &errorStream)
} else {
print(message, to: &stream)
print(message, terminator: terminator, to: &stream)
}
}

Expand Down

0 comments on commit 5a75928

Please sign in to comment.