velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dr. Matthias Laux" <matthias.l...@web.de>
Subject Problems using logging in Velocity 1.6.2
Date Sun, 23 Aug 2009 08:07:30 GMT
(aopolgies if this should appear twice - I don't
see my first email on the mailing list archive so
I gather the mail may not have made it)



Hi,

I'm lost getting Velocity logging to work the way I need it.

In the past I used the Velocity directly such as

Velocity.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, 
templateDir);
Velocity.init();

and got the expected output in the velocity.log file.

Now I moved to using VelocityEngine instead because I had some issues 
with the output
in a long running server app which performed the same tasks over and 
over again (the
velocity.log file would grow and I did not know how to get Velocity to 
start a new file
for every processing run).

Anyway. Now the new code started to look like this:

engine = new VelocityEngine();
engine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templateDir);
engine.init();

and nothing happens other than an empty file "velocity.log" being 
created. Well.

So I added a LogChute:

engine = new VelocityEngine();
engine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templateDir);
engine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, 
"org.apache.velocity.runtime.log.JdkLogChute");
engine.init();

because I'm using JDK logging in my app anyway. My own logging is based
on a console handler with level INFO and a file handler with level FINE (at
least right now).

What happened now was that there was nothing related to Velocity on the
console, and truckloads of FINE log entries in the file handler. That's not
quite all of the expected results, but it's the best I got so far. As it 
seems,
Velocity seems to pick up the settings of the JDK logging subsystem.

It gets weird tho when I set the logging level for the file handler to 
INFO as
well: all log entries to the file handler for the JdkLogChute are gone. 
The only
way for me to understand these observations is that only log messages of
level FINE are actually recorded. Even if I go to level FINEST and check out
the log files afterwards, there's zillions of Velocity log entries, but all
with level FINE. This works also for the java.util.logging.ConsoleHandler,
i. e. setting the level to FINE there also gives me the log messages, but
all of level FINE. In my original velocity.log there were - for the same 
set of
data - "[error]" and "[debug]" entries which I would like to see again as
corresponding log entries.

Having only messages of level FINE can't be correct tho.

When, for testing purposes, I add a manual log entry like this

engine.getLog().info("Hello");

right after the init(), it works on both console and file. So the loggers
used inside Velocity also work correctly, but it seems that Velocity
itself only creates log messages with level FINE - which I refuse to 
believe.

I also tried the AvalonLogChute instead since that seems to be the
default used in my previous implementation (velocity.log created
by interacting with Velocity instead of VelocityEngine). Same result
- an empty velocity.log file. Well, this is not too surprising since
I presume that the AvalonLogChute is still the default - and I had
not specified a LogChute in the first attempts.

I'm kinda lost right now. I would like to be able to use JDK logging
(since then I don't have to deal with different output files in analysis
afterwards) and I would like to propagate the (configurable) log
levels of my application to the Velocity logging.

At the very least, I need a new velocity.log file to be created whenever
my application starts a new iteration - whichever LogChute gives
me that back. It does this effectively as listed above:

Old version:

Invoke

Velocity.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, 
templateDir);
Velocity.init();

-> results in all output being appended to one velocity.log file. This will
be a file system capacity issue in the long run.

New Version:

engine = new VelocityEngine();
engine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templateDir);
engine.init();

-> results in an empty velocity.log. Not very helpful for finding problems.

Any help would be very much appreciated. Studying the Velocity source
code gave me some hints, but for now to no avail. Something must be
wrong in the way I configure the VelocityEngine instance, I guess.

Thanks,
Matthias


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Mime
View raw message