Skip to content

Commit 5a75928

Browse files
committed
Add terminator property for print logger
1 parent 4901565 commit 5a75928

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Sources/Cosmic/Loggers/PrintLogger.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,22 @@ public class PrintLogger: Logger {
1414

1515
public var formatters: [LogFormatter] = []
1616

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

21+
/// An optional suffix for each message logged.
22+
/// Defaults to an empty string.
1923
public var suffix: String = ""
24+
25+
/// The terminator for each line printed
26+
/// This is used as the `terminator` argument for the `print` function.
27+
public var terminator: String = "\n"
2028

2129
internal var stream: LogOutputStream = StandardOutputStream()
2230

2331
internal var errorStream: LogOutputStream = StandardErrorStream()
2432

25-
2633
public required init() { }
2734

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

3542
if logLevel == .error {
36-
print(message, to: &errorStream)
43+
print(message, terminator: terminator, to: &errorStream)
3744
} else {
38-
print(message, to: &stream)
45+
print(message, terminator: terminator, to: &stream)
3946
}
4047
}
4148

0 commit comments

Comments
 (0)