zoukankan      html  css  js  c++  java
  • mybatis 日志的使用以及设计

    1、为什么要配置mybtis的logger?

    mybatis自己设计以及实现了org.apache.ibatis.logging.Log接口。

    Mybatis为了避免对第三方的日志包存在强依赖,内部的Log采用了代理模式。通过配置的方式,代理真实的日志对象

    如果没有配置log,mybatis会按照以下顺序尝试加载Log:SL4j->Common logging->log4j2->log4j->jdkLoging->noLogging

     1   static {
     2     tryImplementation(new Runnable() {
     3       @Override
     4       public void run() {
     5         useSlf4jLogging();
     6       }
     7     });
     8     tryImplementation(new Runnable() {
     9       @Override
    10       public void run() {
    11         useCommonsLogging();
    12       }
    13     });
    14     tryImplementation(new Runnable() {
    15       @Override
    16       public void run() {
    17         useLog4J2Logging();
    18       }
    19     });
    20     tryImplementation(new Runnable() {
    21       @Override
    22       public void run() {
    23         useLog4JLogging();
    24       }
    25     });
    26     tryImplementation(new Runnable() {
    27       @Override
    28       public void run() {
    29         useJdkLogging();
    30       }
    31     });
    32     tryImplementation(new Runnable() {
    33       @Override
    34       public void run() {
    35         useNoLogging();
    36       }
    37     });
    38   }

    加载具体Logger的方式:

    通过调用具体Logger的构造函数,反射出。

    private static void setImplementation(Class<? extends Log> implClass) {
        try {
          Constructor<? extends Log> candidate = implClass.getConstructor(String.class);
          Log log = candidate.newInstance(LogFactory.class.getName());
          if (log.isDebugEnabled()) {
            log.debug("Logging initialized using '" + implClass + "' adapter.");
          }
          logConstructor = candidate;
        } catch (Throwable t) {
          throw new LogException("Error setting Log implementation.  Cause: " + t, t);
        }
      }
  • 相关阅读:
    第3节:vue-router如何参数传递
    第2节:vue-router配置子路由
    Vue-router笔记 第1节:Vue-router入门
    vue-cli模版解读
    Vue-cli项目结构讲解
    vue-cli笔记
    实例属性
    实例方法-扩展器-生命zhou
    父子组件
    伪数组转为数组 Array.prototype.slice.call(arguments)
  • 原文地址:https://www.cnblogs.com/marioS/p/10392057.html
Copyright © 2011-2022 走看看