How to configure JBoss JsonFormatter for Filebeat (WildFly 14)

心已入冬 提交于 2020-02-06 09:27:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!