Skip to content

Commit 9469c8f

Browse files
fix
Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
1 parent a3cd895 commit 9469c8f

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

Sources/NextcloudKit/Log/NKLogFileManager.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,25 +143,25 @@ public final class NKLogFileManager {
143143
/// - Parameters:
144144
/// - message: The log message to record.
145145
/// - typeTag: Optional log type tag to determine console emoji (e.g. [INFO], [ERROR]).
146-
public func writeLog(_ message: String, typeTag: NKLogTypeTag? = nil) {
147-
guard logLevel != .disabled else { return }
146+
public func writeLog(_ message: String?, typeTag: NKLogTypeTag? = nil) {
147+
guard logLevel != .disabled, let message = message else { return }
148148

149-
// Generate timestamps for file and console
150149
let fileTimestamp = Self.stableTimestampString()
151150
let consoleTimestamp = Self.localizedTimestampString()
152-
153-
// Prepare the clean file line (without emojis or replacements)
154151
let fileLine = "\(fileTimestamp) \(message)\n"
155152

156-
// Determine emoji only if a typeTag is provided
157-
let emojiPrefix = typeTag.map { emojiColored($0.rawValue) } ?? ""
153+
// First emoji based on typeTag (e.g. [ERROR], [DEBUG], etc.)
154+
let emojiFromTag = typeTag.map { emojiColored($0.rawValue) } ?? ""
155+
156+
// Second emoji based on content of message (e.g. [SUCCESS] or [ERROR] keywords)
157+
let emojiFromMessage = emojiColored(message)
158158

159-
// Apply keyword replacements (e.g. [SUCCESS] -> 🟢) only in console
159+
// Build visual message with replacements
160160
let visualMessage = message
161161
.replacingOccurrences(of: "[SUCCESS]", with: "🟢")
162162
.replacingOccurrences(of: "[ERROR]", with: "🔴")
163163

164-
let consoleLine = "[NKLOG] [\(consoleTimestamp)] \(emojiPrefix)\(visualMessage)"
164+
let consoleLine = "[NKLOG] [\(consoleTimestamp)] \(emojiFromTag)\(emojiFromMessage)\(visualMessage)"
165165
print(consoleLine)
166166

167167
rotationQueue.sync {

0 commit comments

Comments
 (0)