我们最近已从Log4J切换到Logback。除了SyslogAppender中的堆栈跟踪外,日志记录似乎运行良好。它们的前缀就像剩余的日志消息一样。
有没有办法如何禁用此前缀并确保它们将像Log4J SyslogAppender一样打印?提前致谢。
当前行为:
Apr 02 12:31:08 host.name 2012-04-02T12:31:08.418+0200 ajp-bio-8009-exec-7 com.gooddata.exception.servlet.HttpExceptionTranslator ERROR: Processing client_request=/gdcwebapp/gdc/projects/FoodMartDemo/groups/everyone status=FAILED errorCode=gdc.usergroups.default_group_modification errorDescription="Attempt to modify default group (everyone)" exceptionId=abc37cf0-9c56-4e68-a4a7-2111ca823fd4 component=webapp request_id=cAWvICOaKVFF1VvI userId=1 projectId=FoodMartDemo nodeId=nodeOne nodeId=nodeOne, requestId=cAWvICOaKVFF1VvI, userId=1, projectId=FoodMartDemo
Apr 02 12:31:08 host.name #011at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Apr 02 12:31:08 host.name #011at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
Apr 02 12:31:08 host.name #011at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
Apr 02 12:31:08 host.name #011at java.lang.reflect.Method.invoke(Method.java:601)
Apr 02 12:31:08 host.name #011at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:212)
Apr 02 12:31:08 host.name #011at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
Apr 02 12:31:08 host.name #011at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
Apr 02 12:31:08 host.name #011at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
Apr 02 12:31:08 host.name #011at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
Apr 02 12:31:08 host.name #011at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
Apr 02 12:31:08 host.name #011at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900)
期望的行为:
Apr 02 12:31:08 host.name 2012-04-02T12:31:08.418+0200 ajp-bio-8009-exec-7 com.gooddata.exception.servlet.HttpExceptionTranslator ERROR: Processing client_request=/gdcwebapp/gdc/projects/FoodMartDemo/groups/everyone status=FAILED errorCode=gdc.usergroups.default_group_modification errorDescription="Attempt to modify default group (everyone)" exceptionId=abc37cf0-9c56-4e68-a4a7-2111ca823fd4 component=webapp request_id=cAWvICOaKVFF1VvI userId=1 projectId=FoodMartDemo nodeId=nodeOne nodeId=nodeOne, requestId=cAWvICOaKVFF1VvI, userId=1, projectId=FoodMartDemo
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:212)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900)
SyslogAppender的当前logback.xml:
<appender name="SYSLOG" class="ch.qos.logback.classic.net.SyslogAppender">
<facility>local2</facility>
<syslogHost>localhost</syslogHost>
<suffixPattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} %t %c %p: %m component=webapp request_id=%X{requestId} userId=%X{userId} projectId=%X{projectId} nodeId=%X{nodeId} %X%n</suffixPattern>
</appender>
答案 0 :(得分:7)
您可以通过将throwableExcluded参数设置为true并在后缀模式中指定异常来解决此问题。
<appender name="SYSLOG" class="ch.qos.logback.classic.net.SyslogAppender">
<syslogHost>localhost</syslogHost>
<facility>LOCAL7</facility>
<throwableExcluded>true</throwableExcluded>
<suffixPattern>%d{ISO8601} %p %t %c{0}.%M - %m%n%xException</suffixPattern>
</appender>
根据您使用的系统日志服务器,您可能需要关闭控制字符转义才能正确呈现文本。例如rsyslog v5的$EscapeControlCharactersOnReceive off
答案 1 :(得分:0)
在logback邮件列表(http://old.nabble.com/SyslogAppender-stacktrace-logging-prefix-td33555063.html)中提出了可能的解决方案,其中一个可能的解决方案是:http://jira.qos.ch/browse/LBCLASSIC-327
答案 2 :(得分:0)
Logback的Syslog Appender没有处理此权利。 你必须自己写。它可以基于原始的。基本上问题就在这里:
StringBuilder sb = new StringBuilder();
sb.append(stackTracePrefix).append(step);
sw.write(sb.toString().getBytes());
sw.flush();
当您正在刷新时,它会向syslog发送新消息。如果你想避免它,你只需要在整个堆栈之后进行刷新。