Can not use log4j extensions in log4j configuration, causes ClassNotFoundException

Bug #511955 reported by Oded Peer
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
play framework
New
Undecided
Unassigned
1.0
Won't Fix
Undecided
Unassigned
1.1
Confirmed
Undecided
Unassigned

Bug Description

I want to use my my own classes, extension of log4j classes, in my log4j configuration.
I wrote the classes and changed the log4j.properties accordingly.
For example:

public class MyAppender extends org.apache.log4j.ConsoleAppender
{}

And the log4j configuration
log4j.rootLogger=WARN, Console
log4j.appender.Console=MyAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d %p [%c] - <%m>%n

When I run the server in the command line I get java.lang.ClassNotFoundException: MyAppender.
When I run the server from Eclipse it works properly.
I think it works in Eclipse since the Eclipse classpath looks in the Eclipse compiled classes folder.
I tried to precompile the application (play precompile) but I get the same log4j error during precompilation.

Tags: log4j
Revision history for this message
Erwan Loisant (eloisant) wrote :

Did you try writing a plugin and putting your classes in src/, rather than putting them in the portion that gets compiled on the fly?

Revision history for this message
Oded Peer (oded-50) wrote :

I would really like to avoid having my classes in the "src" directory.
There are a few solutions as I see it:
1. Create a new project for logging. Have this project produce a jar file, add the jar file to play. This is what I've done to work around the problem, but since play does not have a real "build" procedure I would like to maintain only one project. This is more a maven-style solution.

2. Move my log4j.xml file out of the conf directory, and re-configure log4j in a plugin with my log4j.xml file.

3. Have some kind of "boot" play class loader. This will also allow play developers to override the way Play reads the configuration.

Changed in play:
milestone: none → 1.0.2
summary: - Can not use log4j extensions in log4j configuration, casues
+ Can not use log4j extensions in log4j configuration, causes
ClassNotFoundException
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.