如何在logback中的HTMLLayout中设置HTML编码?
默认情况下,logback 只为 HTML 日志文件生成以下标头:
<!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>
但此处未设置编码。有些浏览器默认编码为他们想要的东西,例如“windows-1251”或“ISO-8859-1”或“ISO-8859-5”。
如何
<meta http-equiv="Content-Type" content="text/html; charset=utf-16">
向 HTML 标头添加类似内容?另外,由于Java中的所有字符串都是UTF-16,所以这不应该在logback源代码中永久设置吗?
有没有办法通过 logback 配置文件来做到这一点,或者我应该创建自己的 HTMLLayout 后代?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你不能设置“head”标签,但你可以扩展“HTMLLayout”,例如:
如果你使用xml配置,更改“layout”标签,使用你的类
You couldn't set "head" tag,but you can extend "HTMLLayout",such example:
if you use xml configraution , change "layout" tag,use your class
从 javadoc 来看,似乎不存在这样的选项,但请检查来源以确定。在 1.0 之前,Logback 仍然是一个不断变化的目标。
如果您发现它不存在,请在 logback JIRA 实例中提出错误 - http:// jira.qos.ch/secure/Dashboard.jspa - 并请求它,或提交添加该功能的补丁。
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.