bob*_*205 5 apache velocity logfiles
似乎很直接.http://velocity.apache.org/engine/devel/developer-guide.html#Configuring_Logging上的文档 说明要设置runtime.log属性.这是我所有物业的所得.
velocityEngine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templatesPath);
velocityEngine.setProperty("runtime.log", "/path/to/my/file/velocity.log");
velocityEngine.setProperty("resource.loader", "string");
velocityEngine.setProperty("string.resource.loader.class", "org.apache.velocity.runtime.resource.loader.StringResourceLoader");
velocityEngine.setProperty("string.resource.loader.repository.class", "org.apache.velocity.runtime.resource.util.StringResourceRepositoryImpl");
Run Code Online (Sandbox Code Playgroud)
没有找到我告诉它放置它的任何日志文件,而是找到旧的(初始化文件夹)位置的新错误.有任何想法吗?:d
小智 1
我在运行时设置一些选项时遇到了类似的问题。我通过自定义 VelocityBuilder 和外部 Velocity.properties 文件解决了这些问题,您可以在其中放置所有运行时属性。这是代码:
public class BaseVelocityBuilder implements VelocityBuilder {
private VelocityEngine engine;
private Log logger = LogFactory.getLog(getClass());
@Autowired
private WebApplicationContext webApplicationContext;
public VelocityEngine engine() {
if(engine == null) {
engine = new VelocityEngine();
Properties properties = new Properties();
InputStream in = null;
try {
in = webApplicationContext.getServletContext().getResourceAsStream("/WEB-INF/velocity.properties");
properties.load(in);
engine.init(properties);
} catch (IOException e) {
e.printStackTrace();
logger.error("Error loading velocity engine properties");
throw new ProgramException("Cannot load velocity engine properties");
}
IOUtils.closeQuietly(in);
}
return engine;
}
}
Run Code Online (Sandbox Code Playgroud)
看到这一行:
in = webApplicationContext.getServletContext().getResourceAsStream("/WEB-INF/velocity.properties");
properties.load(in);
engine.init(properties);
Run Code Online (Sandbox Code Playgroud)
所以我在/WEB-INF中有一个velocity.properties文件,我在其中放置了一些配置:
resource.loader = webinf, class
webinf.resource.loader.description = Framework Templates Resource Loader
webinf.resource.loader.class = applica.framework.library.velocity.WEBINFResourceLoader
webapp.resource.loader.class = org.apache.velocity.tools.view.servlet.WebappLoader
webapp.resource.loader.path =
file.resource.loader.description = Velocity File Resource Loader
file.resource.loader.class = org.apache.velocity.runtime.resource.loader.FileResourceLoader
file.resource.loader.path =
class.resource.loader.description = Velocity Classpath Resource Loader
class.resource.loader.class = org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
runtime.log='/pathYouWant/velocity.log'
Run Code Online (Sandbox Code Playgroud)
最后在你的 application.xml 中:
<bean class="applica.framework.library.velocity.BaseVelocityBuilder" />
Run Code Online (Sandbox Code Playgroud)
通过这种方式,您可以为不同的应用程序拥有不同的文件日志,并且当您在生产中进行战争时,sysadm 可以由于生产服务器的 env 配置而更改属性。
归档时间: |
|
查看次数: |
9293 次 |
最近记录: |