public class Log4JConfigurator extends Object
The Log4JConfigurator bean can be used to configure log4j settings in Spring. It takes the path to the log4j properties file, and the directory where logfiles should be written. The directory is then configured as system property log.dir so it can also be used in the log4j properties file.
Log4J is configured when the configure method of the bean is called.
Example use in spring configuration file:
<bean class="com.foreach.spring.logging.Log4JConfigurator" init-method="configure" lazy-init="false"> <property name="propertiesFile" value="classpath:/config/log.properties"/> <property name="logDirectory" value="/project-logging-dir"/> </bean>
Example excerpt of log.properties (depends on apache-log4j-extras):
log4j.appender.logfile=org.apache.log4j.rolling.RollingFileAppender
log4j.appender.logfile.rollingPolicy=org.apache.log4j.rolling.TimeBasedRollingPolicy
log4j.appender.logfile.rollingPolicy.FileNamePattern=${log.dir}/logfile-%d{yyyy-MM-dd}.log
| Constructor and Description |
|---|
Log4JConfigurator() |
| Modifier and Type | Method and Description |
|---|---|
void |
configure()
Configures Log4J using a
PropertyConfigurator and the properties file set on the bean. |
String |
getLogDirectory()
Getter for the field
logDirectory. |
org.springframework.core.io.Resource |
getPropertiesFile()
Getter for the field
propertiesFile. |
void |
setLogDirectory(String logDirectory)
Setter for the field
logDirectory. |
void |
setPropertiesFile(org.springframework.core.io.Resource location)
Setter for the Log4J configuration file (properties format).
|
public final void configure()
throws IOException
Configures Log4J using a PropertyConfigurator and the properties file set on the bean.
IOException - if something goes wrong with reading the properties file.public final org.springframework.core.io.Resource getPropertiesFile()
Getter for the field propertiesFile.
Resource object.public final void setPropertiesFile(org.springframework.core.io.Resource location)
Setter for the Log4J configuration file (properties format).
location - a Resource object.public final String getLogDirectory()
Getter for the field logDirectory.
String object.Copyright © 2017. All rights reserved.