emaloney / CleanroomLogger

CleanroomLogger provides an extensible Swift-based logging API that is simple, lightweight and performant
MIT License
1.32k stars 154 forks source link

how to change the log's color in XcodeColors #45

Closed IamAlchemist closed 8 years ago

IamAlchemist commented 8 years ago

CleanroomLogger really great, but i wan't to know how to change the color of logs in XcodeColor According to the document, ColorTable Should be override.

Could anybody give me an example to set it?

the following is my way to override the ColorTable but never worked

        let formatter = XcodeLogFormatter(timestampStyle: .Default, severityStyle: .Xcode, delimiterStyle: nil, showCallSite: true, showCallingThread: false, colorizer: nil)
        let config = XcodeLogConfiguration(minimumSeverity: .Verbose, colorTable: HulkColorTable(), formatter: formatter)
        Log.enable(configuration: config)
emaloney commented 8 years ago

Hmmm, just taking a glance at the code you've supplied, it looks like you're doing everything correctly.

Can you verify that XcodeColors is installed correctly & enabled? (If you don't pass your own ColorTable, do you get the expected default colorized output?)

Also, if you wouldn't mind letting me take a look at the HulkColorTable implementation, perhaps I can help. If that's OK with you, I'll reach out via e-mail.

IamAlchemist commented 8 years ago

@emaloney Thank you a lot for replying

This is the implement of HulkColorTable

struct HulkColorTable : ColorTable {
    func foregroundColorForSeverity(severity: LogSeverity) -> Color? {
        switch severity {
        case .Verbose:
            return Color(r: 64, g: 64, b: 64)
        case .Debug:
            return Color(r: 128, g: 128, b: 128)
        case .Info:
            return Color(r: 0, g: 184, b: 254)
        case .Warning:
            return Color(r: 214, g: 134, b: 47)
        case .Error:
            return Color(r: 185, g: 81, b: 46)
        }
    }
}

Although I set configuration with this HulkColorTable, the console still show the error message with the color of (255,0,0)

screen shot 2016-05-06 at 22 10 12

please email me if needed.

thanks a lot

dev4dev commented 8 years ago

The same problem here. It just ignores colors from ColorTable =\ But I have different setup code

        let config = XcodeLogConfiguration(minimumSeverity: .Verbose, debugMode: true, verboseDebugMode: true, logToASL: false, colorizer: XcodeColorsTextColorizer(), colorTable: LoggerColorTable(), filters: [], formatter: XcodeLogFormatter())
        Log.enable(configuration: config)
emaloney commented 8 years ago

Thanks a lot for finding the source of this bug, @IamAlchemist.

I have not merged in your PR since I've applied your fix manually (at least to master as of this moment).

I plan to do some more Swift 2.3 / Swift 3.0 work next week and hope to roll the fix out to all branches then.

In the meantime, I'll keep your PR open until you can confirm that the fix on master works as expected for you.

I appreciate you digging in to this. If you have a Twitter handle and let me know what it is, I'll give you a shout-out there, too.

emaloney commented 8 years ago

P.S. I should add that the fix is available in CleanroomLogger 2.1.1.

emaloney commented 8 years ago

An update: Your fix is also now available on the swift2.3 and swift3 branches. Thanks again!