diff --git a/Sources/Scribe/LogConfiguration.swift b/Sources/Scribe/LogConfiguration.swift index 7bd3f7c..d4e2fe6 100644 --- a/Sources/Scribe/LogConfiguration.swift +++ b/Sources/Scribe/LogConfiguration.swift @@ -33,6 +33,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. public var autoLoggerCacheLimit: Int? @@ -67,14 +72,16 @@ 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" ) { self.enabledCategories = enabledCategories - self.formatter = nil + formatter = nil 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" + autoLoggerCacheLimit: Int? = 100 ) { self.enabledCategories = enabledCategories self.formatter = formatter - self.includeTimestamp = true - self.includeEmoji = true - self.includeShortCode = false + includeTimestamp = true + includeEmoji = true + includeShortCode = false + includeFileAndLineNumber = true self.autoLoggerCacheLimit = autoLoggerCacheLimit - self.dateFormat = dateFormat + 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..c66a1a6 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 {