rs / zerolog

Zero Allocation JSON Logger
MIT License
10.62k stars 572 forks source link

Adding Event.Type(...) method to log the type of an object #437

Closed w3aponx closed 2 years ago

w3aponx commented 2 years ago

I found myself wanting to log the type of an object and was convinced there would be a method to do that already, but I didn't find one. Here's a case where one might want such a method:

    var value interface{}
    var result string
    switch v := value.(type) {
    case int:
        result = strconv.Itoa(v)
    case string:
        result = v
    default:
        log.Panic().Type("type", v).Msg("Unexpected value type")
    }
    log.Info().Msg(result)

Let me know if there's anything else that needs to change for this to get accepted.

w3aponx commented 2 years ago

@rs are you waiting for any more changes here? Just wanted to make sure because AFAIK the requested changes were implemented a while back and I'm not sure how I can convey that any better than by requesting another review. If it's just that you've been busy with other stuff, no worries -- just wanted to ensure you weren't waiting for something on my part.