log4j设置日志级别

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010609345/article/details/50547954

前几天写了一个ifm_tt_sheet项目,从IFM向铁塔那边发送故障单,可是weblogic自带的jar包webservice中的某个包和我导入的jar包saaj.jar包路径内容完全一致,导致axis.jar一直抛空指针,查了这么多资料实在没有办法,找叶师傅帮忙,叶师傅说这个问题是axis抛的他写的这么多项目也是这样不用管。我想了想也实在没有招,大的环境变量不能动,配置weblogic.xml让提前加载导入的包又不行。就这样吧,虽然有点绝望,还是期望自己在看完一本webservice的书之后有所改变,因为空指针弄得log日志庞大,一分钟就达到4,5M的量,就想着把log的级别设置更高一极。
1、修改log4j.properties,其中若级别为info那么debug的异常将不在输出到日志上,只打印比info大的级别如(INFO 、 WARN 、 ERROR、 FATAL)

#DEBUG < INFO < WARN < ERROR < FATAL
log4j.rootLogger=INFO, A1, stdout
#log4j.rootLogger=DEBUG, A1, stdout 这是原先的配置

log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A1.Encoding=UTF-8
log4j.appender.A1.File=e\:/log_tt_sheet/ifmttsheet.log
log4j.appender.A1.DatePattern=yyyy-MM-dd
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern= [%-5p][%d{HH:mm:ss.SSS}]:%x %l - %m%n

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern= [%-5p][%d{HH:mm:ss.SSS}]:%x %l - %m%n

这样一来,日志就简单多了,只打印发出去的xml和接收的xml。

关于webservice客户端报的空指针是:
差不多都是这样,头痛。把日志级别上升一个等级也只是掩耳盗铃罢了。不过这事叶师傅知道。

[DEBUG][17:46:34.531]: org.apache.axis.client.Call.getParamList(Call.java:2045) - operation.getNumParams()=1
[DEBUG][17:46:34.546]: org.apache.axis.client.Call.getParamList(Call.java:2068) - getParamList number of params: 1
[DEBUG][17:46:34.578]: org.apache.axis.utils.XMLUtils.releaseDocumentBuilder(XMLUtils.java:254) - Failed to set EntityResolver to null on DocumentBuilder
java.lang.NullPointerException
    at weblogic.xml.jaxp.ChainingEntityResolver.popEntityResolver(ChainingEntityResolver.java:75)
    at weblogic.xml.jaxp.RegistryDocumentBuilder.setEntityResolver(RegistryDocumentBuilder.java:179)
    at org.apache.axis.utils.XMLUtils.releaseDocumentBuilder(XMLUtils.java:252)
    at org.apache.axis.utils.XMLUtils.newDocument(XMLUtils.java:342)
    at org.apache.axis.message.SOAPDocumentImpl.<init>(SOAPDocumentImpl.java:70)
    at org.apache.axis.message.MessageElement.getOwnerDocument(MessageElement.java:2142)
    at org.apache.axis.message.MessageElement.addTextNode(MessageElement.java:1388)
    at org.apache.axis.message.RPCParam.addTextNode(RPCParam.java:249)
    at org.apache.axis.message.RPCParam.<init>(RPCParam.java:84)
    at org.apache.axis.message.RPCParam.<init>(RPCParam.java:95)
    at org.apache.axis.client.Call.getParamList(Call.java:2087)
    at org.apache.axis.client.Call.invoke(Call.java:2364)
    at org.apache.axis.client.Call.invoke(Call.java:1812)
    at com.lansoft.http.services.SaAlarmService.SaAlarmServiceSoapBindingStub.notifyFaultOver(SaAlarmServiceSoapBindingStub.java:187)
    at com.lansoft.servlet.CreateXml.run(CreateXml.java:111)
    at java.lang.Thread.run(Thread.java:595)
[DEBUG][17:46:34.640]: org.apache.axis.client.Call.invoke(Call.java:2405) - Enter: Call::invoke(RPCElement)
[DEBUG][17:46:34.687]: org.apache.axis.i18n.ProjectResourceBundle.handleGetObject(ProjectResourceBundle.java:72) - org.apache.axis.i18n.resource::handleGetObject(attachEnabled)
[DEBUG][17:46:34.687]: org.apache.axis.Message.isAttachmentSupportEnabled(Message.java:289) - Attachment support is enabled?  true
[DEBUG][17:46:34.718]: org.apache.axis.SOAPPart.<init>(SOAPPart.java:182) - Enter: SOAPPart ctor(FORM_SOAPENVELOPE)
[DEBUG][17:46:34.718]: org.apache.axis.i18n.ProjectResourceBundle.handleGetObject(ProjectResourceBundle.java:72) - org.apache.axis.i18n.resource::handleGetObject(setMsgForm)
[DEBUG][17:46:34.734]: org.apache.axis.SOAPPart.setCurrentForm(SOAPPart.java:374) - Setting current message form to: FORM_SOAPENVELOPE (currentMessage is now org.apache.axis.message.SOAPEnvelope)
[DEBUG][17:46:34.734]: org.apache.axis.SOAPPart.<init>(SOAPPart.java:188) - Exit: SOAPPart ctor()
[DEBUG][17:46:34.734]: org.apache.axis.i18n.ProjectResourceBundle.handleGetObject(ProjectResourceBundle.java:72) - org.apache.axis.i18n.resource::handleGetObject(addBody00)
[DEBUG][17:46:34.750]: org.apache.axis.message.SOAPBody.addBodyElement(SOAPBody.java:168) - Adding body element to message...
[DEBUG][17:46:34.750]: org.apache.axis.client.Call.invoke(Call.java:2638) - Enter: Call::invoke()
[DEBUG][17:46:34.750]: org.apache.axis.MessageContext.setTargetService(MessageContext.java:749) - MessageContext: setTargetService(SaAlarmService)
[DEBUG][17:46:34.765]: org.apache.axis.i18n.ProjectResourceBundle.handleGetObject(ProjectResourceBundle.java:72) - org.apache.axis.i18n.resource::handleGetObject(noService10)
[DEBUG][17:46:34.781]: org.apache.axis.ConfigurationException.logException(ConfigurationException.java:110) - Exception: 
org.apache.axis.ConfigurationException: No service named SaAlarmService is available
org.apache.axis.ConfigurationException: No service named SaAlarmService is available
    at org.apache.axis.configuration.FileProvider.getService(FileProvider.java:233)
    at org.apache.axis.AxisEngine.getService(AxisEngine.java:311)
    at org.apache.axis.MessageContext.setTargetService(MessageContext.java:756)
    at org.apache.axis.client.Call.invoke(Call.java:2690)
    at org.apache.axis.client.Call.invoke(Call.java:2443)
    at org.apache.axis.client.Call.invoke(Call.java:2366)
    at org.apache.axis.client.Call.invoke(Call.java:1812)
    at com.lansoft.http.services.SaAlarmService.SaAlarmServiceSoapBindingStub.notifyFaultOver(SaAlarmServiceSoapBindingStub.java:187)
    at com.lansoft.servlet.CreateXml.run(CreateXml.java:111)
    at java.lang.Thread.run(Thread.java:595)

    at org.apache.axis.configuration.FileProvider.getService(FileProvider.java:233)
    at org.apache.axis.AxisEngine.getService(AxisEngine.java:311)
    at org.apache.axis.MessageContext.setTargetService(MessageContext.java:756)
    at org.apache.axis.client.Call.invoke(Call.java:2690)
    at org.apache.axis.client.Call.invoke(Call.java:2443)
    at org.apache.axis.client.Call.invoke(Call.java:2366)
    at org.apache.axis.client.Call.invoke(Call.java:1812)
    at com.lansoft.http.services.SaAlarmService.SaAlarmServiceSoapBindingStub.notifyFaultOver(SaAlarmServiceSoapBindingStub.java:187)
    at com.lansoft.servlet.CreateXml.run(CreateXml.java:111)
    at java.lang.Thread.run(Thread.java:595)
[DEBUG][17:46:34.828]: org.apache.axis.MessageContext.setService(MessageContext.java:793) - MessageContext: setServiceHandler(null)
[DEBUG][17:46:34.828]: org.apache.axis.i18n.ProjectResourceBundle.handleGetObject(ProjectResourceBundle.java:72) - org.apache.axis.i18n.resource::handleGetObject(targetService)
[DEBUG][17:46:34.828]: org.apache.axis.client.Call.invoke(Call.java:2715) - Target service:  SaAlarmService
[DEBUG][17:46:34.828]: org.apache.axis.MessageContext.setTargetService(MessageContext.java:749) - MessageContext: setTargetService()
[DEBUG][17:46:34.843]: org.apache.axis.i18n.ProjectResourceBundle.handleGetObject(ProjectResourceBundle.java:72) - org.apache.axis.i18n.resource::handleGetObject(noService10)
[DEBUG][17:46:34.843]: org.apache.axis.ConfigurationException.logException(ConfigurationException.java:110) - Exception: 
org.apache.axis.ConfigurationException: No service named  is available
org.apache.axis.ConfigurationException: No service named  is available
    at org.apache.axis.configuration.FileProvider.getService(FileProvider.java:233)
    at org.apache.axis.AxisEngine.getService(AxisEngine.java:311)
    at org.apache.axis.MessageContext.setTargetService(MessageContext.java:756)
    at org.apache.axis.transport.http.HTTPTransport.setupMessageContextImpl(HTTPTransport.java:89)
    at org.apache.axis.client.Transport.setupMessageContext(Transport.java:46)
    at org.apache.axis.client.Call.invoke(Call.java:2738)
    at org.apache.axis.client.Call.invoke(Call.java:2443)
    at org.apache.axis.client.Call.invoke(Call.java:2366)
    at org.apache.axis.client.Call.invoke(Call.java:1812)
    at com.lansoft.http.services.SaAlarmService.SaAlarmServiceSoapBindingStub.notifyFaultOver(SaAlarmServiceSoapBindingStub.java:187)
    at com.lansoft.servlet.CreateXml.run(CreateXml.java:111)
    at java.lang.Thread.run(Thread.java:595)

    at org.apache.axis.configuration.FileProvider.getService(FileProvider.java:233)
    at org.apache.axis.AxisEngine.getService(AxisEngine.java:311)
    at org.apache.axis.MessageContext.setTargetService(MessageContext.java:756)
    at org.apache.axis.transport.http.HTTPTransport.setupMessageContextImpl(HTTPTransport.java:89)
    at org.apache.axis.client.Transport.setupMessageContext(Transport.java:46)
    at org.apache.axis.client.Call.invoke(Call.java:2738)
    at org.apache.axis.client.Call.invoke(Call.java:2443)
    at org.apache.axis.client.Call.invoke(Call.java:2366)
    at org.apache.axis.client.Call.invoke(Call.java:1812)
    at com.lansoft.http.services.SaAlarmService.SaAlarmServiceSoapBindingStub.notifyFaultOver(SaAlarmServiceSoapBindingStub.java:187)
    at com.lansoft.servlet.CreateXml.run(CreateXml.java:111)
阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页