博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【logback】认识logback
阅读量:4583 次
发布时间:2019-06-09

本文共 2388 字,大约阅读时间需要 7 分钟。

一. Reference:

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,就不能更改。

 

转载于:https://www.cnblogs.com/hongdanning/p/4569105.html

你可能感兴趣的文章
[BZOJ 1188] [HNOI2007] 分裂游戏 【博弈论|SG函数】
查看>>
[BZOJ - 2631] tree 【LCT】
查看>>
ASP.NET Core管道深度剖析(2):创建一个“迷你版”的管道来模拟真实管道请求处理流程...
查看>>
JS实现数组排序:升序和降序
查看>>
怎样写具体设计文档
查看>>
CAShapeLayer
查看>>
ACM_夏天到了,又到了出游的季节
查看>>
【转载】HTTP 错误 500.19 - Internal Server Error
查看>>
2015 Multi-University Training Contest 3 hdu 5325 Crazy Bobo
查看>>
SQL Server 存储图片
查看>>
php特级课---4、网站服务监控(常用网站服务监控软件有哪些)
查看>>
ubuntu14.04 boost 1.58.0 安裝
查看>>
漏洞基本概念
查看>>
直角三角形 (Standard IO)
查看>>
web 12
查看>>
Centos7安装Nginx
查看>>
探讨在线支付平台支付接口的设计
查看>>
【设计模式】常用设计模式总结
查看>>
.NET中的六个重要概念
查看>>
二十九、简谈设计模式
查看>>