如何动态更改log4j日志文件? [英] how to change the log4j log file dynamically?

查看:148
本文介绍了如何动态更改log4j日志文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个log4j配置,使日志文件名应该像$ {System-name} log.log一样。即如果应用程序在任何系统上启动,则无需更改配置文件或代码。它应该生成所提到的日志文件名。
谢谢。

I want to have a log4j configuration such that the log file name should have like ${System-name}log.log. that is if the application is launched on any system then without changing the configuration file or code. it should generate the log file name as mentioned. thanks.

推荐答案

您可以使用 $ {property} <的Java系统属性/ code>语法。默认情况下定义了许多系统属性,包括

You can use Java system properties with the ${property} syntax. There are number of system properties that are defined by default including

"os.arch"     Operating system architecture
"os.name"     Operating system name
"os.version"  Operating system version

完整版默认属性列表请参阅的API系统或列出它们 System.getProperties()。list(System.out)

For a full list of default properties see API of System or list them with System.getProperties().list(System.out).

如果默认属性不起作用,那么您将使用 System.setProperty(property,value)添加自己的属性。

If the default properties won't do then you'll have top add your own properties using System.setProperty(property, value).

这篇关于如何动态更改log4j日志文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆