Skip to content

Harmonize Logback's console and file logging charset #46846

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

Closed
wants to merge 2 commits into from

Conversation

nosan
Copy link
Contributor

@nosan nosan commented Aug 15, 2025

See #44472

I wonder if DefaultLogbackConfiguration.java should be updated to use UTF-8 as well. If so, perhaps System.console().charset() should be used as the default for the console.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 15, 2025
@mhalbritter mhalbritter changed the title Switching Logback's file logging charset to UTF-8 Switch Logback's file logging charset to UTF-8 Aug 18, 2025
@mhalbritter mhalbritter added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 18, 2025
@mhalbritter mhalbritter added this to the 4.0.x milestone Aug 18, 2025
@mhalbritter
Copy link
Contributor

I wonder if DefaultLogbackConfiguration.java should be updated to use UTF-8 as well

I think so. Right now, DefaultLogbackConfiguration uses Charset.defaultCharset().name(), but defaults.xml uses UTF-8.

@nosan
Copy link
Contributor Author

nosan commented Aug 18, 2025

Just to be on the same page, should DefaultLogbackConfiguration be updated to use the same values as defaults.xml?

At the moment, defaults.xml has the following values:

  • ${CONSOLE_LOG_CHARSET:-${file.encoding:-UTF-8}}
  • ${FILE_LOG_CHARSET:-${file.encoding:-UTF-8}}

@mhalbritter
Copy link
Contributor

mhalbritter commented Aug 18, 2025

I'd use Console.charset() if that's available, otherwise the default charset. And UTF-8 for files.

That should align it with #44353 (comment)

Aligns the file charset between Log4j2 and Logback.

Prior to this commit, there was an inconsistency between the two:
Log4j2 used UTF-8, while Logback used Charset.defaultCharset(),
which is platform-dependent.

Signed-off-by: Dmytro Nosan <[email protected]>
@nosan
Copy link
Contributor Author

nosan commented Aug 18, 2025

Thanks, @mhalbritter
PR has been updated.

@snicoll snicoll self-assigned this Aug 18, 2025
@snicoll snicoll modified the milestones: 4.0.x, 4.0.0-M2 Aug 18, 2025
@nosan
Copy link
Contributor Author

nosan commented Aug 18, 2025

@snicoll
I am totally forgot to update DEFAULT_CHARSET = Charset.defaultCharset().name(); to UTF-8! Could you please update to UTF-8?

@nosan
Copy link
Contributor Author

nosan commented Aug 18, 2025

Tests work for me because UTF-8 is default locale on my laptop 🤦

@snicoll
Copy link
Member

snicoll commented Aug 18, 2025

@nosan I was reviewing but feel free to push a fix, I'll wait

Signed-off-by: Dmytro Nosan <[email protected]>
@nosan
Copy link
Contributor Author

nosan commented Aug 18, 2025

@snicoll
Fixed, FYI I did not squash commits.

@snicoll snicoll changed the title Switch Logback's file logging charset to UTF-8 Harmonize Logback's console and file logging charset Aug 18, 2025
snicoll pushed a commit that referenced this pull request Aug 18, 2025
This commit aligns the file charset between Log4j2 and Logback.

Prior to this commit, there was an inconsistency between the two: Log4j2
used UTF-8, while Logback used Charset.defaultCharset(), which is
platform-dependent.

See gh-46846

Signed-off-by: Dmytro Nosan <[email protected]>
@snicoll snicoll closed this in 9fed7f3 Aug 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants