DaveWoodCom/XCGLogger

XcodeColorsLogFormatter not working

DuShuYuan opened this issue · 3 comments

let log: XCGLogger = {
    // Setup XCGLogger
    
    let log = XCGLogger.default

    let dateFormatter = DateFormatter()
    dateFormatter.dateFormat = "hh:mm:ss.SSS"
    dateFormatter.locale = Locale.current
    log.dateFormatter = dateFormatter
    
    
    let ansiColorLogFormatter = XcodeColorsLogFormatter()
    ansiColorLogFormatter.colorize(level: .debug, with: .black)
    ansiColorLogFormatter.colorize(level: .info, with: .blue)
    ansiColorLogFormatter.colorize(level: .notice, with: .green)
    ansiColorLogFormatter.colorize(level: .warning, with: .red)
    ansiColorLogFormatter.colorize(level: .error, with: .red)
    ansiColorLogFormatter.colorize(level: .severe, with: .white, on: .red)
    ansiColorLogFormatter.colorize(level: .alert, with: .white, on: .red)
    ansiColorLogFormatter.colorize(level: .emergency, with: .white, on: .red)
    log.formatters = [ansiColorLogFormatter]
    #if DEBUG
        log.setup(
            level: .debug,
            showFunctionName: false,
            showThreadName: true,
            showLevel: true,
            showFileNames: true,
            showLineNumbers: true,
            writeToFile: nil
        )
    #else
        log.setup(
            level: .error,
            showFunctionName: false,
            showThreadName: true,
            showLevel: true,
            showFileNames: true,
            showLineNumbers: true,
            writeToFile: nil
        )
    #endif
    
    log.levelDescriptions[.verbose] = "🗯🗯"
    log.levelDescriptions[.debug] = "✳️✳️"
    log.levelDescriptions[.info] = "ℹ️ℹ️"
    log.levelDescriptions[.notice] = "🔹🔹"
    log.levelDescriptions[.warning] = "⚠️⚠️"
    log.levelDescriptions[.error] = "‼️‼️"
    log.levelDescriptions[.severe] = "💣💣"
    log.levelDescriptions[.alert] = "🛑🛑"
    log.levelDescriptions[.emergency] = "🚨🚨"
    
    log.logAppDetails()

    return log
}()

WeChatbbde421e7e146e3e61ccfeb35e132091

xcode12.4 xcglogger 7.0.1

Remove:

    let ansiColorLogFormatter = XcodeColorsLogFormatter()
    ansiColorLogFormatter.colorize(level: .debug, with: .black)
    ansiColorLogFormatter.colorize(level: .info, with: .blue)
    ansiColorLogFormatter.colorize(level: .notice, with: .green)
    ansiColorLogFormatter.colorize(level: .warning, with: .red)
    ansiColorLogFormatter.colorize(level: .error, with: .red)
    ansiColorLogFormatter.colorize(level: .severe, with: .white, on: .red)
    ansiColorLogFormatter.colorize(level: .alert, with: .white, on: .red)
    ansiColorLogFormatter.colorize(level: .emergency, with: .white, on: .red)
    log.formatters = [ansiColorLogFormatter]

from your set up. Xcode no longer supporters colours in the console area. The XcodeColorsLogFormatter is only useful now if you're logging to an external source compatible with ANSI codes.

Instead of below it also not work

let ansiColorLogFormatter = ANSIColorLogFormatter()
ansiColorLogFormatter.colorize(level: .debug, with: .black)
ansiColorLogFormatter.colorize(level: .info, with: .blue)
ansiColorLogFormatter.colorize(level: .notice, with: .green)
ansiColorLogFormatter.colorize(level: .warning, with: .red)
ansiColorLogFormatter.colorize(level: .error, with: .red)
ansiColorLogFormatter.colorize(level: .severe, with: .white, on: .red)
ansiColorLogFormatter.colorize(level: .alert, with: .white, on: .red)
ansiColorLogFormatter.colorize(level: .emergency, with: .white, on: .red)
log.formatters = [ansiColorLogFormatter]