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

Header not written for RollingFileAppender since version 1.5.7 #857

Open
balrok opened this issue Sep 9, 2024 · 0 comments
Open

Header not written for RollingFileAppender since version 1.5.7 #857

balrok opened this issue Sep 9, 2024 · 0 comments

Comments

@balrok
Copy link

balrok commented Sep 9, 2024

In 85bed93 the encoderInit()-method was moved from setOutputStream() to start(). The RollingFileAppender will not call start() once a new file is rolled. Therefore these new files won't get a header anymore.
We are using logback to create a binary file which requires a header. Due to this change, only the first file gets the header (because start() calls encoderInit()). But every other file created by RollingFileAppender is without the header.

As a hotfix it works to override the setOutputStream-method with:

public void setOutputStream(final OutputStream outputStream) {
	super.setOutputStream(outputStream);
	if (isStarted()) {
		try {
			getOutputStream().write(getEncoder().headerBytes());
		} catch (final IOException e) {
			addWarn("Konnte etem-Header nicht schreiben. " + e.getMessage());
		}
	}
}

The isStarted()-check is needed to avoid, that the header is written twice in the beginning.

balrok added a commit to balrok/logback that referenced this issue Sep 18, 2024
this fixes issue qos-ch#857

`encoderInit` will write the header once the `OutputStreamAppender` is
started. Since the outputStream is set before starting, the other
`encoderInit` inside the `start`-method is still needed.
balrok added a commit to balrok/logback that referenced this issue Sep 18, 2024
this fixes issue qos-ch#857

`encoderInit` will write the header once the `OutputStreamAppender` is
started. Since the outputStream is set before starting, the other
`encoderInit` inside the `start`-method is still needed.

Signed-off-by: Carl Mai <[email protected]>
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

1 participant