当前位置: 首页 > news >正文

南昌简单做网站上蔡网站建设

南昌简单做网站,上蔡网站建设,聊城网站建设哪家专业,哈尔滨网站推广服务log4j2官方例子在spring boot中报错而且还是用的是org.apache.commons.dbcp包我给改了一下使用org.apache.commons.dbcp2包1.log4j2.xml如下:methodgetDatabaseConnection /includeLocationtrueAsyncLogger 表示是异步插入.需要在pom.xml中插入…log4j2官方例子在spring boot中报错而且还是用的是org.apache.commons.dbcp包我给改了一下使用org.apache.commons.dbcp2包1.log4j2.xml如下:methodgetDatabaseConnection /includeLocationtrueAsyncLogger 表示是异步插入.需要在pom.xml中插入disruptor引用com.lmaxdisruptor3.4.12.创建LogConnectionFactory类:package com.malls.common.tool;import java.sql.Connection;import java.sql.DriverManager;import java.sql.SQLException;import java.util.concurrent.locks.Lock;import java.util.concurrent.locks.ReentrantLock;import javax.sql.DataSource;import org.apache.commons.dbcp2.ConnectionFactory;import org.apache.commons.dbcp2.DriverManagerConnectionFactory;import org.apache.commons.dbcp2.PoolableConnection;import org.apache.commons.dbcp2.PoolableConnectionFactory;import org.apache.commons.dbcp2.PoolingDataSource;import org.apache.commons.pool2.ObjectPool;import org.apache.commons.pool2.impl.GenericObjectPool;import com.malls.common.model.DBConfig;public class LogConnectionFactory {private static interface Singleton {final LogConnectionFactory INSTANCE new LogConnectionFactory();}private DataSource dataSource;private LogConnectionFactory() {}private void initDataSource() {try {//// First, well create a ConnectionFactory that the// pool will use to create Connections.// Well use the DriverManagerConnectionFactory,// using the connect string passed in the command line// arguments.DBConfig dbConfig ApplicationConfig.GetDbConfig(dblog);ConnectionFactory connectionFactory new DriverManagerConnectionFactory(dbConfig.getUrl(),dbConfig.getUserName(), dbConfig.getPassword());//// Next well create the PoolableConnectionFactory, which wraps// the real Connections created by the ConnectionFactory with// the classes that implement the pooling functionality.//PoolableConnectionFactory poolableConnectionFactory new PoolableConnectionFactory(connectionFactory,null);//// Now well need a ObjectPool that serves as the// actual pool of connections.//// Well use a GenericObjectPool instance, although// any ObjectPool implementation will suffice.//ObjectPool connectionPool new GenericObjectPool(poolableConnectionFactory);// Set the factorys pool property to the owning poolpoolableConnectionFactory.setPool(connectionPool);//// Finally, we create the PoolingDriver itself,// passing in the object pool we created.//dataSource new PoolingDataSource(connectionPool);} catch (Exception e) {// TODO 自动生成的 catch 块e.printStackTrace();dataSource null;}}int i 0;private static Lock lock new ReentrantLock();public static Connection getDatabaseConnection() throws SQLException {if (Singleton.INSTANCE.i 0) {//这儿如果第一次直接返回连接池的话会报错//因为PoolableConnectionFactory也使用了log4j记录日志//这儿是重点Singleton.INSTANCE.i;DBConfig dbConfig ApplicationConfig.GetDbConfig(dblog);return DriverManager.getConnection(dbConfig.getUrl(), dbConfig.getUserName(), dbConfig.getPassword());}if (Singleton.INSTANCE.dataSource null) {lock.lock();try {if (Singleton.INSTANCE.dataSource null) {Singleton.INSTANCE.initDataSource();}} finally {lock.unlock();}}return Singleton.INSTANCE.dataSource.getConnection();}}要注意注释的地方,第二次才返回连接池3.创建DBLog类:package com.malls.common.tool;import java.time.Duration;import java.time.LocalDateTime;import java.util.UUID;import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;import org.apache.logging.log4j.message.StructuredDataMessage;import org.springframework.web.context.request.RequestAttributes;import org.springframework.web.context.request.RequestContextHolder;import com.malls.common.model.RequestModel;public class DBLog {private static final Logger LOGGER LogManager.getLogger(AsyncDBLogger);public static void process(String logType, String content) {process(logType, content, );}public static void process(String logType, String content, String keyWord) {StructuredDataMessage msg getataMessage(logType, content, keyWord);addMsg(msg, logLevel, Process);LOGGER.info(msg);}public static void error(String logType, String content) {error(logType, content, );}public static void error(String logType, String content, String keyWord) {StructuredDataMessage msg getataMessage(logType, content, keyWord);addMsg(msg, logLevel, Error);LOGGER.error(msg);}public static void handle(String logType, String content) {handle(logType, content, );}public static void handle(String logType, String content, String keyWord) {StructuredDataMessage msg getataMessage(logType, content, keyWord);addMsg(msg, LogLevel, Handle);LOGGER.info(msg);}private static StructuredDataMessage getataMessage(String logType, String content, String keyWord) {String confirm UUID.randomUUID().toString().replace(-, );StructuredDataMessage msg new StructuredDataMessage(confirm, , transfer);RequestAttributes req RequestContextHolder.currentRequestAttributes();RequestModel requestModel null;if (req ! null) {requestModel (RequestModel) req.getAttribute(RequestModel, RequestAttributes.SCOPE_REQUEST);}if (requestModel null) {requestModel new RequestModel();}addMsg(msg, RequestKey, requestModel.getRequestKey());addMsg(msg, RequestUrl, requestModel.getRequestUrl());addMsg(msg, UserName, String.valueOf(requestModel.getCurrentUserId()));addMsg(msg, OrderNo, requestModel.getOrderNo());addMsg(msg, LogType, logType);addMsg(msg, Content, content);addMsg(msg, Keyword, keyWord);addMsg(msg, ClientIP, requestModel.getClientIP());long timeLong Duration.between(requestModel.getBeginRequestTime(), LocalDateTime.now()).toMillis();addMsg(msg, TimeLong, String.valueOf(timeLong));addMsg(msg, ServerDesc, 777);addMsg(msg, RequestServerIP, requestModel.getRequestServerIP());addMsg(msg, ServerIP, requestModel.getServerIP());addMsg(msg, CurrentApiRequestKey, requestModel.getCurrentApiRequestKey());addMsg(msg, LogTime, LocalDateTime.now().toString());return msg;}private static void addMsg(StructuredDataMessage msg, String key, String val) {if (val null) {msg.put(key, );} else {msg.put(key, val);}}}这样就可以了.
http://www.zqtcl.cn/news/537674/

相关文章:

  • 省住房城乡建设厅门户网站电子商务网站建设用什么软件
  • 怎么给自己的网站做模版企业网站开发外包
  • 哪家可以做网站东莞网站建设少儿托管
  • 最好的网站建设公司排名生物技术网站开发
  • 网站建设经验大总结不良人网页设计怎么做
  • 宁波市余姚建设局网站学做网站要代码
  • 戴尔公司网站开发的经营目标贵州省铜仁市城乡建设局网站
  • 商务网站建设简答题及答案网站备案 域名证书
  • 网站后门怎么去除贾汪城乡建设局网站
  • 烟台住房和城乡建设厅网站重庆网站界面设计
  • 企业网站推广服务协议html编程语言
  • 上海知名网站建设公司合肥建设云平台证书查询
  • 网站响应度西安哪家公司做的网站好
  • 广州市白云区网站建设维护wordpress如何匹配模板
  • 360网站导航公司地址怎么做seo 优化一般包括哪些内容
  • 龙岗高端建设网站建设南京旅游网页设计
  • 企业网站优化问题wordpress滑动
  • 亳州网站建设费用广东网站建设报价
  • ai生成作文网站驾校网站源码下载
  • icon图标素材下载网站郑州做定制网站的公司
  • 网站建设培训哪家好北京有几个区几个县
  • 县局网站建设招标最新网页游戏传奇
  • 咋么做进网站跳转加群代理记账公司如何寻找客户
  • 可以做pos机的网站app网站建设制作
  • 手机移动端网站影视摄影传媒公司
  • 做化工资讯的网站湖南省做网站的
  • 廊坊哪些公司做网站做网站域名是什么意思
  • 印刷网络商城网站建设上海那家公司做响应式网站建设
  • 四川省建设厅职称查询网站购物网站页面设计
  • 网站开发导航可以进不良网站的浏览器