Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape special characters in JSON and XML format #161

Open
sullerandras opened this issue Nov 15, 2017 · 3 comments
Open

Escape special characters in JSON and XML format #161

sullerandras opened this issue Nov 15, 2017 · 3 comments

Comments

@sullerandras
Copy link

I see that there is a json format, but it seems like special characters like double quote (") and newline (\n) are not escaped in Msg so the result is an invalid json.
XML also has characters which should be escaped.
Is there a solution to this?

@Anteoy
Copy link

Anteoy commented Jan 11, 2018

I encountered the same problem, is there any solution?

@jpadilla
Copy link

Just ran into this as well.

@timestee
Copy link

timestee commented Jun 13, 2018

Just ran into this as well. +1 ,should we escape the msg by ourself?

Update, you could quote msg like:

var StdReceiverConf string = `<seelog type="sync">
		<outputs>
			<console formatid="std_json"/>
		</outputs>
		<formats>
			<format id="std_json" format='{"t":"%Date %Time","l":"%Lev","m":%QuoteMsg,"p":"%RelFile","n":"%Line"}%n'/>
		</formats>
	</seelog>`


func createQuoteMsgFormatter(params string) seelog.FormatterFunc {
	return func(message string, level seelog.LogLevel, context seelog.LogContextInterface) interface{} {
		return strconv.Quote(message)
	}
}
seelog.RegisterCustomFormatter("QuoteMsg",createQuoteMsgFormatter)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants