Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Close file before rotating in RollingFileLogWriter #433

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pm47
Copy link

@pm47 pm47 commented Feb 24, 2025

Otherwise a java.nio.file.FileSystemException will be raised, at least on Windows.

Otherwise a `java.nio.file.FileSystemException` will be raised, at least
on Windows.
rollLogs()
true
} else false
private fun shouldRollLogs(logFilePath: Path): Boolean {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the signature of this function because calling maybeRollLogs(fileSizeOrZero()) seemed cumbersome.

@@ -136,8 +134,8 @@ open class RollingFileLogWriter(
private suspend fun writer() {
val logFilePath = pathForLogIndex(0)

if (fileSystem.exists(logFilePath)) {
maybeRollLogs(fileSizeOrZero(logFilePath))
if (fileSystem.exists(logFilePath) && shouldRollLogs(logFilePath)) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT we should just do this:

Suggested change
if (fileSystem.exists(logFilePath) && shouldRollLogs(logFilePath)) {
if (shouldRollLogs(logFilePath)) {

because metadataOrNull() already handled the case where the file doesn't exist.

pm47 added a commit to ACINQ/phoenixd that referenced this pull request Feb 25, 2025
pm47 added a commit to ACINQ/phoenixd that referenced this pull request Feb 25, 2025
pm47 added a commit to ACINQ/phoenixd that referenced this pull request Feb 25, 2025
Initially the goal was to use Kermit's `RollingFileLogWriter`, but an issue was found during testing (see touchlab/Kermit#433) so we are using a local patched version in the meantime.

Logging can be configured with these two new config parameters:
- `--log-rotate-size` Log rotate size in MB (default 10 MB)
- `--log-rotate-max-files`: Maximum number of log files kept (default 5)
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant