logback-android
logback-android copied to clipboard
Daily rollover uses UTC instead of local time
Description
I configured daily rollover with TimeBasedRollingPolicy, according to example in wiki. It generally works, but rollover happens at UTC midnight, not local midnight. This may be confusing.
I know it's possible to specify time zone explicitly, but I suppose local time should be used by default, like it was in older versions (e.g. 1.1.1).
Maybe the same issue was reported at #198.
Steps to reproduce
- Checkout sample project
- Configure GMT+3 time zone on device or emulator
- Leave app running overnight
- log.txt contains events since 3:00, not 0:00
Environment
-
logback-android
version: 2.0.0 - Android version: 5.1, 6.0
- Platform: devices, emulator
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for reporting the issue.
Hey, bot, this issue is not stale! :)
Wait, why is this issue closed? Is it fixed?
Any updates on this? Im experiencing the same problem for quite a while.
I found a solution. use FileNamePattern: "%d{yyyy.MM.dd, " + TimeZone.getDefault().getID() + "}"
@enuoCM This only works when you programmatically set the pattern, right? I'm using a logback.xml which doesn't seem to evaluate "TimeZone.getDefault().getID()".
Commit https://github.com/tony19/logback-android/commit/446eb7ca7ba07f97712d79afbddd89bed8030c6c probably has caused this issue. It sets the timezone to "GMT" if no timezone is given instead of doing the simple "super()" call.
I found a solution. use FileNamePattern: "%d{yyyy.MM.dd, " + TimeZone.getDefault().getID() + "}"
The scheme worked. I tried it out.I am from China, so this is my use of software to translate Chinese into English, which may be difficult to read.Above this code directly into XML as if not, use a plus sign to the connection string, should be used in the Java code, rather than in XML, so I will call in the Java code TimeZone.getDefault().getID() to get the time zone id in my area, so that it can be hard code written in XML, so weakness is hard-coded, as I have the following code is only suitable for time zones in China mobile phone use:
<fileNamePattern>${EXT_DIR}/Android/data/${PACKAGE_NAME}/files/Documents/logs/log_%d{yyyy_MM_dd, Asia/Shanghai}.txt</fileNamePattern>
I don't know why the author didn't help us solve the problem when he saw it clearly. If anyone has a better plan, please also reply,thanks!