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

Remove backslashes from output #40

Open
djtecha opened this issue Apr 10, 2014 · 4 comments
Open

Remove backslashes from output #40

djtecha opened this issue Apr 10, 2014 · 4 comments

Comments

@djtecha
Copy link

djtecha commented Apr 10, 2014

Is there a way to remove the escape chars. from showing up in the output? This leads to ugly logs, especially when links are involved that I'd like to follow.
Ex: User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:28.0) Gecko/20100101 Firefox/28.0

should show up as:
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:28.0) Gecko/20100101 Firefox/28.0

@lusis
Copy link
Contributor

lusis commented Sep 9, 2014

Where/what is generating that event? I'm not seeing it on my side so I'd like to have something I can write a test case against.

@djtecha
Copy link
Author

djtecha commented Sep 9, 2014

This was tomcat that was writing to a file using this plugin. Notice the "/" showing up. The JSON file would then show a string such as: {"thread_name":"localhost-startStop-1","message":"Using the database properties file at : /data/program/../config/trunk.database.properties","@timestamp":"2014-09-09T19:30:52.302Z","level":"INFO","mdc":{},"file":"?","class":"?","line_number":"?","logger_name":"program.hibernateConfig.HibernatePropertyManager","method":"?","@Version":1,"source_host":"trunk-websrv-1"}

@lusis
Copy link
Contributor

lusis commented Sep 10, 2014

@djtecha I just want to verify that this ONLY happens when using the json formatter and not using standard log4j formatting? There's nothing explict in this code that would do that. It COULD be a json serialization thing but forward slashes don't NEED to be escaped.

I'm looking now to see if this is something Hibernate is doing.

@jkburges
Copy link

It seems to me that the escaping happens because of https://code.google.com/p/json-smart/source/browse/2.0/json-smart/src/main/java/net/minidev/json/JSONObject.java?r=ec861df8c01fd61f6dc6cd395a96edee99f225d3#51 (at least if you believe the comment).

It'd be nice if there was a way to either log an "unescaped" string, and/or pass in a map, e.g.:

log.info([key: 'val'])

I think it's possible with something like the below:

org.apache.log4j.spi.LoggingEvent loggingEvent = 
    new org.apache.log4j.spi.LoggingEvent(
        'my.cat', 
        new org.apache.log4j.spi.RootLogger(org.apache.log4j.Level.INFO),
        org.apache.log4j.Level.INFO,
        [ key: "{ some: 'more' }" ],
        null
    )

net.minidev.json.JSONObject logstashEvent = new net.minidev.json.JSONObject()
logstashEvent.put("message", loggingEvent.getMessage());

println "logstashEvent: ${logstashEvent.toString()}"

This outputs:

logstashEvent: {"message":{"key":"{ some: 'more' }"}}

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

3 participants