From 79a2d01955596cacfe37f0ff1d2446f2c21bbcc7 Mon Sep 17 00:00:00 2001 From: Frizlab Date: Tue, 7 Jan 2025 14:51:47 +0100 Subject: [PATCH 1/7] Fix compilation on Windows --- Sources/CLTLogger.swift | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/Sources/CLTLogger.swift b/Sources/CLTLogger.swift index 6cc0aa1..9170c12 100644 --- a/Sources/CLTLogger.swift +++ b/Sources/CLTLogger.swift @@ -1,4 +1,7 @@ import Foundation +#if canImport(WinSDK) +import WinSDK +#endif import Logging @@ -200,6 +203,11 @@ public struct CLTLogger : LogHandler { /* * * The logging style is not defined specifically in the dedicated environment value: we try and detect a correct value depending on other environmental clues. * * */ + if let s = getenv("GITHUB_ACTIONS"), String(cString: s) == "true" { + /* GitHub does support colors. */ + return .color + } +#if !os(Windows) /* Is the fd on which we write a tty? * Most ttys nowadays support colors, with a notable exception: Xcode. */ if isatty(fh.fileDescriptor) != 0 { @@ -217,10 +225,10 @@ public struct CLTLogger : LogHandler { * In theory we should use the curses database to check for colors (ncurses has the `has_colors` function for this). */ return (getenv("TERM") == nil ? .text : .color) } - if let s = getenv("GITHUB_ACTIONS"), String(cString: s) == "true" { - /* GitHub does support colors. */ - return .color +#else + if GetFileType(fh._handle) == FILE_TYPE_CHAR { } +#endif /* Unknown case: we return the text logging style. */ return .text } @@ -265,7 +273,12 @@ public extension CLTLogger { static func defaultConstantsByLogLevelForEmoji(on fh: FileHandle) -> [Logger.Level: Constants] { func addMeta(_ str: String, _ padding: String) -> Constants { var str = str - if isatty(fh.fileDescriptor) != 0, tcgetpgrp(fh.fileDescriptor) == -1, errno == ENOTTY { +#if !os(Windows) + let isXcode = (isatty(fh.fileDescriptor) != 0 && tcgetpgrp(fh.fileDescriptor) == -1 && errno == ENOTTY) +#else + let isXcode = false +#endif + if isXcode { /* We’re in Xcode (probably). * By default we do not do the emoji padding, unless explicitly asked to (`CLTLOGGER_TERMINAL_EMOJI` set to anything but “NO”). */ if let s = getenv("CLTLOGGER_TERMINAL_EMOJI"), String(cString: s) != "NO" { From dd9955a20aa23c0fc7b590eef84d8626339175d4 Mon Sep 17 00:00:00 2001 From: Frizlab Date: Tue, 7 Jan 2025 15:00:12 +0100 Subject: [PATCH 2/7] Use ProcessInfo.processInfo.environment instead of getenv --- Sources/CLTLogger.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/CLTLogger.swift b/Sources/CLTLogger.swift index 9170c12..b0dd523 100644 --- a/Sources/CLTLogger.swift +++ b/Sources/CLTLogger.swift @@ -191,8 +191,8 @@ public struct CLTLogger : LogHandler { } private static func autoLogStyle(with fh: FileHandle) -> Style { - if let s = getenv("CLTLOGGER_LOG_STYLE") { - switch String(cString: s) { + if let s = ProcessInfo.processInfo.environment["CLTLOGGER_LOG_STYLE"] { + switch s { case "none": return .none case "color": return .color case "emoji": return .emoji @@ -203,7 +203,7 @@ public struct CLTLogger : LogHandler { /* * * The logging style is not defined specifically in the dedicated environment value: we try and detect a correct value depending on other environmental clues. * * */ - if let s = getenv("GITHUB_ACTIONS"), String(cString: s) == "true" { + if ProcessInfo.processInfo.environment["GITHUB_ACTIONS"] == "true" { /* GitHub does support colors. */ return .color } @@ -223,7 +223,7 @@ public struct CLTLogger : LogHandler { } /* If the TERM env var is not set we assume colors are not supported and return the text logging style. * In theory we should use the curses database to check for colors (ncurses has the `has_colors` function for this). */ - return (getenv("TERM") == nil ? .text : .color) + return (ProcessInfo.processInfo.environment["TERM"] == nil ? .text : .color) } #else if GetFileType(fh._handle) == FILE_TYPE_CHAR { @@ -281,13 +281,13 @@ public extension CLTLogger { if isXcode { /* We’re in Xcode (probably). * By default we do not do the emoji padding, unless explicitly asked to (`CLTLOGGER_TERMINAL_EMOJI` set to anything but “NO”). */ - if let s = getenv("CLTLOGGER_TERMINAL_EMOJI"), String(cString: s) != "NO" { + if let s = ProcessInfo.processInfo.environment["CLTLOGGER_TERMINAL_EMOJI"], s != "NO" { str = str + padding } } else { /* We’re not in Xcode (probably). * By default we do the emoji padding, unless explicitly asked not to (`CLTLOGGER_TERMINAL_EMOJI` set to “NO”). */ - if let s = getenv("CLTLOGGER_TERMINAL_EMOJI"), String(cString: s) == "NO" { + if ProcessInfo.processInfo.environment["CLTLOGGER_TERMINAL_EMOJI"] == "NO" { /*nop*/ } else { str = str + padding From b5c3812842e15f7b2e0f8849a02d6a6f6120841d Mon Sep 17 00:00:00 2001 From: Frizlab Date: Tue, 7 Jan 2025 15:06:02 +0100 Subject: [PATCH 3/7] Take windows into account for the emoji padding detection --- Sources/CLTLogger.swift | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Sources/CLTLogger.swift b/Sources/CLTLogger.swift index b0dd523..ce12ba2 100644 --- a/Sources/CLTLogger.swift +++ b/Sources/CLTLogger.swift @@ -275,18 +275,17 @@ public extension CLTLogger { var str = str #if !os(Windows) let isXcode = (isatty(fh.fileDescriptor) != 0 && tcgetpgrp(fh.fileDescriptor) == -1 && errno == ENOTTY) + let needsPaddingByDefault = !isXcode #else - let isXcode = false + let needsPaddingByDefault = true #endif - if isXcode { - /* We’re in Xcode (probably). - * By default we do not do the emoji padding, unless explicitly asked to (`CLTLOGGER_TERMINAL_EMOJI` set to anything but “NO”). */ + if !needsPaddingByDefault { + /* By default we do not do the emoji padding, unless explicitly asked to (`CLTLOGGER_TERMINAL_EMOJI` set to anything but “NO”). */ if let s = ProcessInfo.processInfo.environment["CLTLOGGER_TERMINAL_EMOJI"], s != "NO" { str = str + padding } } else { - /* We’re not in Xcode (probably). - * By default we do the emoji padding, unless explicitly asked not to (`CLTLOGGER_TERMINAL_EMOJI` set to “NO”). */ + /* By default we do the emoji padding, unless explicitly asked not to (`CLTLOGGER_TERMINAL_EMOJI` set to “NO”). */ if ProcessInfo.processInfo.environment["CLTLOGGER_TERMINAL_EMOJI"] == "NO" { /*nop*/ } else { From b09f70b131dbd16dc1b090cd8f2ee85dd04cdfd9 Mon Sep 17 00:00:00 2001 From: Frizlab Date: Tue, 7 Jan 2025 15:17:59 +0100 Subject: [PATCH 4/7] Change critical emoji for Windows --- Sources/CLTLogger.swift | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Sources/CLTLogger.swift b/Sources/CLTLogger.swift index ce12ba2..576734a 100644 --- a/Sources/CLTLogger.swift +++ b/Sources/CLTLogger.swift @@ -301,7 +301,10 @@ public extension CLTLogger { lineSeparator: "\n" ) } - /* The padding corrects alignment issues on the Terminal. */ + /* The padding corrects alignment issues in the Terminal and VSCode. + * In Windows PowerShell, the alignment is off for the debug, warning and error levels. + * For the first two we could try and detect PowerShell somehow and remove the alignment, + * but for the error one we are already **not** compensating the alignment, so there’s not much we can do. */ return [ .trace: addMeta("💩", ""), .debug: addMeta("⚙️", " "), @@ -309,8 +312,17 @@ public extension CLTLogger { .notice: addMeta("🗣", " "), .warning: addMeta("⚠️", " "), .error: addMeta("❗️", ""), + ].merging({ +#if !os(Windows) + [ .critical: addMeta("‼️", " ") ] +#else + [ + .critical: addMeta("🚨", ""), + ] +#endif + }(), uniquingKeysWith: { _, new in preconditionFailure() }) } /* Terminal does not support RGB colors, so we use 255-color palette. */ From a064c6dc6471376ff575034023c7810ffb6fe979 Mon Sep 17 00:00:00 2001 From: Frizlab Date: Tue, 7 Jan 2025 15:26:53 +0100 Subject: [PATCH 5/7] Change the error emoji for Windows --- Sources/CLTLogger.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/CLTLogger.swift b/Sources/CLTLogger.swift index 576734a..74cd5b3 100644 --- a/Sources/CLTLogger.swift +++ b/Sources/CLTLogger.swift @@ -302,23 +302,23 @@ public extension CLTLogger { ) } /* The padding corrects alignment issues in the Terminal and VSCode. - * In Windows PowerShell, the alignment is off for the debug, warning and error levels. - * For the first two we could try and detect PowerShell somehow and remove the alignment, - * but for the error one we are already **not** compensating the alignment, so there’s not much we can do. */ + * In Windows PowerShell, the alignment is off for the debug and warning levels. + * We could try and detect PowerShell somehow and fix the alignment for those. */ return [ .trace: addMeta("💩", ""), .debug: addMeta("⚙️", " "), .info: addMeta("📔", ""), .notice: addMeta("🗣", " "), .warning: addMeta("⚠️", " "), - .error: addMeta("❗️", ""), ].merging({ #if !os(Windows) [ + .error: addMeta("❗️", ""), .critical: addMeta("‼️", " ") ] #else [ + .error: addMeta("❌", ""), .critical: addMeta("🚨", ""), ] #endif From 9d99e368e2f6e27db5c08c610a160c056fe81e45 Mon Sep 17 00:00:00 2001 From: Frizlab Date: Tue, 7 Jan 2025 17:54:12 +0100 Subject: [PATCH 6/7] Fix emoji logging on Windows and VSCode --- Sources/CLTLogger.swift | 60 ++++++--------------- Sources/Emoji.swift | 73 +++++++++++++++++++++++++ Sources/EmojiSet.swift | 96 +++++++++++++++++++++++++++++++++ Sources/OutputEnvironment.swift | 88 ++++++++++++++++++++++++++++++ 4 files changed, 274 insertions(+), 43 deletions(-) create mode 100644 Sources/Emoji.swift create mode 100644 Sources/EmojiSet.swift create mode 100644 Sources/OutputEnvironment.swift diff --git a/Sources/CLTLogger.swift b/Sources/CLTLogger.swift index 74cd5b3..e0b7de7 100644 --- a/Sources/CLTLogger.swift +++ b/Sources/CLTLogger.swift @@ -271,58 +271,32 @@ public extension CLTLogger { }() static func defaultConstantsByLogLevelForEmoji(on fh: FileHandle) -> [Logger.Level: Constants] { - func addMeta(_ str: String, _ padding: String) -> Constants { - var str = str -#if !os(Windows) - let isXcode = (isatty(fh.fileDescriptor) != 0 && tcgetpgrp(fh.fileDescriptor) == -1 && errno == ENOTTY) - let needsPaddingByDefault = !isXcode -#else - let needsPaddingByDefault = true -#endif - if !needsPaddingByDefault { - /* By default we do not do the emoji padding, unless explicitly asked to (`CLTLOGGER_TERMINAL_EMOJI` set to anything but “NO”). */ - if let s = ProcessInfo.processInfo.environment["CLTLOGGER_TERMINAL_EMOJI"], s != "NO" { - str = str + padding - } - } else { - /* By default we do the emoji padding, unless explicitly asked not to (`CLTLOGGER_TERMINAL_EMOJI` set to “NO”). */ - if ProcessInfo.processInfo.environment["CLTLOGGER_TERMINAL_EMOJI"] == "NO" { - /*nop*/ - } else { - str = str + padding - } - } + func addMeta(_ paddedEmoji: String) -> Constants { return .init( - logPrefix: str + " → ", - multilineLogPrefix: str + " ", + logPrefix: paddedEmoji + " → ", + multilineLogPrefix: paddedEmoji + " ", metadataLinePrefix: " ▷ ", metadataSeparator: " - ", logAndMetadataSeparator: " -- ", lineSeparator: "\n" ) } - /* The padding corrects alignment issues in the Terminal and VSCode. - * In Windows PowerShell, the alignment is off for the debug and warning levels. - * We could try and detect PowerShell somehow and fix the alignment for those. */ + let envVars = ProcessInfo.processInfo.environment + let outputEnvironment: OutputEnvironment = .detect(from: fh, envVars) + let emojiSet = EmojiSet.default(for: outputEnvironment) + /* To see all the emojis with the padding. If padding is correct, everything should be aligned. */ + //for emoji in Emoji.allCases { + // print("\(emoji.rawValue)\(emoji.padding(for: outputEnvironment)) |") + //} return [ - .trace: addMeta("💩", ""), - .debug: addMeta("⚙️", " "), - .info: addMeta("📔", ""), - .notice: addMeta("🗣", " "), - .warning: addMeta("⚠️", " "), - ].merging({ -#if !os(Windows) - [ - .error: addMeta("❗️", ""), - .critical: addMeta("‼️", " ") + .trace: addMeta(emojiSet.paddedEmoji(for: .trace, in: outputEnvironment)), + .debug: addMeta(emojiSet.paddedEmoji(for: .debug, in: outputEnvironment)), + .info: addMeta(emojiSet.paddedEmoji(for: .info, in: outputEnvironment)), + .notice: addMeta(emojiSet.paddedEmoji(for: .notice, in: outputEnvironment)), + .warning: addMeta(emojiSet.paddedEmoji(for: .warning, in: outputEnvironment)), + .error: addMeta(emojiSet.paddedEmoji(for: .error, in: outputEnvironment)), + .critical: addMeta(emojiSet.paddedEmoji(for: .critical, in: outputEnvironment)), ] -#else - [ - .error: addMeta("❌", ""), - .critical: addMeta("🚨", ""), - ] -#endif - }(), uniquingKeysWith: { _, new in preconditionFailure() }) } /* Terminal does not support RGB colors, so we use 255-color palette. */ diff --git a/Sources/Emoji.swift b/Sources/Emoji.swift new file mode 100644 index 0000000..4c0f563 --- /dev/null +++ b/Sources/Emoji.swift @@ -0,0 +1,73 @@ +import Foundation + + + +internal enum Emoji : String, CaseIterable { + + case poo = "💩" + case cog = "⚙️" + case notebook = "📔" + case speaker = "🗣" + case warning = "⚠️" + case exclamationPoint = "❗️" + case doubleExclamationPoint = "‼️" + case eyebrow = "🤨" + case redCross = "❌" + case policeLight = "🚨" + case ladybug = "🐞" + case orangeDiamond = "🔶" + + case redHeart = "❤️" + case orangeHeart = "🧡" + case yellowHeart = "💛" + case greenHeart = "💚" + case blueHeart = "💙" + case purpleHeart = "💜" + case blackHeart = "🖤" + case greyHeart = "🩶" + case brownHeart = "🤎" + case whiteHeart = "🤍" + case pinkHeart = "🩷" + case lightBlueHeart = "🩵" + + func padding(for environment: OutputEnvironment) -> String { + guard environment != .xcode else { + /* All emojis are correct on Xcode. */ + return "" + } + + switch self { + case .poo, .notebook, .eyebrow, .redCross, .policeLight, .ladybug, .orangeDiamond, + .orangeHeart, .yellowHeart, .greenHeart, .blueHeart, .purpleHeart, + .blackHeart, .brownHeart, .whiteHeart: + return "" + + case .cog, .warning, .doubleExclamationPoint, .redHeart: + guard !environment.isVSCode, environment != .macOSTerminal + else {return " "} + return "" + + case .speaker: + guard !environment.isVSCode, !environment.isWindowsShell, environment != .macOSTerminal, environment != .macOSiTerm2 + else {return " "} + return "" + + case .exclamationPoint: + /* Note: For the Windows Terminal and Console, we’re a negative 1 space… + # We ignore this special case and return an empty string. */ + guard !environment.isWindowsShell + else {return ""/*negative one space*/} + return "" + + case .greyHeart, .pinkHeart, .lightBlueHeart: + guard !environment.isVSCode + else {return " "} + return "" + } + } + + func valueWithPadding(for environment: OutputEnvironment) -> String { + rawValue + padding(for: environment) + } + +} diff --git a/Sources/EmojiSet.swift b/Sources/EmojiSet.swift new file mode 100644 index 0000000..40233a3 --- /dev/null +++ b/Sources/EmojiSet.swift @@ -0,0 +1,96 @@ +import Foundation + +import Logging + + + +internal enum EmojiSet : String { + + /** + The original set of emoji used in clt-logger. + These work well in Terminal and Xcode (and on macOS generally, though not in VSCode). */ + case original = "ORIGINAL" + case originalForWindowsTerminal = "ORIGINAL+WINDOWS_TERMINAL" + case originalForVSCodeMacOS = "ORIGINAL+VSCODE_MACOS" + case originalForVSCodeWindows = "ORIGINAL+VSCODE_WINDOWS" + + case vaibhavsingh97EmojiLogger = "VAIBHAVSINGH97_EMOJI_LOGGER" + + static func `default`(for environment: OutputEnvironment, _ envVars: [String: String] = ProcessInfo.processInfo.environment) -> EmojiSet { + if let envStr = envVars["CLTLOGGER_EMOJI_SET_NAME"], let ret = EmojiSet(rawValue: envStr) { + return ret + } + switch environment { + case .xcode, .macOSTerminal, .macOSiTerm2, .macOSUnknown: + return .original + + case .macOSVSCode, .unknownVSCode, .unknown: + return .originalForVSCodeMacOS + + case .windowsTerminal, .windowsConsole, .windowsUnknown: + return .originalForWindowsTerminal + + case .windowsVSCode: + return .originalForVSCodeWindows + } + } + + /* Exceptions: + * - ⚙️ on VSCode macOS renders as text + * - ⚠️ on VSCode macOS renders as text + * - ‼️ on VSCode macOS renders as text + * - ❤️ on VSCode macOS renders as text + * - 🗣 on VSCode Windows renders as text (I think) + * - ‼️ on VSCode Windows renders as text + * - ❗️ on Windows Terminal is larger than the rest (negative padding would be needed) + * - ‼️ on Windows Terminal renders as text */ + func emoji(for logLevel: Logger.Level) -> Emoji { + let original: (Logger.Level) -> Emoji = { + switch $0 { + case .critical: return .doubleExclamationPoint + case .error: return .exclamationPoint + case .warning: return .warning + case .notice: return .speaker + case .info: return .notebook + case .debug: return .cog + case .trace: return .poo + } + } + + switch self { + case .original: + return original(logLevel) + + case .originalForWindowsTerminal: + switch logLevel { + case .critical: return .policeLight + case .error: return .redCross + default: return original(logLevel) + } + + case .originalForVSCodeMacOS: + switch logLevel { + case .critical: return .policeLight + case .warning: return .orangeDiamond + case .debug: return .ladybug + default: return original(logLevel) + } + + case .originalForVSCodeWindows: + switch logLevel { + case .critical: return .policeLight + case .notice: return .eyebrow + default: return original(logLevel) + } + + case .vaibhavsingh97EmojiLogger: + /* TODO */ + return original(logLevel) + } + } + + func paddedEmoji(for logLevel: Logger.Level, in environment: OutputEnvironment) -> String { + return emoji(for: logLevel).valueWithPadding(for: environment) + } + +} diff --git a/Sources/OutputEnvironment.swift b/Sources/OutputEnvironment.swift new file mode 100644 index 0000000..e2291f3 --- /dev/null +++ b/Sources/OutputEnvironment.swift @@ -0,0 +1,88 @@ +import Foundation + + + +internal enum OutputEnvironment : String { + + case xcode = "XCODE" + + case macOSTerminal = "MACOS_TERMINAL" + case macOSiTerm2 = "MACOS_ITERM2" + case macOSVSCode = "MACOS_VSCODE" + case macOSUnknown = "MACOS_UNKNOWN" + + /* This value is never auto-detected. + * We don’t know how to detect the Windows Terminal (TERM_PROGRAM is not set). */ + case windowsTerminal = "WINDOWS_TERMINAL" + /* This value is never auto-detected. + * We don’t know how to detect the Windows Console. */ + case windowsConsole = "WINDOWS_CONSOLE" + case windowsVSCode = "WINDOWS_VSCODE" + case windowsUnknown = "WINDOWS_UNKNOWN" + + case unknownVSCode = "UNKNOWN_VSCODE" + case unknown = "UNKNOWN" + + var isVSCode: Bool { + switch self { + case .macOSVSCode, .windowsVSCode, .unknownVSCode: return true + default: return false + } + } + + var isWindowsShell: Bool { + switch self { + case .windowsTerminal, .windowsConsole, .windowsUnknown: return true + default: return false + } + } + + static func detect(from fh: FileHandle, _ envVars: [String: String] = ProcessInfo.processInfo.environment) -> OutputEnvironment { + if let envStr = envVars["CLTLOGGER_OUTPUT_ENV"] { + return OutputEnvironment(rawValue: envStr) ?? .unknown + } + +#if !os(Windows) + /* Let’s detect Xcode. */ + if isatty(fh.fileDescriptor) != 0 && tcgetpgrp(fh.fileDescriptor) == -1 && errno == ENOTTY { + return .xcode + } +#endif + switch envVars["TERM_PROGRAM"] { + case "Apple_Terminal": +#if os(macOS) + return .macOSTerminal +#else + return .unknown +#endif + + case "iTerm.app": +#if os(macOS) + return .macOSiTerm2 +#else + return .unknown +#endif + + case "vscode": +#if os(macOS) + return .macOSVSCode +#elseif os(Windows) + return .windowsVSCode +#else + return .unknownVSCode +#endif + + default: +#if os(macOS) + return .macOSUnknown +#elseif os(Windows) + /* We don’t know how to detect the Windows Terminal env: + * anything we have not previously detected on Windows is the Terminal. */ + return .windowsTerminal +#else + return .unknown +#endif + } + } + +} From cd2ab5e099f7489a673ff5fd4803b9e79056f3de Mon Sep 17 00:00:00 2001 From: Frizlab Date: Wed, 8 Jan 2025 00:25:00 +0100 Subject: [PATCH 7/7] Add a new emoji set --- Sources/Emoji.swift | 13 +++++++++++-- Sources/EmojiSet.swift | 25 +++++++++++++++++++++---- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Sources/Emoji.swift b/Sources/Emoji.swift index 4c0f563..8a42f15 100644 --- a/Sources/Emoji.swift +++ b/Sources/Emoji.swift @@ -14,9 +14,15 @@ internal enum Emoji : String, CaseIterable { case eyebrow = "🤨" case redCross = "❌" case policeLight = "🚨" - case ladybug = "🐞" + case worm = "🐛" case orangeDiamond = "🔶" + case ambulance = "🚑" + case ladybug = "🐞" + case monocle = "🧐" + case greenCheck = "✅" + case fearFace = "😱" + case redHeart = "❤️" case orangeHeart = "🧡" case yellowHeart = "💛" @@ -37,11 +43,14 @@ internal enum Emoji : String, CaseIterable { } switch self { - case .poo, .notebook, .eyebrow, .redCross, .policeLight, .ladybug, .orangeDiamond, + case .poo, .notebook, .eyebrow, .redCross, .policeLight, .worm, .orangeDiamond, .orangeHeart, .yellowHeart, .greenHeart, .blueHeart, .purpleHeart, .blackHeart, .brownHeart, .whiteHeart: return "" + case .ambulance, .ladybug, .monocle, .greenCheck, .fearFace: + return "" + case .cog, .warning, .doubleExclamationPoint, .redHeart: guard !environment.isVSCode, environment != .macOSTerminal else {return " "} diff --git a/Sources/EmojiSet.swift b/Sources/EmojiSet.swift index 40233a3..c56ec5c 100644 --- a/Sources/EmojiSet.swift +++ b/Sources/EmojiSet.swift @@ -14,7 +14,8 @@ internal enum EmojiSet : String { case originalForVSCodeMacOS = "ORIGINAL+VSCODE_MACOS" case originalForVSCodeWindows = "ORIGINAL+VSCODE_WINDOWS" - case vaibhavsingh97EmojiLogger = "VAIBHAVSINGH97_EMOJI_LOGGER" + case vaibhavsingh97EmojiLogger = "VAIBHAVSINGH97_EMOJI_LOGGER" + case vaibhavsingh97EmojiLoggerForVSCodeMacOS = "VAIBHAVSINGH97_EMOJI_LOGGER+VSCODE_MACOS" static func `default`(for environment: OutputEnvironment, _ envVars: [String: String] = ProcessInfo.processInfo.environment) -> EmojiSet { if let envStr = envVars["CLTLOGGER_EMOJI_SET_NAME"], let ret = EmojiSet(rawValue: envStr) { @@ -56,6 +57,17 @@ internal enum EmojiSet : String { case .trace: return .poo } } + let vaibhavsingh97: (Logger.Level) -> Emoji = { + switch $0 { + case .critical: return .ambulance + case .error: return .fearFace + case .warning: return .warning + case .notice: return .greenCheck /* Called success in upstream. */ + case .info: return .monocle + case .debug: return .ladybug + case .trace: return .poo /* Does not exist in upstream. */ + } + } switch self { case .original: @@ -72,7 +84,7 @@ internal enum EmojiSet : String { switch logLevel { case .critical: return .policeLight case .warning: return .orangeDiamond - case .debug: return .ladybug + case .debug: return .worm default: return original(logLevel) } @@ -84,8 +96,13 @@ internal enum EmojiSet : String { } case .vaibhavsingh97EmojiLogger: - /* TODO */ - return original(logLevel) + return vaibhavsingh97(logLevel) + + case .vaibhavsingh97EmojiLoggerForVSCodeMacOS: + switch logLevel { + case .warning: return .orangeDiamond + default: return vaibhavsingh97(logLevel) + } } }