StimVinsh / xdocreport

Automatically exported from code.google.com/p/xdocreport
0 stars 0 forks source link

Configure velocity logging #68

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,

Issue:

Using xdocreport on a web-app based on jboss server with limited 
write-permission.
Velocity logging tries to write on a file "velocity.log" in bin directory
On our server is it impossible, report processing results in a "permission 
denied"
As Velocity engine is created (and RuntimeInstance set in) your framework, I 
didn't figure out how to configure velocity logging in docxreport.

Workaround:

Our workaround was to modify VelocityTemplateEngine (see attach .java) and add 
properties in order to use "org.apache.velocity.runtime.log.Log4JLogChute" as 
LogChute.

Proposition:

May be is it interesting to allow adding a Properties object in IContext to add 
custom modifications in VelocityEngine

see .txt for proposition

Thanks, and nice work, it's very useful! ;-)

Original issue reported on code.google.com by yoplaitd...@gmail.com on 19 Jan 2012 at 12:40

Attachments:

GoogleCodeExporter commented 8 years ago
Hi,

Ok I understand your problem. I will study how to customize the velocity engine.
For your proposition about IContext we cannot do that because the Velocity 
engine is configured before loading docx/odt file.

I will study your code.

> Thanks, and nice work, it's very useful! ;-)

Thanks a lot!

Regards Angelo

Original comment by angelo.z...@gmail.com on 19 Jan 2012 at 1:18

GoogleCodeExporter commented 8 years ago
Hi,

I have commited in the Git Repository a new version of VelocityTemplateEngine 
(see 
http://code.google.com/p/xdocreport/source/browse/template/fr.opensagres.xdocrep
ort.template.velocity/src/main/java/fr/opensagres/xdocreport/template/velocity/V
elocityTemplateEngine.java). At first by default, the velocity engine 
properties is configured to disbale velocity log (to avoid to generate 
velocity.log) : 

---------------------------------------------------
velocityEngineProperties.setProperty(                                
RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,"org.apache.velocity.runtime.log.Nu
llLogChute");
---------------------------------------------------

After I have done a new method Properties VelocityTemplateEngine 
#getVelocityEngineProperties() which returns the properties. So you can call 
this method to customize the properties. The question is where you can call 
this method? 

At first you must understand that there is one instance of 
    VelocityTemplateEngine (so one instance of VelocityEngine) per document type 
(docx, odt, etc....). This design was done to improve performance (use 
VelocityCache, init of Velicity Engine can be long etc...)

Each document type customize the VelocityTemplateEngine (for instance od 
document kinf initialize velocity engine to replace "\n" with <text:line-break 
/> when merge is done. This is done by the 
ODTTemplateEngineInitializerConfigurationDiscovery class. This class implement 
ITemplateEngineInitializerDiscovery and implement void 
ITemplateEngineInitializerDiscovery #initialize(ITemplateEngine 
templateEngine)to initialize the template engine. 

The ODTTemplateEngineInitializerConfigurationDiscovery is registered by using 
SPI means, on other word there is fr.opensagres.xdocreport.document.odt JAR a 
file
META-INF/services/fr.opensagres.xdocreport.document.discovery.ITemplateEngineIni
tializerDiscovery which contains

--------------------------------------------------------
fr.opensagres.xdocreport.document.odt.discovery.ODTTemplateEngineInitializerConf
igurationDiscovery
--------------------------------------------------------

So for your case : 

1) Create you a class like VelocityTemplateEngineInitializerConfiguration like 
this: 

---------------------------------------------------------------------
package fr.opensagres.xdocreport;

import java.util.Properties;

import org.apache.velocity.runtime.RuntimeConstants;

import 
fr.opensagres.xdocreport.document.discovery.ITemplateEngineInitializerDiscovery;
import fr.opensagres.xdocreport.template.ITemplateEngine;
import fr.opensagres.xdocreport.template.TemplateEngineKind;
import fr.opensagres.xdocreport.template.velocity.VelocityTemplateEngine;

public class VelocityTemplateEngineInitializerConfiguration implements 
ITemplateEngineInitializerDiscovery {

    public String getId() {
        return VelocityTemplateEngineInitializerConfiguration.class.getName();
    }

    public String getDescription() {
        return null;
    }

    public String getDocumentKind() {
        return null;
    }

    public void initialize(ITemplateEngine templateEngine) {
        if (TemplateEngineKind.Velocity.name().equals(templateEngine.getKind())) {
            Properties p = ((VelocityTemplateEngine) templateEngine)
                    .getVelocityEngineProperties();
            p.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
                    "org.apache.velocity.runtime.log.Log4JLogChute");
            p.setProperty("runtime.log.logsystem.log4j.logger", "XdocLogger");
        }
    }
}
---------------------------------------------------------------------

In your project create a file 
META-INF/services/fr.opensagres.xdocreport.document.discovery.ITemplateEngineIni
tializerDiscovery

with this content : 

---------------------------------------------------------------------
fr.opensagres.xdocreport.VelocityTemplateEngineInitializerConfiguration
---------------------------------------------------------------------

And that's all.

Hope you will like this idea.

Regards Angelo

Original comment by angelo.z...@gmail.com on 20 Jan 2012 at 9:02

GoogleCodeExporter commented 8 years ago
I tested replacing again our "custom" class by the one you communicate 
hereover, seems to work pretty well.

Setting logChute on null by default gave a satisfactory answer to our problem 
yet.

Anyway I'll keep a look on this and check again in next version.

Thanks for quick reaction.

A plus

Original comment by yoplaitd...@gmail.com on 23 Jan 2012 at 2:08

GoogleCodeExporter commented 8 years ago

Original comment by angelo.z...@gmail.com on 20 Mar 2012 at 1:23

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Hi, I have the same problem. Please tell me if the solution is always valid or 
not. I can not seem to implement this code (VelocityTemplateEngine have 
different methods). I'm very angry to see "Caused by: 
java.io.FileNotFoundException: velocity.log (Permission denied)".

Thanks in advance
Pasquale

Original comment by pdi...@gmail.com on 30 Jul 2013 at 4:58

GoogleCodeExporter commented 8 years ago
If you use last version of XDocReport (1.0.2), Velocity is setted with 
org.apache.velocity.runtime.log.NullLogChute. See that at
https://code.google.com/p/xdocreport/source/browse/template/fr.opensagres.xdocre
port.template.velocity/src/main/java/fr/opensagres/xdocreport/template/velocity/
discovery/VelocityTemplateEngineDiscovery.java

The two reasons that I see that Velocity tries to log in the velocity.log are : 

1) org.apache.velocity.runtime.log.NullLogChute doesn't exist in your classpath.
2) you have define a velocity.properties which override the XDocReport config 
for Velocity.

Original comment by angelo.z...@gmail.com on 30 Jul 2013 at 7:07