This is parameters below,which are using the log4j2 library.
status=error
name=PropertiesConfig
property.filename=C:\\logs\\sms.log
filters=threshold
filter.threshold.type=ThresholdFilter
filter.threshold.level=all
appenders=rolling
appender.rolling.type=RollingFile
appender.rolling.name=RollingFile
appender.rolling.fileName=${filename}
appender.rolling.filePattern=C:\\logs\\sms-%d{MM-dd-yy-HH-mm-ss}-%i.log
appender.rolling.layout.type=PatternLayout
appender.rolling.layout.pattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %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.policies.size.type=SizeBasedTriggeringPolicy
appender.rolling.policies.size.size=10MB
appender.rolling.strategy.type=DefaultRolloverStrategy
appender.rolling.strategy.max=20
loggers=rolling
logger.rolling.name=com.company.Main
logger.rolling.level=all
logger.rolling.additivity=true
logger.rolling.appenderRef.rolling.ref=RollingFile
When I run the project for the first time, it creates a folder named logs and creates a .txt file in it, and there are logging messages you know in it.Suppose our requestes and responces are written to the file for the first time created. Then we terminate and restart our project on the same day.
But when I end the project and restart it, it creates a new .txt file on the same day. But I don't want it to create a new .txt file when I finalize the project I need on the same day.When we restart our project on the same day, I want our logging messages to be written to the same file and I want it to create a new file every time we switch to a new day
. I need help with what to change or add from the above parameters.
CodePudding user response:
The issue is with appender.rolling.filePattern=C:\\logs\\sms-%d{MM-dd-yy-HH-mm-ss}-%i.log
.
The pattern you gave has HH-mm-sss
in it . So when you restart the service/server again, a new file is created for that time frame.
If you want to write to one file per day, remove HH-mm-ss
from filePattern
and try.
Like this appender.rolling.filePattern=C:\\logs\\sms-%d{MM-dd-yy}-%i.log
.