• 【logback】认识logback


    一. Reference: http://www.cnblogs.com/yongze103/archive/2012/05/05/2484753.html

    1. Logback为取代log4j而生,logback当前分为三个模块:logback-core,logback-classic,logback-access. Simple Log Facade , slf4j.

    2. Logback的核心对象:Logger, Appender, Layout,Logback主要建立于Logger, Appender 和Layout这三个类之上的。

      Logger: 日志的记录器,把他关联到对应的context上后,主要用于存放日志对象,也可以定义日志类型,级别。Logger对象一般多定义为静态常量。

        Appender:用于指定日志输出的目的地,目的地可以是控制台、文件、远程套接字服务器、mysql等。

          Layout:负责把事件转换成字符串,格式化的日志信息的输出。具体的Layout通配符,可以直接查看帮助文档。

    3. Level有效级别

      Logger可以被分配级别。级别包括:trace, debug, info, warn和error, 定义于ch.qos.logback.classic.Level类。

    4. 三值逻辑

      Logback的过滤器基于三值逻辑(ternary logic),允许把他们组装或成链,从而组成任意的复合过滤策略。过滤器的返回值有三种:

      deny:那么记录时间立即被抛弃,不再经过剩余过滤器;

      neutral:那么有序列表里的下一个过滤器会接着处理记录事件;

      accept:那么记录事件会被立即处理,不再经过剩余过滤器。

    5. Filter过滤器

      Logback-classic提供两种类型的过滤器:常规过滤器和TuroboFilter过滤器。logback整体流程:logger产生日志信息,layout修饰这条msg的显示格式,filter过滤显示的内容,appender具体的显示,即保存这日志信息的地方。

    二. reference: logback.qos.ch/manual

    1. An appender is a class that can be seen as an output destination. Appenders exist for many different destination including the console, files, syslog, tcp sockets, jms and many more. Users can also easily create their own Appenders as appropriate for their specific situation.

    2. core, classic, access

    classic extends core, implements the SLF4J API.

    access integrates with Servlet containers to provide HTTP-access log functionality.

    3. Every single logger is attached to a LoggerContext which is responsible for manufacturing loggers as well as arranging them in a tree like hierarchy.

    4. The root logger resides at the top of the logger hierarchy.

    5. To ensure that all loggers can eventually inherit a level, the root logger always has an assigned level. By default, this level is DEBUG.

    6. Parameterized logging

      6.1

      logger.debug("Entry number: " + i + " is " + String.valueOf(entry[i]));

      如果没有做判断,这logger中的字符串拼接会执行,但是当获取entry中第i个字符,并将其转换为字符串,并拼接成功之后,debug输出的这条语句未必显示,所以在这种语句之前最好判断一下:

    if(logger.isDebugEnabled()) { 
      logger.debug("Entry number: " + i + " is " + String.valueOf(entry[i]));
    }

      6.2 

    logger.debug("The new entry is "+entry+".");
    logger.debug("The new entry is {}.", entry);//在判断是否会被输出,并且将会被输出,之后才对被输出的参数进行处理

    7. Logback依赖于一个配置库叫做:Joran,这个库位于Logback-core。

    8. Logback通过StatusManager对象收集log内部的状态数据,这个StatusManager可以通过LoggerContext访问。

    9. 每个Logger都依附于一个Logger Context。默认情况下,这个logger context叫做“default”。但是,我们可以通过<contextName> 来给context起一个名字,但是一旦名字被set,就不能更改。

  • 相关阅读:
    select&pselect/poll&ppoll/epoll
    软件常见基础问题总结
    FIFO、LRU、OPT这三种置换算法的缺页次数
    Django配置静态文件(CSSjs)及Django调用JS、CSS、图片等静态文件
    Django基础
    Django开发网站(四)
    Django开发网站(二)
    ubuntu1304下安装boa服务器
    Django开发网站(一)
    C语言中的七种排序算法
  • 原文地址:https://www.cnblogs.com/hongdanning/p/4569105.html
Copyright © 2020-2023  润新知