[ 
https://issues.apache.org/jira/browse/LOG4J2-3385?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17485895#comment-17485895
 ] 

Jitin Dominic commented on LOG4J2-3385:
---------------------------------------

[~rgoers] 

I updated my _log4j2.properties_ file:

 
{code:java}
appender.rolling.type = RollingFile
appender.rolling.name = RollingFile
appender.rolling.fileName = /home/jd/app.log
appender.rolling.filePattern = /home/jd/app.%d{yyyy-MM-dd-HH-mm-ss}.log

appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %m%n

appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
 
logger.rolling.name = org.apache.logging.log4j.core.appender.RollingFileAppender
logger.rolling.level = debug
logger.rolling.additivity = false
logger.rolling.appenderRefs = rolling
logger.rolling.appenderRef.rolling.ref = RollingFile

rootLogger.level = debug
rootLogger.appenderRefs = rolling
rootLogger.appenderRef.stdout.ref = RollingFile
 {code}
Now, it creates a file on each run. One  of the concerns is that latest logs 
get added to app.log file, the previous log file gets renamed along with date 
timestamp. 

 

*For eg:*
app.log
app.2022-02-02-20-17-56.log
app.2022-02-02-20-17-53.log

 

Is it possible to have the date time stamp on each file (including the latest 
log file)?

 

And, I think rootLogger is a must, otherwise no data gets added into the logs 
file. As I already have appenders configured at logger and rootLogger, but 
without rootLogger it doesn't log.

> New log file on each run
> ------------------------
>
>                 Key: LOG4J2-3385
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3385
>             Project: Log4j 2
>          Issue Type: Question
>            Reporter: Jitin Dominic
>            Priority: Major
>
> I'm using the latest (v2.17.1) log4j2 dependencies in my grails 2.5.4 
> application. Following are the dependencies used:
>  * log4j-api
>  * log4j-core
>  * log4j-1.2-api
>  * log4j-slf4j-impl
>  
> I'm trying to configure the _log4j2.properties_ in a way to create a new file 
> based on date and time on each application run.
> But when I run it, only the application.log file gets created. There's no 
> date and time in the file name. And also, nothing is logged inside the file; 
> it's empty.  Any idea what I might be configuring wrong.
> Here's my log4j2.properties file:
> {code:java}
> appender.rolling.type = RollingFile 
> appender.rolling.name = RollingFile 
> appender.rolling.fileName = /home/jd/application.log 
> appender.rolling.filePattern = /home/jd/application.%d{dd-MMM-hh}.log 
> appender.rolling.layout.type = PatternLayout appender.rolling.layout.pattern 
> = %d{yyyy-MM-dd HH:mm:ss} %-5p %m%n 
> appender.rolling.policies.type = Policies appender.rolling.policies.time.type 
> = TimeBasedTriggeringPolicy appender.rolling.policies.time.interval = 1 
> appender.rolling.policies.time.modulate = true 
> appender.rolling.strategy.type = DefaultRolloverStrategy 
> appender.rolling.strategy.max = 5   
> logger.rolling.name = 
> org.apache.logging.log4j.core.appender.RollingFileAppender 
> logger.rolling.level = debug 
> logger.rolling.additivity = false 
> logger.rolling.appenderRefs = rolling logger.rolling.appenderRef.rolling.ref 
> = RollingFile  {code}
> *+Update:+*
> When I add rootLogger level,
> {code:java}
> rootLogger.level = debug
> rootLogger.appenderRefs = rolling
> rootLogger.appenderRef.stdout.ref = RollingFile {code}
> am able to see the contents now in the file. Is it necessary to have root 
> logger configured always?
>  
> Although am still not able to generate multiple files based on each 
> application run. It just created application.log file and keeps on appending 
> the log of each run in the same file.
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to