Search code examples
javalogginglogback

How to set HTML encoding in HTMLLayout in logback?


By default logback only produces the following header for HTML log files:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
  <head>
    <title>Logback Log Messages</title>
<style  type="text/css">

</style>
</head>

But encoding here is not set. And some browsers default encoding to something they want like 'windows-1251' or 'ISO-8859-1' or 'ISO-8859-5'.

How do I add something like

<meta http-equiv="Content-Type" content="text/html; charset=utf-16">

to HTML header? Also since all strings in Java are UTF-16, shouldn't this be permanently set in logback source code?

Is there any way to do it via logback configuration file or should I create my own HTMLLayout descendant?


Solution

  • It appears from the javadocs that no such option exists, but check the source to be certain. Logback is still a moving target until 1.0.

    If you find it is not present, then raise a bug in the logback JIRA instance -- http://jira.qos.ch/secure/Dashboard.jspa - and ask for it, or submit a patch that adds the functionality.