I’ve been working at getting Solr working under Tomcat, and ran into velocity.log issue
I’m documenting my troubles and their solutions here because otherwise they won’t exist on the web for people to find. Putting solutions to problems on the web makes them findable for the next poor guy who has the same problem. I figure that if I spend a day working on fixing problems, I can spend another hour publishing them so others can benefit.
Problem 1 – FileNotFoundException: velocity.log
HTTP Status 500 – org.apache.velocity.exception.VelocityException:
Failed to initialize an instance of
org.apache.velocity.runtime.log.Log4JLogChute with the current
runtime configuration. java.lang.RuntimeException:
org.apache.velocity.exception.VelocityException: Failed to initialize
an instance of org.apache.velocity.runtime.log.Log4JLogChute with
the current runtime configuration. at
Caused by: java.io.FileNotFoundException: velocity.log
(Permission denied) at java.io.FileOutputStream.openAppend(Native
Method) at java.io.FileOutputStream.<init>(FileOutputStream.java:207)
You can refer to this link for fix. Although it’s more like a bandit rather than a real solution, but it works.
Problem 2 – specify velocity.properties
The right solution is to specify velocity.log location yourself. Read Solr Wiki here for details. Basically you need to the following line into solrconfig.xml:
Then put velocity.properties into your solr/conf folder, not not solr/conf/velocity folder!
So I put the following line in my velocity.properties file
When running it in Tomcat, it works, it outputs to tomcat/logs/velocity.log! However, when I deploy it to EC2, I got permission error again!
Problem 3 – there are two velocity.log files
Check my local system, I’ve got tomcat/logs/velocity.log and tomcat/velocity.log, the latter location is the root cause!
Then why it still gets created under tomcat folder? The link explained well.
Version 1.4 of the Velocity template engine supports the log4j logger, amongst others. By default, Velocity will try to use the Jakarta Avalon Logkit. To change this behavior, you must either:
Make sure that no version of the logkit jar file exists in your Tomcat configuration; or
Add the following line to your velocity.properties file:
The latter option is preferable.
That just gets Velocity using Log4j. Velocity will still send its log data to a file named velocity.log. To get Velocity to use the Tomcat system log instead, add the following directive to your velocity.properties file:
This is the name of the Log object to use. Just about any class name would work here, but this is consistent with recommended practice. To change the log level of the Velocity logger to INFO, for example, add this line to your log4j.properties file:
So the ultimate velocity.properties contains the following configuration, everything works fine now!!!