Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using log4j from src/groovy files

I'm trying to use log4j from my src/groovy class in grails project like this:

package com.brand.vh.importer.command

import org.apache.log4j.Logger

class NewOrder extends CommandAbstract {
   private final Logger log = Logger.getLogger(getClass())

   NewOrder() {
       log.debug("NewOrder constructor called")
   }
}

In Config.groovy I have the following log4j settings:

....
// log4j configuration
import org.apache.log4j.DailyRollingFileAppender
log4j = {
    appenders {
        appender new DailyRollingFileAppender(
            name: "fileAppenderImporter",
            file: "log/importer.log",
            datePattern: "'.'yyyy-MM-dd",
            layout: pattern(
                        conversionPattern:
                        "%d{ISO8601} [%p][%X{IP}](%F:%M:%L):%n%m%n%n"
                    )
        )
        ....
    }
    ...
    debug additivity: false,
        fileAppenderImporter: ["com.brand.vh.importer"]
    ...
}

But my log/importer.log is always empty. What's wrong with my code/config?

I will be glad to any advice, links etc

like image 271
dyker Avatar asked Dec 23 '11 12:12

dyker


1 Answers

I wonder if you have your parameters out of order.

This works for me:

log4j = {
    appenders {
        console name: 'stdout', layout: pattern(conversionPattern: '%d [%t] %-5p [%c(%F:%L)] - %m%n')
        appender new DailyRollingFileAppender(
                name: "fileAppenderImporter",
                file: "log/importer.log",
                datePattern: "'.'yyyy-MM-dd",
                layout: pattern(
                        conversionPattern:
                        "%d{ISO8601} [%p][%X{IP}](%F:%M:%L):%n%m%n%n"
                )
        )
    }

    root {
        debug 'stdout'
        info 'stdout'
        additivity = false
    }

    debug fileAppenderImporter: ['com.brand.vh.importer'], additivity: false
}

With your same code.

like image 108
Rob Elsner Avatar answered Sep 23 '22 22:09

Rob Elsner