diff --git a/CleanroomLogger.xcodeproj/project.pbxproj b/CleanroomLogger.xcodeproj/project.pbxproj index be6353fd..0cd073c2 100644 --- a/CleanroomLogger.xcodeproj/project.pbxproj +++ b/CleanroomLogger.xcodeproj/project.pbxproj @@ -11,11 +11,7 @@ 3B475D271DB47B8A0047D397 /* BasicLogConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B475D001DB47B8A0047D397 /* BasicLogConfiguration.swift */; }; 3B475D281DB47B8A0047D397 /* CallingThreadLogFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B475D011DB47B8A0047D397 /* CallingThreadLogFormatter.swift */; }; 3B475D291DB47B8A0047D397 /* CallSiteLogFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B475D021DB47B8A0047D397 /* CallSiteLogFormatter.swift */; }; - 3B475D2A1DB47B8A0047D397 /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B475D031DB47B8A0047D397 /* Color.swift */; }; - 3B475D2B1DB47B8A0047D397 /* ColorizingLogFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B475D041DB47B8A0047D397 /* ColorizingLogFormatter.swift */; }; - 3B475D2C1DB47B8A0047D397 /* ColorTable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B475D051DB47B8A0047D397 /* ColorTable.swift */; }; 3B475D2D1DB47B8A0047D397 /* ConcatenatingLogFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B475D061DB47B8A0047D397 /* ConcatenatingLogFormatter.swift */; }; - 3B475D2E1DB47B8A0047D397 /* DefaultColorTable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B475D071DB47B8A0047D397 /* DefaultColorTable.swift */; }; 3B475D2F1DB47B8A0047D397 /* DelimiterLogFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B475D081DB47B8A0047D397 /* DelimiterLogFormatter.swift */; }; 3B475D301DB47B8A0047D397 /* FieldBasedLogFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B475D091DB47B8A0047D397 /* FieldBasedLogFormatter.swift */; }; 3B475D311DB47B8A0047D397 /* FileLogRecorder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B475D0A1DB47B8A0047D397 /* FileLogRecorder.swift */; }; @@ -39,9 +35,7 @@ 3B475D451DB47B8A0047D397 /* StackFrameLogFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B475D1E1DB47B8A0047D397 /* StackFrameLogFormatter.swift */; }; 3B475D461DB47B8A0047D397 /* StandardLogFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B475D1F1DB47B8A0047D397 /* StandardLogFormatter.swift */; }; 3B475D471DB47B8A0047D397 /* StandardOutputLogRecorder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B475D201DB47B8A0047D397 /* StandardOutputLogRecorder.swift */; }; - 3B475D481DB47B8A0047D397 /* TextColorizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B475D211DB47B8A0047D397 /* TextColorizer.swift */; }; 3B475D491DB47B8A0047D397 /* TimestampLogFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B475D221DB47B8A0047D397 /* TimestampLogFormatter.swift */; }; - 3B475D4A1DB47B8A0047D397 /* XcodeColorsTextColorizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B475D231DB47B8A0047D397 /* XcodeColorsTextColorizer.swift */; }; 3B475D4B1DB47B8A0047D397 /* XcodeLogConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B475D241DB47B8A0047D397 /* XcodeLogConfiguration.swift */; }; 3B475D4C1DB47B8A0047D397 /* XcodeLogFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B475D251DB47B8A0047D397 /* XcodeLogFormatter.swift */; }; 3B475D501DB47BD50047D397 /* LoggingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B475D4E1DB47BD50047D397 /* LoggingTests.swift */; }; @@ -65,11 +59,7 @@ 3B475D001DB47B8A0047D397 /* BasicLogConfiguration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicLogConfiguration.swift; sourceTree = ""; }; 3B475D011DB47B8A0047D397 /* CallingThreadLogFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CallingThreadLogFormatter.swift; sourceTree = ""; }; 3B475D021DB47B8A0047D397 /* CallSiteLogFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CallSiteLogFormatter.swift; sourceTree = ""; }; - 3B475D031DB47B8A0047D397 /* Color.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Color.swift; sourceTree = ""; }; - 3B475D041DB47B8A0047D397 /* ColorizingLogFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColorizingLogFormatter.swift; sourceTree = ""; }; - 3B475D051DB47B8A0047D397 /* ColorTable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColorTable.swift; sourceTree = ""; }; 3B475D061DB47B8A0047D397 /* ConcatenatingLogFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConcatenatingLogFormatter.swift; sourceTree = ""; }; - 3B475D071DB47B8A0047D397 /* DefaultColorTable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DefaultColorTable.swift; sourceTree = ""; }; 3B475D081DB47B8A0047D397 /* DelimiterLogFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DelimiterLogFormatter.swift; sourceTree = ""; }; 3B475D091DB47B8A0047D397 /* FieldBasedLogFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FieldBasedLogFormatter.swift; sourceTree = ""; }; 3B475D0A1DB47B8A0047D397 /* FileLogRecorder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileLogRecorder.swift; sourceTree = ""; }; @@ -93,9 +83,7 @@ 3B475D1E1DB47B8A0047D397 /* StackFrameLogFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StackFrameLogFormatter.swift; sourceTree = ""; }; 3B475D1F1DB47B8A0047D397 /* StandardLogFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StandardLogFormatter.swift; sourceTree = ""; }; 3B475D201DB47B8A0047D397 /* StandardOutputLogRecorder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StandardOutputLogRecorder.swift; sourceTree = ""; }; - 3B475D211DB47B8A0047D397 /* TextColorizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextColorizer.swift; sourceTree = ""; }; 3B475D221DB47B8A0047D397 /* TimestampLogFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TimestampLogFormatter.swift; sourceTree = ""; }; - 3B475D231DB47B8A0047D397 /* XcodeColorsTextColorizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XcodeColorsTextColorizer.swift; sourceTree = ""; }; 3B475D241DB47B8A0047D397 /* XcodeLogConfiguration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XcodeLogConfiguration.swift; sourceTree = ""; }; 3B475D251DB47B8A0047D397 /* XcodeLogFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XcodeLogFormatter.swift; sourceTree = ""; }; 3B475D4E1DB47BD50047D397 /* LoggingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoggingTests.swift; sourceTree = ""; }; @@ -139,11 +127,7 @@ 3B475D001DB47B8A0047D397 /* BasicLogConfiguration.swift */, 3B475D011DB47B8A0047D397 /* CallingThreadLogFormatter.swift */, 3B475D021DB47B8A0047D397 /* CallSiteLogFormatter.swift */, - 3B475D031DB47B8A0047D397 /* Color.swift */, - 3B475D041DB47B8A0047D397 /* ColorizingLogFormatter.swift */, - 3B475D051DB47B8A0047D397 /* ColorTable.swift */, 3B475D061DB47B8A0047D397 /* ConcatenatingLogFormatter.swift */, - 3B475D071DB47B8A0047D397 /* DefaultColorTable.swift */, 3B475D081DB47B8A0047D397 /* DelimiterLogFormatter.swift */, 3B475D091DB47B8A0047D397 /* FieldBasedLogFormatter.swift */, 3B475D0A1DB47B8A0047D397 /* FileLogRecorder.swift */, @@ -167,9 +151,7 @@ 3B475D1E1DB47B8A0047D397 /* StackFrameLogFormatter.swift */, 3B475D1F1DB47B8A0047D397 /* StandardLogFormatter.swift */, 3B475D201DB47B8A0047D397 /* StandardOutputLogRecorder.swift */, - 3B475D211DB47B8A0047D397 /* TextColorizer.swift */, 3B475D221DB47B8A0047D397 /* TimestampLogFormatter.swift */, - 3B475D231DB47B8A0047D397 /* XcodeColorsTextColorizer.swift */, 3B475D241DB47B8A0047D397 /* XcodeLogConfiguration.swift */, 3B475D251DB47B8A0047D397 /* XcodeLogFormatter.swift */, ); @@ -354,7 +336,6 @@ 3B475D281DB47B8A0047D397 /* CallingThreadLogFormatter.swift in Sources */, 3B475D491DB47B8A0047D397 /* TimestampLogFormatter.swift in Sources */, 3B475D3F1DB47B8A0047D397 /* ReadableLogFormatter.swift in Sources */, - 3B475D2C1DB47B8A0047D397 /* ColorTable.swift in Sources */, 3B475D4B1DB47B8A0047D397 /* XcodeLogConfiguration.swift in Sources */, 3B475D431DB47B8A0047D397 /* RotatingLogFileRecorder.swift in Sources */, 3B475D471DB47B8A0047D397 /* StandardOutputLogRecorder.swift in Sources */, @@ -362,14 +343,10 @@ 3B475D3E1DB47B8A0047D397 /* PayloadLogFormatter.swift in Sources */, 3B475D271DB47B8A0047D397 /* BasicLogConfiguration.swift in Sources */, 3B475D311DB47B8A0047D397 /* FileLogRecorder.swift in Sources */, - 3B475D2B1DB47B8A0047D397 /* ColorizingLogFormatter.swift in Sources */, - 3B475D2E1DB47B8A0047D397 /* DefaultColorTable.swift in Sources */, - 3B475D2A1DB47B8A0047D397 /* Color.swift in Sources */, 3B475D331DB47B8A0047D397 /* Log.swift in Sources */, 3B475D301DB47B8A0047D397 /* FieldBasedLogFormatter.swift in Sources */, 3B475D391DB47B8A0047D397 /* LogReceptacle.swift in Sources */, 3B475D351DB47B8A0047D397 /* LogConfiguration.swift in Sources */, - 3B475D481DB47B8A0047D397 /* TextColorizer.swift in Sources */, 3B475D381DB47B8A0047D397 /* LogFormatter.swift in Sources */, 3B475D2D1DB47B8A0047D397 /* ConcatenatingLogFormatter.swift in Sources */, 3B475D261DB47B8A0047D397 /* ASLLogRecorder.swift in Sources */, @@ -378,7 +355,6 @@ 3B475D321DB47B8A0047D397 /* LiteralLogFormatter.swift in Sources */, 3B475D3B1DB47B8A0047D397 /* LogRecorderBase.swift in Sources */, 3B475D461DB47B8A0047D397 /* StandardLogFormatter.swift in Sources */, - 3B475D4A1DB47B8A0047D397 /* XcodeColorsTextColorizer.swift in Sources */, 3B475D3D1DB47B8A0047D397 /* ParsableLogFormatter.swift in Sources */, 3B475D4C1DB47B8A0047D397 /* XcodeLogFormatter.swift in Sources */, 3B475D2F1DB47B8A0047D397 /* DelimiterLogFormatter.swift in Sources */, diff --git a/Sources/Color.swift b/Sources/Color.swift deleted file mode 100644 index d5047b0d..00000000 --- a/Sources/Color.swift +++ /dev/null @@ -1,44 +0,0 @@ -// -// Color.swift -// CleanroomLogger -// -// Created by Evan Maloney on 12/16/15. -// Copyright © 2015 Gilt Groupe. All rights reserved. -// - -/** - Represents a 3-component RGB color where each component is 8 bits. - Used for specifying log output colors. -*/ -public struct Color -{ - /** A type representing a single color component. A value of `0x00` - represents absense of the color, while `0xFF` indicates color at - full brightness. */ - public typealias Component = UInt8 - - /** The red component of the color. */ - public private(set) var r: Component - - /** The green component of the color. */ - public private(set) var g: Component - - /** The blue component of the color. */ - public private(set) var b: Component - - /** - Color initializer. - - - parameter r: The red component - - - parameter g: The green component - - - parameter b: The blue component - */ - public init(r: Component, g: Component, b: Component) - { - self.r = r - self.g = g - self.b = b - } -} diff --git a/Sources/ColorTable.swift b/Sources/ColorTable.swift deleted file mode 100644 index 0a59212a..00000000 --- a/Sources/ColorTable.swift +++ /dev/null @@ -1,57 +0,0 @@ -// -// ColorTable.swift -// CleanroomLogger -// -// Created by Evan Maloney on 12/16/15. -// Copyright © 2015 Gilt Groupe. All rights reserved. -// - -/** - `ColorTable`s are used to supply foreground and background `Color` values - for a given `LogSeverity`. - */ -public protocol ColorTable -{ - /** - Returns the foreground color to use (if any) for colorizing messages - at the given `LogSeverity`. - - - parameter severity: The `LogSeverity` whose color information is - being retrieved. - - - returns: The foreground `Color` to use for `severity`, or `nil` if no - color is specified. - */ - func foreground(forSeverity severity: LogSeverity) -> Color? - - /** - Returns the background color to use (if any) for colorizing messages - at the given `LogSeverity`. - - - parameter severity: The `LogSeverity` whose color information is - being retrieved. - - - returns: The background `Color` to use for `severity`, or `nil` if no - color is specified. - */ - func background(forSeverity severity: LogSeverity) -> Color? -} - -extension ColorTable -{ - /** - A default function implementation to always return `nil` indicating - that no background color information is specified. By default, - `ColorTable` implementations only supply foreground color information. - - - parameter severity: The `LogSeverity` whose color information is - being retrieved. - - - returns: Always `nil`. - */ - public func background(forSeverity severity: LogSeverity) - -> Color? - { - return nil - } -} diff --git a/Sources/ColorizingLogFormatter.swift b/Sources/ColorizingLogFormatter.swift deleted file mode 100644 index 3ed45587..00000000 --- a/Sources/ColorizingLogFormatter.swift +++ /dev/null @@ -1,68 +0,0 @@ -// -// ColorizingLogFormatter.swift -// CleanroomLogger -// -// Created by Evan Maloney on 1/4/16. -// Copyright © 2016 Gilt Groupe. All rights reserved. -// - -/** - Wraps another `LogFormatter` and colorizes its output according to the - `LogSeverity` of the `LogEntry` being recorded. - */ -public struct ColorizingLogFormatter: LogFormatter -{ - /** The `LogFormatter` wrapped by the receiver. */ - public let formatter: LogFormatter - - /** The `TextColorizer` used to apply color formatting to the output of the - receiver's `formatter`. */ - public let colorizer: TextColorizer - - /** The `ColorTable` used to supply foreground and background text color - information. */ - public let colorTable: ColorTable - - /** - Initializes a new `ColorizingLogFormatter` instance. - - - parameter formatter: The `LogFormatter` whose output will be colorized - by the receiver. - - - parameter colorizer: The `TextColorizer` that will be used to colorize - the output of `formatter`. - - - parameter colorTable: The `ColorTable` to use for supplying color - information to the `TextColorizer`. - */ - public init(formatter: LogFormatter, colorizer: TextColorizer, colorTable: ColorTable? = nil) - { - self.formatter = formatter - self.colorizer = colorizer - self.colorTable = colorTable ?? DefaultColorTable() - } - - /** - Formats the `LogEntry` by first passing it to the `LogFormatter` used - to construct the receiver. Then, if a non-`nil` value is returned, the - resulting string have color formatting codes applied to it using the - `colorizer` and `colorTable` specified at instantiation. - - - parameter entry: The `LogEntry` to be formatted. - - - returns: The formatted result, or `nil` if the receiver's - `formatter` returns `nil` when attempting to format `entry`. - */ - public func format(_ entry: LogEntry) - -> String? - { - guard let str = formatter.format(entry) else { - return nil - } - - let fg = colorTable.foreground(forSeverity: entry.severity) - let bg = colorTable.background(forSeverity: entry.severity) - - return colorizer.colorize(str, foreground: fg, background: bg) - } -} diff --git a/Sources/DefaultColorTable.swift b/Sources/DefaultColorTable.swift deleted file mode 100644 index bba4434d..00000000 --- a/Sources/DefaultColorTable.swift +++ /dev/null @@ -1,58 +0,0 @@ -// -// DefaultColorTable.swift -// CleanroomLogger -// -// Created by Evan Maloney on 12/16/15. -// Copyright © 2015 Gilt Groupe. All rights reserved. -// - -/** - A default implementation of the `ColorTable` protocol. - */ -public struct DefaultColorTable: ColorTable -{ - /** A light gray `Color` (`#999999`) used as the foreground color - for the `.verbose` severity. */ - public static let verboseColor = Color(r: 0x99, g: 0x99, b: 0x99) - - /** A dark gray `Color` (`#666666`) used as the foreground color - for the `.debug` severity. */ - public static let debugColor = Color(r: 0x66, g: 0x66, b: 0x66) - - /** A blue `Color` (`#0000CC`) used as the foreground color - for the `.info` severity. */ - public static let infoColor = Color(r: 0x00, g: 0x00, b: 0xCC) - - /** An orange `Color` (`#DD7722`) used as the foreground color - for the `.warning` severity. */ - public static let warningColor = Color(r: 0xDD, g: 0x77, b: 0x22) - - /** A red `Color` (`#CC0000`) used as the foreground color - for the `.error` severity. */ - public static let errorColor = Color(r: 0xCC, g: 0x00, b: 0x00) - - /** The constructor. */ - public init() {} - - /** - Returns the foreground color to use (if any) for colorizing messages - at the given `LogSeverity`. - - - parameter severity: The `LogSeverity` whose color information is - being retrieved. - - - returns: The foreground `Color` to use for `severity`, or `nil` if no - color is specified. - */ - public func foreground(forSeverity severity: LogSeverity) - -> Color? - { - switch severity { - case .verbose: return type(of: self).verboseColor - case .debug: return type(of: self).debugColor - case .info: return type(of: self).infoColor - case .warning: return type(of: self).warningColor - case .error: return type(of: self).errorColor - } - } -} diff --git a/Sources/Log.swift b/Sources/Log.swift index aeee2c6f..235ebef9 100644 --- a/Sources/Log.swift +++ b/Sources/Log.swift @@ -144,17 +144,12 @@ public struct Log an opaque identifier for the calling thread will be added to formatted log messages. - - parameter suppressColors: If `true`, log message colorization will be - disabled. By default, if the third-party XcodeColors plug-in for Xcode - is installed, and if CleanroomLogger detects that it is enabled, log - messages are colorized automatically. - - parameter filters: The `LogFilter`s to use when deciding whether a given `LogEntry` should be passed along for recording. */ - public static func enable(minimumSeverity: LogSeverity = .info, debugMode: Bool = false, verboseDebugMode: Bool = false, timestampStyle: TimestampStyle? = .default, severityStyle: SeverityStyle? = .xcode, showCallSite: Bool = true, showCallingThread: Bool = false, suppressColors: Bool = false, filters: [LogFilter] = []) + public static func enable(minimumSeverity: LogSeverity = .info, debugMode: Bool = false, verboseDebugMode: Bool = false, timestampStyle: TimestampStyle? = .default, severityStyle: SeverityStyle? = .xcode, showCallSite: Bool = true, showCallingThread: Bool = false, filters: [LogFilter] = []) { - let config = XcodeLogConfiguration(minimumSeverity: minimumSeverity, debugMode: debugMode, verboseDebugMode: verboseDebugMode, timestampStyle: timestampStyle, severityStyle: severityStyle, showCallSite: showCallSite, showCallingThread: showCallingThread, suppressColors: suppressColors, filters: filters) + let config = XcodeLogConfiguration(minimumSeverity: minimumSeverity, debugMode: debugMode, verboseDebugMode: verboseDebugMode, timestampStyle: timestampStyle, severityStyle: severityStyle, showCallSite: showCallSite, filters: filters) enable(configuration: config) } diff --git a/Sources/ParsableLogFormatter.swift b/Sources/ParsableLogFormatter.swift index 77a176da..f809c303 100644 --- a/Sources/ParsableLogFormatter.swift +++ b/Sources/ParsableLogFormatter.swift @@ -11,11 +11,10 @@ By default, this formatter: - - Uses `.UNIX` as the default `TimestampStyle` - - Uses `.Numeric` as the default `SeverityStyle` - - Uses `.Tab` as the default `DelimiterStyle` + - Uses `.unix` as the default `TimestampStyle` + - Uses `.numeric` as the default `SeverityStyle` + - Uses `.tab` as the default `DelimiterStyle` - Outputs the call site and calling thread - - Does not perform text colorization These defaults can be overridden during instantiation. */ @@ -39,16 +38,9 @@ open class ParsableLogFormatter: StandardLogFormatter - parameter showCallingThread: If `true`, a hexadecimal string containing an opaque identifier for the calling thread will be added to formatted log messages. - - - parameter colorizer: The `TextColorizer` that will be used to colorize - the output of the receiver. If `nil`, no colorization will occur. - - - parameter colorTable: If a `colorizer` is provided, an optional - `ColorTable` may also be provided to supply color information. If `nil`, - `DefaultColorTable` will be used for colorization. */ - public override init(timestampStyle: TimestampStyle? = .unix, severityStyle: SeverityStyle? = .numeric, delimiterStyle: DelimiterStyle? = .tab, showCallSite: Bool = true, showCallingThread: Bool = true, colorizer: TextColorizer? = nil, colorTable: ColorTable? = nil) + public override init(timestampStyle: TimestampStyle? = .unix, severityStyle: SeverityStyle? = .numeric, delimiterStyle: DelimiterStyle? = .tab, showCallSite: Bool = true, showCallingThread: Bool = true) { - super.init(timestampStyle: timestampStyle, severityStyle: severityStyle, delimiterStyle: delimiterStyle, showCallSite: showCallSite, showCallingThread: showCallingThread, colorizer: colorizer, colorTable: colorTable) + super.init(timestampStyle: timestampStyle, severityStyle: severityStyle, delimiterStyle: delimiterStyle, showCallSite: showCallSite, showCallingThread: showCallingThread) } } diff --git a/Sources/ReadableLogFormatter.swift b/Sources/ReadableLogFormatter.swift index e940a4bb..a00d0a7e 100644 --- a/Sources/ReadableLogFormatter.swift +++ b/Sources/ReadableLogFormatter.swift @@ -11,11 +11,10 @@ By default, this formatter: - - Uses `.Default` as the default `TimestampStyle` - - Uses `.Simple` as the default `SeverityStyle` + - Uses `.default` as the default `TimestampStyle` + - Uses `.simple` as the default `SeverityStyle` - Uses default field separator delimiters - Outputs the call site and calling thread - - Does not perform text colorization These defaults can be overridden during instantiation. */ @@ -39,16 +38,9 @@ open class ReadableLogFormatter: StandardLogFormatter - parameter showCallingThread: If `true`, a hexadecimal string containing an opaque identifier for the calling thread will be added to formatted log messages. - - - parameter colorizer: The `TextColorizer` that will be used to colorize - the output of the receiver. If `nil`, no colorization will occur. - - - parameter colorTable: If a `colorizer` is provided, an optional - `ColorTable` may also be provided to supply color information. If `nil`, - `DefaultColorTable` will be used for colorization. */ - public override init(timestampStyle: TimestampStyle? = .default, severityStyle: SeverityStyle? = .simple, delimiterStyle: DelimiterStyle? = nil, showCallSite: Bool = true, showCallingThread: Bool = true, colorizer: TextColorizer? = nil, colorTable: ColorTable? = nil) + public override init(timestampStyle: TimestampStyle? = .default, severityStyle: SeverityStyle? = .simple, delimiterStyle: DelimiterStyle? = nil, showCallSite: Bool = true, showCallingThread: Bool = true) { - super.init(timestampStyle: timestampStyle, severityStyle: severityStyle, delimiterStyle: delimiterStyle, showCallSite: showCallSite, showCallingThread: showCallingThread, colorizer: colorizer, colorTable: colorTable) + super.init(timestampStyle: timestampStyle, severityStyle: severityStyle, delimiterStyle: delimiterStyle, showCallSite: showCallSite, showCallingThread: showCallingThread) } } diff --git a/Sources/StandardLogFormatter.swift b/Sources/StandardLogFormatter.swift index be01041d..b5b92d36 100644 --- a/Sources/StandardLogFormatter.swift +++ b/Sources/StandardLogFormatter.swift @@ -29,15 +29,8 @@ open class StandardLogFormatter: FieldBasedLogFormatter - parameter showCallingThread: If `true`, a hexadecimal string containing an opaque identifier for the calling thread will be added to formatted log messages. - - - parameter colorizer: The `TextColorizer` that will be used to colorize - the output of the receiver. If `nil`, no colorization will occur. - - - parameter colorTable: If a `colorizer` is provided, an optional - `ColorTable` may also be provided to supply color information. If `nil`, - `DefaultColorTable` will be used for colorization. */ - public init(timestampStyle: TimestampStyle? = .default, severityStyle: SeverityStyle? = .simple, delimiterStyle: DelimiterStyle? = nil, showCallSite: Bool = true, showCallingThread: Bool = false, colorizer: TextColorizer? = nil, colorTable: ColorTable? = nil) + public init(timestampStyle: TimestampStyle? = .default, severityStyle: SeverityStyle? = .simple, delimiterStyle: DelimiterStyle? = nil, showCallSite: Bool = true, showCallingThread: Bool = false) { var fields: [Field] = [] var addSeparator = false @@ -76,11 +69,6 @@ open class StandardLogFormatter: FieldBasedLogFormatter } fields += [.payload] - if colorizer == nil { - super.init(fields: fields) - } - else { - super.init(formatters: [ColorizingLogFormatter(formatter: FieldBasedLogFormatter(fields: fields), colorizer: colorizer!, colorTable: colorTable ?? DefaultColorTable())]) - } + super.init(fields: fields) } } diff --git a/Sources/TextColorizer.swift b/Sources/TextColorizer.swift deleted file mode 100644 index b92dba29..00000000 --- a/Sources/TextColorizer.swift +++ /dev/null @@ -1,28 +0,0 @@ -// -// TextColorizer.swift -// CleanroomLogger -// -// Created by Evan Maloney on 12/18/15. -// Copyright © 2015 Gilt Groupe. All rights reserved. -// - -/** - `TextColorizer`s are used to apply color formatting to log messages. - */ -public protocol TextColorizer -{ - /** - Applies the specified foreground and background `Color`s to the passed-in - string. - - - parameter string: The string to be colorized. - - - parameter foreground: An optional foreground color to apply to `string`. - - - parameter background: An optional background color to apply to `string`. - - - returns: A version of `string` with the appropriate color formatting - applied. - */ - func colorize(_ str: String, foreground: Color?, background: Color?) -> String -} diff --git a/Sources/XcodeColorsTextColorizer.swift b/Sources/XcodeColorsTextColorizer.swift deleted file mode 100644 index ae91fd54..00000000 --- a/Sources/XcodeColorsTextColorizer.swift +++ /dev/null @@ -1,90 +0,0 @@ -// -// XcodeColorsTextColorizer.swift -// CleanroomLogger -// -// Created by Evan Maloney on 12/18/15. -// Copyright © 2015 Gilt Groupe. All rights reserved. -// - -import Darwin.C.stdlib - -/** - A `TextColorizer` implementation that applies - [XcodeColors](https://github.com/robbiehanson/XcodeColors/)-compatible - formatting to log messages. - */ -public struct XcodeColorsTextColorizer: TextColorizer -{ - /** - Initializes a new instance if and only if XcodeColors is installed and - enabled, as indicated by the presence of the `XcodeColors` environment - variable. (Unless the value of this variable is the string `YES`, this - initializer will fail.) - */ - public init?() - { - guard let env = getenv("XcodeColors") else { - return nil - } - - guard let str = String(validatingUTF8: env) else { - return nil - } - - guard str == "YES" else { - return nil - } - } - - /** - Applies XcodeColors-style formatting appropriate for the given - `LogSeverity` to the passed-in string. - - - parameter string: The string to be colorized. - - - parameter foreground: An optional foreground color to apply to `string`. - - - parameter background: An optional background color to apply to `string`. - - - returns: A version of `string` with the appropriate color formatting - applied. - */ - public func colorize(_ str: String, foreground: Color?, background: Color?) - -> String - { - let esc = "\u{001b}[" - - var prefix = "" - var suffix = "" - if let fgColor = foreground { - prefix += "\(esc)\(fgColor.xcodeColorsForegroundString);" - suffix = "\(esc);" - } - if let bgColor = background { - prefix += "\(esc)\(bgColor.xcodeColorsBackgroundString);" - suffix = "\(esc);" - } - - return "\(prefix)\(str)\(suffix)" - } -} - -fileprivate extension Color -{ - /// A comma-separated string representation of the red, green and blue - /// components of the color in base-10 integers. - var xcodeColorsString: String { - return "\(r),\(g),\(b)" - } - - /// An XcodeColors-style string representation usable as a foreground color. - var xcodeColorsForegroundString: String { - return "fg\(xcodeColorsString)" - } - - /// An XcodeColors-style string representation usable as a background color. - var xcodeColorsBackgroundString: String { - return "bg\(xcodeColorsString)" - } -} - diff --git a/Sources/XcodeLogConfiguration.swift b/Sources/XcodeLogConfiguration.swift index 4bc75dc5..fa315ba3 100644 --- a/Sources/XcodeLogConfiguration.swift +++ b/Sources/XcodeLogConfiguration.swift @@ -9,19 +9,8 @@ /** A `LogConfiguration` optimized for use when running within Xcode. - By default, this configuration will attempt to detect the presence of - the XcodeColors plug-in, and—if it is present—will enable text colorization. - - If text colorization is used, the `XcodeLogConfiguration` will enable two - separate `LogRecorder`s: a `StandardOutputLogRecorder`, which will be - configured to perform colorization of the logs within the Xcode console, - and an `ASLLogRecorder` which will not use colorization. This ensures that - the colorization escape sequences used within Xcode do not end up in the - Apple System Log (ASL), where they will look like garbage characters. - - If no colorization is used, then the `XcodeLogConfiguration` will configure - only a single recorder: an `ASLLogRecorder` configured to echo output to - `stdout` as well as capturing to the ASL. + The `XcodeLogConfiguration` sets up a single recorder: an `ASLLogRecorder` + configured to echo output to `stdout` as well as capturing to the ASL. */ open class XcodeLogConfiguration: BasicLogConfiguration { @@ -48,8 +37,7 @@ open class XcodeLogConfiguration: BasicLogConfiguration used when recording log entries. - parameter logToASL: If `true`, messages sent to the Xcode console will - also be sent to the Apple System Log (ASL) facility, minus any - colorization codes, which look like corrupted characters in the ASL. + also be sent to the Apple System Log (ASL) facility. - parameter timestampStyle: Governs the formatting of the timestamp in the log output. Pass `nil` to suppress output of the timestamp. @@ -64,24 +52,14 @@ open class XcodeLogConfiguration: BasicLogConfiguration an opaque identifier for the calling thread will be added to formatted log messages. - - parameter suppressColors: If `true`, log message colorization will be - disabled. By default, if the third-party XcodeColors plug-in for Xcode - is installed, and if CleanroomLogger detects that it is enabled, log - messages are colorized automatically. - - parameter filters: The `LogFilter`s to use when deciding whether a given `LogEntry` should be passed along for recording. */ - public convenience init(minimumSeverity: LogSeverity = .info, debugMode: Bool = false, verboseDebugMode: Bool = false, logToASL: Bool = true, timestampStyle: TimestampStyle? = .default, severityStyle: SeverityStyle? = .xcode, showCallSite: Bool = true, showCallingThread: Bool = false, showSeverity: Bool = true, suppressColors: Bool = false, filters: [LogFilter] = []) + public convenience init(minimumSeverity: LogSeverity = .info, debugMode: Bool = false, verboseDebugMode: Bool = false, logToASL: Bool = true, timestampStyle: TimestampStyle? = .default, severityStyle: SeverityStyle? = .xcode, showCallSite: Bool = true, showCallingThread: Bool = false, showSeverity: Bool = true, filters: [LogFilter] = []) { - var colorizer: TextColorizer? - if !suppressColors { - colorizer = XcodeColorsTextColorizer() - } - - let formatter = XcodeLogFormatter(timestampStyle: timestampStyle, severityStyle: severityStyle, delimiterStyle: nil, showCallSite: showCallSite, showCallingThread: showCallingThread, colorizer: nil) + let formatter = XcodeLogFormatter(timestampStyle: timestampStyle, severityStyle: severityStyle, delimiterStyle: nil, showCallSite: showCallSite, showCallingThread: showCallingThread) - self.init(minimumSeverity: minimumSeverity, debugMode: debugMode, verboseDebugMode: verboseDebugMode, logToASL: logToASL, colorizer: colorizer, filters: filters, formatter: formatter) + self.init(minimumSeverity: minimumSeverity, debugMode: debugMode, verboseDebugMode: verboseDebugMode, logToASL: logToASL, filters: filters, formatter: formatter) } /** @@ -107,15 +85,7 @@ open class XcodeLogConfiguration: BasicLogConfiguration used when recording log entries. - parameter logToASL: If `true`, messages sent to the Xcode console will - also be sent to the Apple System Log (ASL) facility, minus any - colorization codes, which look like corrupted characters in the ASL. - - - parameter colorizer: The `TextColorizer` that will be used to colorize - the output of the receiver. If `nil`, no colorization will occur. - - - parameter colorTable: If a `colorizer` is provided, an optional - `ColorTable` may also be provided to supply color information. If `nil`, - `DefaultColorTable` will be used for colorization. + also be sent to the Apple System Log (ASL) facility. - parameter filters: The `LogFilter`s to use when deciding whether a given `LogEntry` should be passed along for recording. @@ -123,9 +93,9 @@ open class XcodeLogConfiguration: BasicLogConfiguration - parameter formatter: A `LogFormatter` to use for formatting log entries to be recorded. */ - public convenience init(minimumSeverity: LogSeverity = .info, debugMode: Bool = false, verboseDebugMode: Bool = false, logToASL: Bool = true, colorizer: TextColorizer? = XcodeColorsTextColorizer(), colorTable: ColorTable? = nil, filters: [LogFilter] = [], formatter: LogFormatter) + public convenience init(minimumSeverity: LogSeverity = .info, debugMode: Bool = false, verboseDebugMode: Bool = false, logToASL: Bool = true, filters: [LogFilter] = [], formatter: LogFormatter) { - self.init(minimumSeverity: minimumSeverity, debugMode: debugMode, verboseDebugMode: verboseDebugMode, logToASL: logToASL, colorizer: colorizer, colorTable: colorTable, filters: filters, formatters: [formatter]) + self.init(minimumSeverity: minimumSeverity, debugMode: debugMode, verboseDebugMode: verboseDebugMode, logToASL: logToASL, filters: filters, formatters: [formatter]) } /** @@ -151,15 +121,7 @@ open class XcodeLogConfiguration: BasicLogConfiguration used when recording log entries. - parameter logToASL: If `true`, messages sent to the Xcode console will - also be sent to the Apple System Log (ASL) facility, minus any - colorization codes, which look like corrupted characters in the ASL. - - - parameter colorizer: The `TextColorizer` that will be used to colorize - the output of the receiver. If `nil`, no colorization will occur. - - - parameter colorTable: If a `colorizer` is provided, an optional - `ColorTable` may also be provided to supply color information. If `nil`, - `DefaultColorTable` will be used for colorization. + also be sent to the Apple System Log (ASL) facility. - parameter filters: The `LogFilter`s to use when deciding whether a given `LogEntry` should be passed along for recording. @@ -167,7 +129,7 @@ open class XcodeLogConfiguration: BasicLogConfiguration - parameter formatters: An array of `LogFormatter`s to use for formatting log entries to be recorded. */ - public init(minimumSeverity: LogSeverity = .info, debugMode: Bool = false, verboseDebugMode: Bool = false, logToASL: Bool = true, colorizer: TextColorizer? = XcodeColorsTextColorizer(), colorTable: ColorTable? = nil, filters: [LogFilter] = [], formatters: [LogFormatter]) + public init(minimumSeverity: LogSeverity = .info, debugMode: Bool = false, verboseDebugMode: Bool = false, logToASL: Bool = true, filters: [LogFilter] = [], formatters: [LogFormatter]) { var minimumSeverity = minimumSeverity if verboseDebugMode { @@ -178,29 +140,12 @@ open class XcodeLogConfiguration: BasicLogConfiguration } let recorders: [LogRecorder] - if let colorizer = colorizer { - let colorFormatters: [LogFormatter] = formatters.map{ ColorizingLogFormatter(formatter: $0, colorizer: colorizer, colorTable: colorTable) } - - if logToASL { - recorders = [ - ASLLogRecorder(formatters: formatters, echoToStdErr: false, addTraceAttributes: debugMode || verboseDebugMode), - StandardOutputLogRecorder(formatters: colorFormatters) - ] - } - else { - recorders = [StandardOutputLogRecorder(formatters: colorFormatters)] - } - } - else if logToASL { - // automatically echoes to stdout + if logToASL { recorders = [ASLLogRecorder(formatters: formatters, echoToStdErr: true, addTraceAttributes: debugMode || verboseDebugMode)] - } - else { + } else { recorders = [StandardOutputLogRecorder(formatters: formatters)] } - let synchronous = debugMode || verboseDebugMode - - super.init(minimumSeverity: minimumSeverity, filters: filters, recorders: recorders, synchronousMode: synchronous) + super.init(minimumSeverity: minimumSeverity, filters: filters, recorders: recorders, synchronousMode: (debugMode || verboseDebugMode)) } } diff --git a/Sources/XcodeLogFormatter.swift b/Sources/XcodeLogFormatter.swift index 13c4ded3..5da31c6e 100644 --- a/Sources/XcodeLogFormatter.swift +++ b/Sources/XcodeLogFormatter.swift @@ -11,14 +11,14 @@ By default, this formatter: - - Uses `.Default` as the default `TimestampStyle` - - Uses `.Xcode` as the default `SeverityStyle` + - Uses `.default` as the default `TimestampStyle` + - Uses `.xcode` as the default `SeverityStyle` - Uses default field separator delimiters - Outputs the call site - Does not output the calling thread - - Performs text colorization if XcodeColors is installed and enabled - These defaults can be overridden during instantiation. + These defaults can be overridden by providing alternate values to the + initializer. */ open class XcodeLogFormatter: StandardLogFormatter { @@ -40,16 +40,9 @@ open class XcodeLogFormatter: StandardLogFormatter - parameter showCallingThread: If `true`, a hexadecimal string containing an opaque identifier for the calling thread will be added to formatted log messages. - - - parameter colorizer: The `TextColorizer` that will be used to colorize - the output of the receiver. If `nil`, no colorization will occur. - - - parameter colorTable: If a `colorizer` is provided, an optional - `ColorTable` may also be provided to supply color information. If `nil`, - `DefaultColorTable` will be used for colorization. */ - public override init(timestampStyle: TimestampStyle? = .default, severityStyle: SeverityStyle? = .xcode, delimiterStyle: DelimiterStyle? = nil, showCallSite: Bool = true, showCallingThread: Bool = false, colorizer: TextColorizer? = XcodeColorsTextColorizer(), colorTable: ColorTable? = nil) + public override init(timestampStyle: TimestampStyle? = .default, severityStyle: SeverityStyle? = .xcode, delimiterStyle: DelimiterStyle? = nil, showCallSite: Bool = true, showCallingThread: Bool = false) { - super.init(timestampStyle: timestampStyle, severityStyle: severityStyle, delimiterStyle: delimiterStyle, showCallSite: showCallSite, showCallingThread: showCallingThread, colorizer: colorizer, colorTable: colorTable) + super.init(timestampStyle: timestampStyle, severityStyle: severityStyle, delimiterStyle: delimiterStyle, showCallSite: showCallSite, showCallingThread: showCallingThread) } }