From 2ada97bda334203ceef3d776d9ab28e0505a35d6 Mon Sep 17 00:00:00 2001 From: Kai Azim Date: Mon, 8 Dec 2025 16:01:19 -0700 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8=20Add=20option=20to=20not=20inclu?= =?UTF-8?q?de=20file=20and=20line=20number=20in=20default=20log=20formatte?= =?UTF-8?q?r?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/Scribe/LogConfiguration.swift | 13 +++++++++---- Sources/Scribe/LogManager.swift | 12 ++++++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Sources/Scribe/LogConfiguration.swift b/Sources/Scribe/LogConfiguration.swift index 7bd3f7c..e2b93a8 100644 --- a/Sources/Scribe/LogConfiguration.swift +++ b/Sources/Scribe/LogConfiguration.swift @@ -32,6 +32,11 @@ public struct LogConfiguration: Sendable { /// /// Only used by the built-in formatter. public var includeShortCode: Bool + + /// Whether to include the file and line number in the format: [file]:[line number]. + /// + /// Only used by the built-in formatter. + public var includeFileAndLineNumber: Bool /// Maximum number of cached auto-generated `Logger` instances (e.g., categories from `#fileID`). `nil` means /// unbounded. Default is 100. @@ -67,6 +72,7 @@ public struct LogConfiguration: Sendable { includeTimestamp: Bool = true, includeEmoji: Bool = true, includeShortCode: Bool = false, + includeFileAndLineNumber: Bool = true, autoLoggerCacheLimit: Int? = 100, dateFormat: String = "yyyy-MM-dd HH:mm:ss.SSSZ" ) { @@ -75,6 +81,7 @@ public struct LogConfiguration: Sendable { self.includeTimestamp = includeTimestamp self.includeEmoji = includeEmoji self.includeShortCode = includeShortCode + self.includeFileAndLineNumber = includeFileAndLineNumber self.autoLoggerCacheLimit = autoLoggerCacheLimit self.dateFormat = dateFormat } @@ -88,21 +95,19 @@ public struct LogConfiguration: Sendable { /// - formatter: Custom formatter closure used to build the final log line. /// - autoLoggerCacheLimit: Maximum cached auto-generated `Logger` instances. Pass `nil` for no limit. Default is /// 100. - /// - dateFormat: Timestamp format string supplied for convenience to formatter users. Default is - /// `"yyyy-MM-dd HH:mm:ss.SSSZ"`. public init( enabledCategories: Set? = nil, formatter: @escaping @Sendable (FormatterContext) -> String, autoLoggerCacheLimit: Int? = 100, - dateFormat: String = "yyyy-MM-dd HH:mm:ss.SSSZ" ) { self.enabledCategories = enabledCategories self.formatter = formatter self.includeTimestamp = true self.includeEmoji = true self.includeShortCode = false + self.includeFileAndLineNumber = true self.autoLoggerCacheLimit = autoLoggerCacheLimit - self.dateFormat = dateFormat + self.dateFormat = "yyyy-MM-dd HH:mm:ss.SSSZ" } /// Default configuration with timestamps enabled and all categories allowed. diff --git a/Sources/Scribe/LogManager.swift b/Sources/Scribe/LogManager.swift index c02c101..2053829 100644 --- a/Sources/Scribe/LogManager.swift +++ b/Sources/Scribe/LogManager.swift @@ -259,16 +259,24 @@ public final class LogManager: @unchecked Sendable { if let tsComponent { parts.append(tsComponent) } + if cfg.includeEmoji { parts.append(level.emoji) } + if cfg.includeShortCode { parts.append("[\(level.shortCode)]") } + parts.append("[\(category.name)]") parts.append(message) - let fileName = (file as NSString).lastPathComponent - formatted = "\(parts.joined(separator: " ")) — \(fileName):\(line)" + + if cfg.includeFileAndLineNumber { + let fileName = (file as NSString).lastPathComponent + parts.append("— \(fileName):\(line)") + } + + formatted = parts.joined(separator: " ") } switch level.osLogType { From 10796d0dcd50957c3e74e947fe20b0a38aa89e5b Mon Sep 17 00:00:00 2001 From: Kai Azim Date: Mon, 8 Dec 2025 16:10:38 -0700 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=8E=A8=20Format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/Scribe/LogConfiguration.swift | 16 ++++++++-------- Sources/Scribe/LogManager.swift | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Sources/Scribe/LogConfiguration.swift b/Sources/Scribe/LogConfiguration.swift index e2b93a8..d4e2fe6 100644 --- a/Sources/Scribe/LogConfiguration.swift +++ b/Sources/Scribe/LogConfiguration.swift @@ -32,7 +32,7 @@ public struct LogConfiguration: Sendable { /// /// Only used by the built-in formatter. public var includeShortCode: Bool - + /// Whether to include the file and line number in the format: [file]:[line number]. /// /// Only used by the built-in formatter. @@ -77,7 +77,7 @@ public struct LogConfiguration: Sendable { dateFormat: String = "yyyy-MM-dd HH:mm:ss.SSSZ" ) { self.enabledCategories = enabledCategories - self.formatter = nil + formatter = nil self.includeTimestamp = includeTimestamp self.includeEmoji = includeEmoji self.includeShortCode = includeShortCode @@ -98,16 +98,16 @@ public struct LogConfiguration: Sendable { public init( enabledCategories: Set? = nil, formatter: @escaping @Sendable (FormatterContext) -> String, - autoLoggerCacheLimit: Int? = 100, + autoLoggerCacheLimit: Int? = 100 ) { self.enabledCategories = enabledCategories self.formatter = formatter - self.includeTimestamp = true - self.includeEmoji = true - self.includeShortCode = false - self.includeFileAndLineNumber = true + includeTimestamp = true + includeEmoji = true + includeShortCode = false + includeFileAndLineNumber = true self.autoLoggerCacheLimit = autoLoggerCacheLimit - self.dateFormat = "yyyy-MM-dd HH:mm:ss.SSSZ" + dateFormat = "yyyy-MM-dd HH:mm:ss.SSSZ" } /// Default configuration with timestamps enabled and all categories allowed. diff --git a/Sources/Scribe/LogManager.swift b/Sources/Scribe/LogManager.swift index 2053829..c66a1a6 100644 --- a/Sources/Scribe/LogManager.swift +++ b/Sources/Scribe/LogManager.swift @@ -275,7 +275,7 @@ public final class LogManager: @unchecked Sendable { let fileName = (file as NSString).lastPathComponent parts.append("— \(fileName):\(line)") } - + formatted = parts.joined(separator: " ") }