问题
I have Filebeat pulling logs from stdout. I want to ensure my logs are outputted as JSON, so they can be properly parsed.
Thus far, here's what I've found:
- org.jboss.logmanager.formatters doesn't have a JSON formatter
- There's an "extension" module that provides a JsonFormatter class.
- I can use it in my logging.properties by doing something like this:
handler.CONSOLE=org.jboss.logmanager.handlers.ConsoleHandler
handler.CONSOLE.properties=autoFlush,target
handler.CONSOLE.autoFlush=true
handler.CONSOLE.formatter=JSON-FORMATTER
handler.CONSOLE.target=SYSTEM_OUT
formatter.JSON-FORMATTER=org.jboss.logmanager.ext.formatters.JSONFormatter
I need to know:
- Am I missing anything with this configuration?
- How can I customise the JSON output (i.e. add or remove fields)?
回答1:
There is a json-formatter in WildFly 14. I would not suggest editing the logging.properties
. The following CLI commands are an example of configuring a json-formatter
.
/subsystem=logging/json-formatter=json:add(exception-output-type=formatted, pretty-print=false, meta-data={label=value})
/subsystem=logging/console-handler=CONSOLE:write-attribute(name=named-formatter, value=json)
Note the meta-data
attribute is just a key/value pair separated by commas.
How can I customise the JSON output (i.e. add or remove fields)?
You can really only add metadata or change field names. You can't remove fields though.
来源:https://stackoverflow.com/questions/54515083/how-to-configure-jboss-jsonformatter-for-filebeat-wildfly-14