Skip to content

Commit 09e7121

Browse files
committed
Merge branch 'fix/frizlab/multiline_shenanigans' into develop
2 parents 82a8f93 + 28a0efb commit 09e7121

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

Sources/CLTLogger.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public struct CLTLogger : LogHandler {
9494
/** Multiline logs are allowed and logs are printed after the log, one line per metadata (metadata are never multiline). */
9595
case allMultiline
9696

97-
public static let `default` = Self.disallowMultiline
97+
public static let `default` = Self.disallowMultilineButMetadataOnNewLines
9898
}
9999

100100
public struct Constants : CLTLogger_Sendable {

Sources/String+Utils.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ internal extension String {
9999
prefix = ""
100100
}
101101

102-
if Self.newLines.contains(scalar) {
102+
let isNewLine = Self.newLines.contains(scalar)
103+
if isNewLine {
103104
hasProcessedNewLines = true
104105
switch newLineProcessing {
105106
case .none: return prefix + String(scalar)
@@ -123,7 +124,7 @@ internal extension String {
123124
specialCharState = (scalar, 0)
124125
return prefix + ""
125126
}
126-
let escaped = scalar.escaped(asASCII: asASCII)
127+
let escaped = scalar.escaped(asASCII: asASCII || isNewLine)
127128
//#if swift(>=5.4)
128129
// return prefix + (octothorpLevel == 0 ? escaped : escaped.replacingOccurrences(of: #"\"#, with: #"\"# + octothorps, options: .literal))
129130
//#else

Tests/CLTLoggerTests/CLTLoggerTests.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import XCTest
88

99
final class CLTLoggerTests : XCTestCase {
1010

11+
static let multilineMode: CLTLogger.MultilineMode = .default
12+
1113
override class func setUp() {
1214
/* ⚠️ Also change in the testBasicLogOutputWithAllEmojiSets method if changed here.
1315
* We have not created a variable because we would have to use the @Sendable annotation, which we cannot as we support Swift 5.2. */
14-
LoggingSystem.bootstrap{ _ in CLTLogger(multilineMode: .allMultiline) }
16+
LoggingSystem.bootstrap{ _ in CLTLogger(multilineMode: Self.multilineMode) }
1517
}
1618

1719
/* From <https://apple.github.io/swift-log/docs/current/Logging/Protocols/LogHandler.html#treat-log-level-amp-metadata-as-values>. */
@@ -95,7 +97,7 @@ final class CLTLoggerTests : XCTestCase {
9597
XCTAssertTrue(true, "We only want to see how the log look, so please see the logs.")
9698

9799
for emojiSet in EmojiSet.allCases {
98-
LoggingSystem.bootstrapInternal{ _ in CLTLogger(multilineMode: .allMultiline, constantsByLevel: CLTLogger.defaultConstantsByLogLevelForEmoji(on: .standardError, forcedEmojiSet: emojiSet)) }
100+
LoggingSystem.bootstrapInternal{ _ in CLTLogger(multilineMode: Self.multilineMode, constantsByLevel: CLTLogger.defaultConstantsByLogLevelForEmoji(on: .standardError, forcedEmojiSet: emojiSet)) }
99101
try FileHandle.standardError.write(contentsOf: Data("\n***** \(emojiSet.rawValue) *****\n".utf8))
100102
var logger = Logger(label: "my logger")
101103
logger.logLevel = .trace
@@ -109,7 +111,7 @@ final class CLTLoggerTests : XCTestCase {
109111
}
110112
/* Reset factory.
111113
* ⚠️ Also change in the setUp method if changed here. */
112-
LoggingSystem.bootstrapInternal{ _ in CLTLogger(multilineMode: .allMultiline) }
114+
LoggingSystem.bootstrapInternal{ _ in CLTLogger(multilineMode: Self.multilineMode) }
113115
}
114116

115117
}

Tests/CLTLoggerTests/StringEscapingTests.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,24 @@ final class StringEscapingTests : XCTestCase {
117117
XCTAssertEqual(actual, expected)
118118
}
119119

120+
func testEscapingUtf8Line1() throws {
121+
let actual = "weird\u{0085}newline"
122+
.processForLogging(
123+
escapingMode: .escapeScalars(octothorpLevel: 0, showQuotes: false),
124+
newLineProcessing: .escape
125+
).string
126+
let expected = #"weird\u{0085}newline"#
127+
XCTAssertEqual(actual, expected)
128+
}
129+
130+
func testEscapingUtf8Line2() throws {
131+
let actual = "weird\u{0085}newline"
132+
.processForLogging(
133+
escapingMode: .escapeScalars(octothorpLevel: 0, showQuotes: false),
134+
newLineProcessing: .replace(replacement: "yolo")
135+
).string
136+
let expected = #"weirdyolonewline"#
137+
XCTAssertEqual(actual, expected)
138+
}
139+
120140
}

0 commit comments

Comments
 (0)