Add DisableEscapeHTML option for json logger#690
Add DisableEscapeHTML option for json logger#690soh335 wants to merge 2 commits intogo-kit:masterfrom
Conversation
|
oops. sorry I break I think there are some ideas.
|
|
My initial thought is to call SetHTMLEscape(false) in jsonLogger without option. I'm not sure how much that is really a breaking change. The output will still be JSON compliant. I wouldn't consider the browser as a primary target for the output of jsonLogger. |
I think so too. so no one care about this change, call SetHTMLEscape(false) in jsonLogger seems to be better than others. |
|
This would read better if the property was named |
|
@peterbourgon how about this ? |
log/json_logger.go
Outdated
|
|
||
| type jsonLogger struct { | ||
| io.Writer | ||
| disableEscapeHTML bool |
There was a problem hiding this comment.
This should be
escapeHTML booldefaulting to false.
log/json_logger.go
Outdated
| type JSONLoggerOption func(*jsonLogger) | ||
|
|
||
| // DisableEscapeHTML disable to escape &, <, >. | ||
| func DisableEscapeHTML(v bool) JSONLoggerOption { |
There was a problem hiding this comment.
log/json_logger.go
Outdated
| } | ||
| return json.NewEncoder(l.Writer).Encode(m) | ||
| enc := json.NewEncoder(l.Writer) | ||
| enc.SetEscapeHTML(!l.disableEscapeHTML) |
There was a problem hiding this comment.
This should be
enc.SetEscapeHTML(l.escapeHTML)|
@peterbourgon thanks for reviewing and change to SetEscapeHTML. Should I change like this ? (I think its not smart...) - format: log.NewJSONLogger,
+ format: func(w io.Writer) log.Logger { return log.NewJSONLogger(w) },- logger := term.NewLogger(os.Stdout, log.NewJSONLogger, colorFn)
+ logger := term.NewLogger(os.Stdout, func(w io.Writer) log.Logger { return log.NewJSONLogger(w) }, colorFn) |
|
Seems like an OK solution. |
|
I'm not convinced yet. There is something very satisfying about the functions signatures of |
|
I could also see this being solved with e.g. type HTMLEscapingLogger struct {
next log.Logger
}
func (l HTMLEscapingLogger) Log(keyvals ...interface{}) error {
for i := 0; i < len(keyvals); i += 2 {
keyvals[i+1] = htmlEscape(keyvals[i+1])
}
l.next(keyvals...)
} |
|
Is it mean call |
|
@ChrisHines @peterbourgon it seems to be difficult both to keep |
|
I haven't seen any objections to just changing the existing JSONLogger to always call |
Hi.
I add DisableEscapeHTML option for json logger. If pass
log.DisableEscapeHTML(true)to NewJSONLogger, we can get more readability.Thanks.