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

自己做的网站被封了邢台规划局网站建设

自己做的网站被封了,邢台规划局网站建设,宣汉县建设局网站,网站怎么实现两种语言在系统中采用了spring boot logback#xff0b;slf4j的日志框架#xff0c;将系统日志记录到数据库。 相关参考来源#xff1a; 官方文档-DBAppender Logback输出日志到自定义MySQL数据库#xff08;重写DBAppender#xff09; logback日志框架中filter的使用 1. 添加依…在系统中采用了spring boot logbackslf4j的日志框架将系统日志记录到数据库。 相关参考来源 官方文档-DBAppender Logback输出日志到自定义MySQL数据库重写DBAppender logback日志框架中filter的使用 1. 添加依赖 从 logback 版本 1.2.8 开始DBAppender 不再随 logback-classic 一起提供所以需要单独引入 dependencygroupIdch.qos.logback.db/groupIdartifactIdlogback-classic-db/artifactIdversion1.2.11.1/version /dependency2. 自定义表结构: 可以根据实际情况增加或减少和修改字段 CREATE TABLE t_log_logback (id VARCHAR ( 64 ) NOT NULL COMMENT 主键,create_time VARCHAR ( 32 ) NOT NULL COMMENT 创建时间,message TEXT NOT NULL COMMENT 内容,level_string VARCHAR ( 254 ) NOT NULL COMMENT 日志等级TRACE,DEBUG,INFO,WARNING,ERROR,FATAL,logger_name VARCHAR ( 254 ) NOT NULL COMMENT 发出日志记录请求的记录器的名称,thread_name VARCHAR ( 254 ) COMMENT 线程名称,reference_flag INT ( 11 ) COMMENT MDC属性,caller_filename VARCHAR ( 254 ) NOT NULL COMMENT 发出日志记录请求的文件名,caller_class VARCHAR ( 254 ) NOT NULL COMMENT 发出日志记录请求的类,caller_method VARCHAR ( 254 ) NOT NULL COMMENT 发出日志记录请求的方法的名称,caller_line VARCHAR ( 4 ) NOT NULL COMMENT 发出日志记录请求的行号, PRIMARY KEY ( id ) USING BTREE ) ENGINE INNODB DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_bin ROW_FORMAT DYNAMIC COMMENT logback系统日志记录表;3. 自定义追加器DbLogbackAppender import ch.qos.logback.classic.spi.CallerData; import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.core.db.DBAppenderBase;import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.format.DateTimeFormatter;/*** p* 自定义DB日志追加器参考实现类 {link ch.qos.logback.classic.db.DBAppender}* 参考来源https://blog.csdn.net/qq_20914913/article/details/92830914* /p*/ public class DbLogbackAppender extends DBAppenderBaseILoggingEvent {private String insertSQL;private static final Method GET_GENERATED_KEYS_METHOD;// 对应于数据库字段的插入数据序号private static final int ID_INDEX 1;private static final int CREATE_TIME_INDEX 2;private static final int MESSAGE_INDEX 3;private static final int LEVEL_STRING_INDEX 4;private static final int LOGGER_NAME_INDEX 5;private static final int THREAD_NAME_INDEX 6;private static final int REFERENCE_FLAG_INDEX 7;private static final int CALLER_FILENAME_INDEX 8;private static final int CALLER_CLASS_INDEX 9;private static final int CALLER_METHOD_INDEX 10;private static final int CALLER_LINE_INDEX 11;private static final StackTraceElement EMPTY_CALLER_DATA CallerData.naInstance();// 处理主键的自动生成这里我们使用手工生成因此下面代码可忽略static {// PreparedStatement.getGeneratedKeys() method was added in JDK 1.4Method getGeneratedKeysMethod;try {// thegetGeneratedKeysMethod PreparedStatement.class.getMethod(getGeneratedKeys, (Class[]) null);} catch (Exception ex) {getGeneratedKeysMethod null;}GET_GENERATED_KEYS_METHOD getGeneratedKeysMethod;}Overridepublic void start() {insertSQL buildInsertSQL();cnxSupportsBatchUpdates connectionSource.supportsBatchUpdates();// super.start();super.started true;}// 核心代码构建插入语句并对应数据库字段private static String buildInsertSQL() {return INSERT INTO t_log_logback (id, create_time, message, level_string, logger_name, thread_name, reference_flag, caller_filename, caller_class, caller_method, caller_line) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);}// 管理每个字段插入的数据private void bindLoggingEventWithInsertStatement(PreparedStatement stmt, ILoggingEvent event) throws SQLException {// TODO 手工处理ID的生成stmt.setString(ID_INDEX, IdUtils.simpleUUID());stmt.setString(CREATE_TIME_INDEX, LocalDateTime.ofInstant(Instant.ofEpochMilli(event.getTimeStamp()),ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern(yyyy-MM-dd HH:mm:ss)));stmt.setString(MESSAGE_INDEX, event.getFormattedMessage());stmt.setString(LEVEL_STRING_INDEX, event.getLevel().toString());stmt.setString(LOGGER_NAME_INDEX, event.getLoggerName());stmt.setString(THREAD_NAME_INDEX, event.getThreadName());}// 管理每个字段插入的数据private void bindCallerDataWithPreparedStatement(PreparedStatement stmt, StackTraceElement[] callerDataArray) throws SQLException {StackTraceElement caller extractFirstCaller(callerDataArray);stmt.setInt(REFERENCE_FLAG_INDEX, 0);stmt.setString(CALLER_FILENAME_INDEX, caller.getFileName());stmt.setString(CALLER_CLASS_INDEX, caller.getClassName());stmt.setString(CALLER_METHOD_INDEX, caller.getMethodName());stmt.setString(CALLER_LINE_INDEX, Integer.toString(caller.getLineNumber()));}// 核心方法插入具体日志数据Overrideprotected void subAppend(ILoggingEvent event, Connection connection, PreparedStatement insertStatement) throws Throwable {bindLoggingEventWithInsertStatement(insertStatement, event);// This is expensive... should we do it every time?bindCallerDataWithPreparedStatement(insertStatement, event.getCallerData());int updateCount insertStatement.executeUpdate();if (updateCount ! 1) {addWarn(Failed to insert loggingEvent);}}private StackTraceElement extractFirstCaller(StackTraceElement[] callerDataArray) {StackTraceElement caller EMPTY_CALLER_DATA;if (hasAtLeastOneNonNullElement(callerDataArray))caller callerDataArray[0];return caller;}private boolean hasAtLeastOneNonNullElement(StackTraceElement[] callerDataArray) {return callerDataArray ! null callerDataArray.length 0 callerDataArray[0] ! null;}Overrideprotected Method getGeneratedKeysMethod() {return GET_GENERATED_KEYS_METHOD;}Overrideprotected String getInsertSQL() {return insertSQL;}protected void secondarySubAppend(ILoggingEvent event, Connection connection, long eventId) throws Throwable {}Overrideprotected long selectEventId(PreparedStatement insertStatement, Connection connection) throws SQLException, InvocationTargetException {return 0;} } 4. logback-spring.xml配置关联 添加自定义的追加器DbLogbackAppender ?xml version1.0 encodingUTF-8? configuration debugfalse!-- 获取springboot中的数据库配置 --springProperty scopecontext namedriverClassName sourcespring.datasource.master.driverClassName defaultValuedriverClassName/springProperty scopecontext nameurl sourcespring.datasource.master.url defaultValueurl/springProperty scopecontext nameusername sourcespring.datasource.master.username defaultValueusername/springProperty scopecontext nameencryptPassword sourcespring.datasource.master.encryptPassword defaultValueencryptPassword/!-- 添加自定义DbLogbackAppender --appender nameDB classcom.xxx.DbLogbackAppenderconnectionSource classch.qos.logback.core.db.DriverManagerConnectionSourcedriverClass${driverClassName}/driverClassurl${url}/urluser${username}/userpassword${password}/password/connectionSource!--临界值过滤。只记录指定级别以及高于该级别的日志--filter classch.qos.logback.classic.filter.ThresholdFilterlevelWARN/level/filter/appenderroot levelDEBUGEappender-ref refDB //root /configuration到这里就配置完成了重启系统访问日志会将warn级别以上的日志记录到数据库表。 由于数据源是使用logback的LogbackConnectionSource如果要自定义数据源请往下看 5.自定义数据源 创建类LogbackConnectionSource.java继承ConnectionSourceBase import ch.qos.logback.core.db.ConnectionSourceBase;import java.sql.Connection; import java.sql.SQLException;/*** p* 获取数据库连接用于logback并提供DbLogbackAppender使用* 参考类ch.qos.logback.core.db.DriverManagerConnectionSource* /p*/ public class LogbackConnectionSource extends ConnectionSourceBase {public Connection getConnection() {获取数据库连接Connection connection null;// 自行构建连接// ...return connection;} }修改logback-spring.xml配置为如下 !-- 添加自定义DbLogbackAppender --appender nameDB classcom.xxx.DbLogbackAppender!-- 添加自定义的数据源 --connectionSource classcom.xxx.LogbackConnectionSource!-- driverClass${driverClassName}/driverClassurl${url}/urluser${username}/userpassword${password}/password--/connectionSource!--临界值过滤。只记录指定级别以及高于该级别的日志--filter classch.qos.logback.classic.filter.ThresholdFilterlevelWARN/level/filter/appender
http://www.w-s-a.com/news/582120/

相关文章:

  • 网站建设项目合同wordpress主题没法用
  • 个旧市哪里有做网站wordpress内页php页面
  • 程序员接活的平台网站互联网平台建设方案
  • 网站安全建设模板深圳企业管理咨询公司
  • 做网站 还是淘宝店wordpress分类链接后加
  • wordpress腾讯云 COSseo内容优化心得
  • 特价旅游机票网站建设i营销
  • 如何成立网站深圳创业项目
  • 建设商业网站惠州网站建设推荐乐云seo
  • 如何申请免费域名做网站免费推广神器
  • 自媒体人专用网站安岳网站建设
  • 特乐网站建设做网站推广要多少钱
  • 山东省建设安全生产协会网站义乌跨境电商公司前十名
  • 做网站优化就是发文章吗起飞页自助建站平台的特点
  • 做网站还是做app好慈溪机械加工网
  • 上传下载文件网站开发的php源码腾讯企点
  • 给分管领导网站建设情况汇报怎么写网络运营的岗位职责及任职要求
  • 电线电缆技术支持中山网站建设广告设计培训学校有哪些
  • 如何禁止通过ip访问网站wordpress无法调用主题布局和图片
  • 江西建设工程信息网站重庆网站推广大全
  • 南浔区住房城乡建设局网站网页设计基础学什么
  • 萧山做网站的企业网站建设 西安
  • 江西省城乡建设厅网站百度站长资源平台
  • 本地搭建linux服务器做网站免费查企业信息查询
  • 电商网站建设与运营网上购物哪个网站最好
  • 做app做网站从何学起网站设计需要什么证
  • 设计网站最重要的是要有良好的短网址还原
  • 大连建设银行招聘网站做seo是要先有网站吗
  • 中山做网站的wordpress建站教程百科
  • 湛江专业网站制作做网站需要工具