Archiv für den Monat: August 2017

Logging in Griffon 2
using Log4j

I’ve done quite some Java programming for the Desktop with JavaFX lately. For that I’ve jumped into using the Griffon Framework and I really love it.

For logging, it comes with SLF4J (the Simple Logging Facade for Java), so you can plug in the actual framework of your chioce – and I gave it a try with Log4J 2 . Since it took me a little while to get it all working the way I wanted it to, here are the basic steps that worked for me:

first, in build.gradle, you have to put

    runtime('log4j:log4j:1.2.17') {
        exclude group: 'ant',         module: 'ant-nodeps'
        exclude group: 'ant',         module: 'ant-junit'
        exclude group: 'ant-contrib', module: 'ant-contrib'
    runtime "org.slf4j:slf4j-log4j12:${slf4jVersion}"

then, create griffon-app/resources/


# log4j.appender.myapp.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{8}:%L - %m%n
log4j.appender.myapp.layout.ConversionPattern=%-5p %c{8}:%L - %m%n

# show tool versions at startup:

# turn down noise on griffon's internals:
# you might need those when searching for a problem

# logs the app itself:

That is it! This of corse is just a very basic configuration but it is exactly what I need and use during development – for deployment, you just need to change the ConsoleAppender to e.g. a RollingFileAppender or whatever you prefer. And you may change the app’s logging level to something less noisy.

Now  just like in Grails, you get a log variable injected into your MVC-members
and you can  for example… "hello world!"

Quite simple, IMHO.

HTH! cheers, weHe