log4j 源码解析_Log4j源码解析--Appender接口解析

1 String securityPrincipalName;2 String securityCredentials;3 String initialContextFactoryName;4 String urlPkgPrefixes;5 String providerURL;6 String topicBindingName;7 String tcfBindingName;8 String userName;9 String password;10 booleanlocationInfo;11 12 TopicConnection topicConnection;13 TopicSession topicSession;14 TopicPublisher topicPublisher;15 16 publicvoidactivateOptions() {17 TopicConnectionFactory topicConnectionFactory;18 try{19 Context jndi;20 LogLog.debug("Getting initial context.");21 if(initialContextFactoryName!=null) {22 Properties env=newProperties();23 env.put(Context.INITIAL_CONTEXT_FACTORY,24 initialContextFactoryName);25 if(providerURL!=null) {26 env.put(Context.PROVIDER_URL, providerURL);27 }else{28 LogLog.warn("You have set InitialContextFactoryName option but not the"29 +"ProviderURL. This is likely to cause problems.");30 }31 if(urlPkgPrefixes!=null) {32 env.put(Context.URL_PKG_PREFIXES, urlPkgPrefixes);33 }34 if(securityPrincipalName!=null) {35 env.put(Context.SECURITY_PRINCIPAL, securityPrincipalName);36 if(securityCredentials!=null) {37 env.put(Context.SECURITY_CREDENTIALS,38 securityCredentials);39 }else{40 LogLog.warn("You have set SecurityPrincipalName option but not the"41 +"SecurityCredentials. This is likely to cause problems.");42 }43 }44 jndi=newInitialContext(env);45 }else{46 jndi=newInitialContext();47 }48 LogLog.debug("Looking up ["+tcfBindingName+"]");49 topicConnectionFactory=(TopicConnectionFactory) lookup(jndi,50 tcfBindingName);51 LogLog.debug("About to create TopicConnection.");52 if(userName!=null) {53 topicConnection=topicConnectionFactory.createTopicConnection(54 userName, password);55 }else{56 topicConnection=topicConnectionFactory57 .createTopicConnection();58 }59 LogLog.debug("Creating TopicSession, non-transactional,"60 +"in AUTO_ACKNOWLEDGE mode.");61 topicSession=topicConnection.createTopicSession(false,62 Session.AUTO_ACKNOWLEDGE);63 LogLog.debug("Looking up topic name ["+topicBindingName+"].");64 Topic topic=(Topic) lookup(jndi, topicBindingName);65 LogLog.debug("Creating TopicPublisher.");66 topicPublisher=topicSession.createPublisher(topic);67 LogLog.debug("Starting TopicConnection.");68 topicConnection.start();69 jndi.close();70 }catch(JMSException e) {71 errorHandler.error(72 "Error while activating options for appender named ["73 +name+"].", e, ErrorCode.GENERIC_FAILURE);74 }catch(NamingException e) {75 errorHandler.error(76 "Error while activating options for appender named ["77 +name+"].", e, ErrorCode.GENERIC_FAILURE);78 }catch(RuntimeException e) {79 errorHandler.error(80 "Error while activating options for appender named ["81 +name+"].", e, ErrorCode.GENERIC_FAILURE);82 }83 }84 85 publicvoidappend(LoggingEvent event) {86 if(!checkEntryConditions()) {87 return;88 }89 try{90 ObjectMessage msg=topicSession.createObjectMessage();91 if(locationInfo) {92 event.getLocationInformation();93 }94 msg.setObject(event);95 topicPublisher.publish(msg);96 }catch(JMSException e) {97 errorHandler.error("Could not publish message in JMSAppender ["98 +name+"].", e, ErrorCode.GENERIC_FAILURE);99 }catch(RuntimeException e) {100 errorHandler.error("Could not publish message in JMSAppender ["101 +name+"].", e, ErrorCode.GENERIC_FAILURE);102 }103 }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值