Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Default path being created wrongly #119

Closed
rtar opened this issue Nov 11, 2019 · 6 comments
Closed

Default path being created wrongly #119

rtar opened this issue Nov 11, 2019 · 6 comments

Comments

@rtar
Copy link

rtar commented Nov 11, 2019

Consider the following line of code:

FileWriter().path(LogPath.simple(directory = Paths.get("/some/path/to/logs")))

The approach defined in documentation:
https://github.com/outr/scribe/wiki/getting-started#logging-to-a-file

This will cause the two LogFile instances being created. One when FileWriter.apply is called, and another when path is changed.

The problem is that, it will also call logFile.flush() on the old instance causing, in some cases, for the path to be created.

The current workaround is to use new FileWriter directly. It does not seem to be a right way though.

Stack trace:

java.nio.file.AccessDeniedException: /opt/docker/logs
	at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:90)
	at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
	at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116)
	at java.base/sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:385)
	at java.base/java.nio.file.Files.createDirectory(Files.java:689)
	at java.base/java.nio.file.Files.createAndCheckIsDirectory(Files.java:796)
	at java.base/java.nio.file.Files.createDirectories(Files.java:782)
	at scribe.writer.file.LogFile.$anonfun$writer$1(LogFile.scala:65)
	at scala.Option.foreach(Option.scala:407)
	at scribe.writer.file.LogFile.writer$lzycompute(LogFile.scala:65)
	at scribe.writer.file.LogFile.writer(LogFile.scala:63)
	at scribe.writer.file.LogFile.flush(LogFile.scala:153)
	at scribe.writer.FileWriter.invoke(FileWriter.scala:19)
	at scribe.writer.FileWriter.withActions(FileWriter.scala:51)
	at scribe.writer.FileWriter.path(FileWriter.scala:55)
@darkfrog26
Copy link
Contributor

That's a good point. Let me look into this and get back to you.

@darkfrog26
Copy link
Contributor

I don't doubt what you're seeing, but looking at the code, the LogFile lazy initializes the writer, so it shouldn't create the file unless you attempt to write something to the FileWriter. Can you further clarify the conditions? If you feel comfortable digging into the source that would be appreciated as my time is incredibly limited right now.

@rtar
Copy link
Author

rtar commented Nov 11, 2019

@darkfrog26 I suspect the reason is the usage of scribe-slf4j18 library.

It might seem highly improbable that app writes something between call of FileWriter.apply and FileWriter.path, but I recall slf4j being able to replay the messages written to log before the system gets initialized first time.

Hence, it is likely, that if app wrote the stuff before the calls to scribe, it starts to write immediately before the reconfiguration is finished.

All these are a random guesses though... I guess I could make a small project to reproduce the effect, so I can share it.

@rtar
Copy link
Author

rtar commented Nov 11, 2019

I have created a minimal project to reproduce the issue. It seems that slf4j not needed, and it is not needed to even write anything to logs: https://github.com/rtar/scribe-119

@rtar
Copy link
Author

rtar commented Nov 11, 2019

@darkfrog26 I found the problem. It is the following line:

def flush(): Unit = if (active) {

The if (active) check is not there in 2.7.3 version (took it from documentation, did not check there is a newer release). In 2.7.10 version the check is there, and the bug cannot be reproduced. I suppose the issue can be closed now.

@rtar rtar closed this as completed Nov 11, 2019
@darkfrog26
Copy link
Contributor

Ah, that makes me feel better. I remember that being a problem before, but could have sworn I solved it....apparently I did. :) No worries man, I'm glad it's working now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants