2

I'm trying to use Log4J for keycloak project as logging framework since there are custom rolling appenders we have written with few value additions.

I was referring to changing logging subsystem in wildfly (keycloak embbeded server - keycloak/standalone/configuration/standalone.xml ), but seems like I'm missing something.

How can I add a custom log4j rolling appender to Keycloak (wildfly)

1 Answers1

2

You can add a log4j appender as a custom-handler. If you're using a custom log4j appender you'd need to install it as a module first.

Example CLI command to add a org.apache.log4j.RollingFileAppender.

/subsystem=logging/custom-handler=log4j-file:add(module=org.apache.log4j,class=org.apache.log4j.RollingFileAppender,named-formatter=PATTERN,properties={maxBackupIndex=5,append=true,immediateFlush=true,maxFileSize="10MB",file="${jboss.server.log.dir}/log4j.log"})
James R. Perkins
  • 16,800
  • 44
  • 60
  • Hi James thank you for your answer. The same you illustrated as CLI can be added to standalone.xml ? – Chamantha De Silva Apr 28 '15 at 05:29
  • Using the CLI will update the standalone.xml. The standalone.xml is just the persistence form of the configuration. Executing the CLI commands updates the runtime configuration and the persistence configuration. – James R. Perkins Apr 28 '15 at 21:48
  • Thanks James, I tried it and it works well with RollingFileAppender. But in my case I have a small problem, I have a custom class instead of RollingFileAppender. Since this is a custom class I included it /standalone/lib/ext but jar didn't seems picked by Wildfly. Any thing extra that I need to be fulfilled in order to pick the dependency from ?. – Chamantha De Silva Apr 29 '15 at 05:14
  • You have install it as a module in order to get it to work. In WildFly CLI there is a `module` command you can use to install it as a module or you can just manually configure the module. – James R. Perkins Apr 29 '15 at 20:31
  • Thanks you James for the instructions, I'm kind a new to Wildfly, with your useful information was able to install new modules and it works fine now. – Chamantha De Silva Apr 30 '15 at 23:08