我有一个log4j2.xml,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="DEBUG">
<Properties>
<Property name="log-path">E:/MLM/MyDomain/servers/MyAppSrv01/logs</Property>
</Properties>
<Appenders>
<RollingFile name="RollingFile" fileName="${log-path}/MLMServices.log" filePattern="${log-path}/MyServices-%d{yyyy-MM-dd}-%i.log" >
<PatternLayout>
<pattern>%d{dd/MMM/yyyy HH:mm:ss,SSS} [%t] [%-5level] - %c{1}: %m%n</pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="1 MB" />
</Policies>
<DefaultRolloverStrategy max="30"/>
</RollingFile>
</Appenders>
<Loggers>
<Logger name="root" level="debug" additivity="false">
<appender-ref ref="RollingFile" level="debug"/>
</Logger>
<Root level="debug" additivity="false">
<AppenderRef ref="RollingFile"/>
</Root>
</Loggers>
</Configuration>
这用于在Windows Server上部署在WebLogic 12.2.1上的应用程序。当我尝试记录这样的异常堆栈跟踪时:
} catch (Exception exception) {
logger.catching(exception);
}
或者像这样:
} catch (Exception exception) {
logger.fatal("", exception);
}
当我使用记事本查看时,日志文件中的结果行将如下所示:
14 / Mar / 2016 14:31:21,344 [[ACTIVE] ExecuteThread:&#39; 11&#39; for queue:&#39; weblogic.kernel.Default(自我调整)&#39;] - TestWS:catch weblogic.management.NoAccessRuntimeException:由于在SecurityConfigurationMBean中设置了ClearTextCredentialAccessEnabled属性,因此不允许以明文形式访问敏感属性。 Attr:CustomIdentityKeyStorePassPhrase,MBean name:com.bea:Name = MLMAppSrv01,Type = Server at weblogic.management.mbeanservers.internal.SecurityInterceptor.checkGetSecurity(SecurityInterceptor.java:590)~ [com.oracle.weblogic.management.mbeanservers.jar:12.2.1.0] at weblogic.management.mbeanservers.internal.SecurityInterceptor.getAttribute(SecurityInterceptor.java:293)〜[com.oracle.weblogic.management.mbeanservers.jar:12.2.1.0] at weblogic.management.jmx.mbeanserver.WLSMBeanServerInterceptorBase $ 17.run(WLSMBeanServerInterceptorBase.java:466)〜[com.bea.core.management.jmx.jar:12.2.1.0] at java.security.AccessController.doPrivileged(Native Method)〜[?:1.8.0_71] at weblogic.management.jmx.mbeanserver.WLSMBeanServerInterceptorBase.getAttribute(WLSMBeanServerInterceptorBase.java:464)〜[com.bea.core.management.jmx.jar:12.2.1.0] at weblogic.management.mbeanservers.internal.MBeanCICInterceptor.getAttribute(MBeanCICInterceptor.java:139)〜[com.oracle.weblogic.management.mbeanservers.jar:12.2.1.0] at weblogic.management.jmx.mbeanserver.WLSMBeanServerInterceptorBase $ 17.run(WLSMBeanServerInterceptorBase.java:466)〜[com.bea.core.management.jmx.jar:12.2.1.0] at java.security.AccessController.doPrivileged(Native Method)〜[?:1.8.0_71] at weblogic.management.jmx.mbeanserver.WLSMBeanServerInterceptorBase.getAttribute(WLSMBeanServerInterceptorBase.java:464)〜[com.bea.core.management.jmx.jar:12.2.1.0] at weblogic.management.mbeanservers.internal.PartitionJMXInterceptor.getAttribute(PartitionJMXInterceptor.java:303)〜[com.oracle.weblogic.management.mbeanservers.jar:12.2.1.0] at weblogic.management.jmx.mbeanserver.WLSMBeanServerInterceptorBase $ 17.run(WLSMBeanServerInterceptorBase.java:466)〜[com.bea.core.management.jmx.jar:12.2.1.0] at java.security.AccessController.doPrivileged(Native Method)〜[?:1.8.0_71] at weblogic.management.jmx.mbeanserver.WLSMBeanServerInterceptorBase.getAttribute(WLSMBeanServerInterceptorBase.java:464)〜[com.bea.core.management.jmx.jar:12.2.1.0] at weblogic.management.mbeanservers.internal.CallerPartitionContextInterceptor.getAttribute(CallerPartitionContextInterceptor.java:177)〜[com.oracle.weblogic.management.mbeanservers.jar:12.2.1.0] at weblogic.management.jmx.mbeanserver.WLSMBeanServer.getAttribute(WLSMBeanServer.java:283)〜[com.bea.core.management.jmx.jar:12.2.1.0] 在com.test.TestWS.webservicemethod4(TestWS.java:132)[_wl_cls_gen.jar:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)〜[?:1.8.0_71] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)〜[?:1.8.0_71] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)〜[?:1.8.0_71] 在java.lang.reflect.Method.invoke(Method.java:497)〜[?:1.8.0_71] 在org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory $ 1.invoke(ResourceMethodInvocationHandlerFactory.java:81)[org.glassfish.jersey.core.jersey-server.jar:?] 在org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher $ 1.run(AbstractJavaResourceMethodDispatcher.java:144)[org.glassfish.jersey.core.jersey-server.jar:?] 在org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161)[org.glassfish.jersey.core.jersey-server.jar:?] at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider $ ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:160)[org.glassfish.jersey.core.jersey-server.jar:?] 在org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99)[org.glassfish.jersey.core.jersey-server.jar:?] 在org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389)[org.glassfish.jersey.core.jersey-server.jar:?] 在org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347)[org.glassfish.jersey.core.jersey-server.jar:?] 在org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)[org.glassfish.jersey.core.jersey-server.jar:?] 在org.glassfish.jersey.server.ServerRuntime $ 2.run(ServerRuntime.java:309)[org.glassfish.jersey.core.jersey-server.jar:?] 在org.glassfish.jersey.internal.Errors $ 1.call(Errors.java:271)[org.glassfish.jersey.core.jersey-common.jar:?] 在org.glassfish.jersey.internal.Errors $ 1.call(Errors.java:267)[org.glassfish.jersey.core.jersey-common.jar:?] 在org.glassfish.jersey.internal.Errors.process(Errors.java:315)[org.glassfish.jersey.core.jersey-common.jar:?] 在org.glassfish.jersey.internal.Errors.process(Errors.java:297)[org.glassfish.jersey.core.jersey-common.jar:?] 在org.glassfish.jersey.internal.Errors.process(Errors.java:267)[org.glassfish.jersey.core.jersey-common.jar:?] 在org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)[org.glassfish.jersey.core.jersey-common.jar:?] 在org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:292)[org.glassfish.jersey.core.jersey-server.jar:?] 在org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154)[org.glassfish.jersey.core.jersey-server.jar:?] 在org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:460)[org.glassfish.jersey.containers.jersey-container-servlet-core.jar:?] 在org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:386)[org.glassfish.jersey.containers.jersey-container-servlet-core.jar:?] 在org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:334)[org.glassfish.jersey.containers.jersey-container-servlet-core.jar:?] 在org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:221)[org.glassfish.jersey.containers.jersey-container-servlet-core.jar:?] at weblogic.servlet.internal.StubSecurityHelper $ ServletServiceAction.run(StubSecurityHelper.java:286)[com.oracle.weblogic.servlet.jar:12.2.1.0] at weblogic.servlet.internal.StubSecurityHelper $ ServletServiceAction.run(StubSecurityHelper.java:260)[com.oracle.weblogic.servlet.jar:12.2.1.0] 在weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:137)[com.oracle.weblogic.servlet.jar:12.2.1.0] 在weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:350)[com.oracle.weblogic.servlet.jar:12.2.1.0] 在weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:247)[com.oracle.weblogic.servlet.jar:12.2.1.0] at weblogic.servlet.internal.WebAppServletContext $ ServletInvocationAction.wrapRun(WebAppServletContext.java:3650)[com.oracle.weblogic.servlet.jar:12.2.1.0] at weblogic.servlet.internal.WebAppServletContext $ ServletInvocationAction.run(WebAppServletContext.java:3620)[com.oracle.weblogic.servlet.jar:12.2.1.0] at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:326)[com.oracle.weblogic.security.subject.jar:12.2.1.0] at weblogic.security.service.SecurityManager.runAsForUserCode(SecurityManager.java:196)[com.oracle.weblogic.security.subject.jar:12.2.1.0] at weblogic.servlet.provider.WlsSecurityProvider.runAsForUserCode(WlsSecurityProvider.java:203)[com.oracle.weblogic.servlet.jar:12.2.1.0] 在weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:71)[com.oracle.weblogic.servlet.jar:12.2.1.0] 在weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2423)[com.oracle.weblogic.servlet.jar:12.2.1.0] at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2280)[com.oracle.weblogic.servlet.jar:12.2.1.0] at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2258)[com.oracle.weblogic.servlet.jar:12.2.1.0] at weblogic.servlet.internal.ServletRequestImpl.runInternal(ServletRequestImpl.java:1626)[com.oracle.weblogic.servlet.jar:12.2.1.0] 在weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1586)[com.oracle.weblogic.servlet.jar:12.2.1.0] at weblogic.servlet.provider.ContainerSupportProviderImpl $ WlsRequestExecutor.run(ContainerSupportProviderImpl.java:270)[com.oracle.weblogic.servlet.jar:12.2.1.0] at weblogic.invocation.ComponentInvocationContextManager._runAs(ComponentInvocationContextManager.java:348)[com.bea.core.utils.full.jar:12.2.1.0] at weblogic.invocation.ComponentInvocationContextManager.runAs(ComponentInvocationContextManager.java:333)[com.bea.core.utils.full.jar:12.2.1.0] at weblogic.work.LivePartitionUtility.doRunWorkUnderContext(LivePartitionUtility.java:54)[com.oracle.weblogic.work.jar:12.2.1.0] at weblogic.work.PartitionUtility.runWorkUnderContext(PartitionUtility.java:41)[com.bea.core.weblogic.workmanager.jar:12.2.1.0] at weblogic.work.SelfTuningWorkManagerImpl.runWorkUnderContext(SelfTuningWorkManagerImpl.java:617)[com.bea.core.weblogic.workmanager.jar:12.2.1.0] 在weblogic.work.ExecuteThread.execute(ExecuteThread.java:397)[com.bea.core.weblogic.workmanager.jar:12.2.1.0] at weblogic.work.ExecuteThread.run(ExecuteThread.java:346)[com.bea.core.weblogic.workmanager.jar:12.2.1.0] 14 / Mar / 2016 14:31:21,344 [[ACTIVE] ExecuteThread:&#39; 11&#39; for queue:&#39; weblogic.kernel.Default(自我调整)&#39;] - TestWS:webservicemethod4 1
这是因为它是Unix格式而不是Windows格式(缺少回车符)。
如何使堆栈跟踪的每一行以回车符和换行符结束&#34; \ r \ n&#34;这样我可以在记事本中查看它?我们在服务器上只有记事本,因此在服务器上查看异常堆栈跟踪可能非常困难。
感谢。
答案 0 :(得分:-1)
您需要启用ANSI转义序列:
Windows上的ANSI样式
ANSI转义序列在许多平台上本机支持,但在Windows上默认不是。要启用ANSI支持,只需将Jansi MVN and Jar Download jar添加到您的应用程序中,Log4j将在写入控制台时自动使用它。