The logback manual #01# Introduction
依赖包如下pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>org.sample.logback</groupId>
<artifactId>test-logback</artifactId>
<version>1.0-SNAPSHOT</version> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- -source 1.5 中不支持 try-with-resources-->
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties> <dependencies>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-core -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
</project>
例子程序:
package org.sample.logback; import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.core.util.StatusPrinter;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; public class LogbackTest { @Test
public void testLogback() {
Logger logger = LoggerFactory.getLogger(LogbackTest.class);
logger.debug(logger.getName()); // 这个logger(记录器)名字叫org.sample.logback.LogbackTest
logger.debug("Hello world."); // 一个级别为DEBUG的logging(记录)语句,并带有消息“Hello world”。
// 不论项目大小,logging语句并不会有什么改变(总是像上面那样简单),只是配置不同! /*
logback的默认配置策略:当未找到默认配置文件时,
logback将把ConsoleAppender添加到root logger(根记录器).
PS. appender是一种可以被视为“输出目的地”的类。所以上
面这句话言下之意即:console将被作为root logger的输出目
的地之一。
*/ // 打印logback的内部状态,这依赖于具体的logback类,而不是slf4j API
// 当然,在出现errors时,logback会自动打印内部状态而无需开启
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
StatusPrinter.print(lc); // 启用“打印logback内部状态”的模式,并不是只打印一次。这在诊断logback相关问题的时候非常有用!
}
}
/*
output=
21:52:55.068 [main] DEBUG org.sample.logback.LogbackTest - org.sample.logback.LogbackTest
21:52:55.068 [main] DEBUG org.sample.logback.LogbackTest - Hello world.
21:52:55,037 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
21:52:55,037 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
21:52:55,037 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.xml]
21:52:55,037 |-INFO in ch.qos.logback.classic.BasicConfigurator@3cd1f1c8 - Setting up default configuration.
*/
The logback manual #01# Introduction的更多相关文章
- ML Lecture 0-1: Introduction of Machine Learning
本博客是针对李宏毅教授在Youtube上上传的课程视频<ML Lecture 0-1: Introduction of Machine Learning>的学习笔记.在Github上也po ...
- Docker 01 Introduction
Docker的组成: Docker Engine,一个轻量级.强大的开源容器虚拟化平台,使用包含了工作流的虚拟化技术,帮助用户建立.并容器化一个应用. Docker Hub,提供的一个SaaS服务,用 ...
- 01——Introduction to Android介绍
Introduction to Android Android provides a rich application framework that allows you to build innov ...
- The logback manual #03# Configuration
索引 Configuration in logback Automatically configuring logback Automatic configuration with logback-t ...
- The logback manual #02# Architecture
索引 Logback's architecture Logger, Appenders and Layouts Effective Level(有效等级)又名Level Inheritance Ret ...
- ACSA Associate -- 01 Introduction To The Course
1. 为什么要学习AWS认证? 2. AWS认证的考试是如何组织的? 3. 你需要做些什么? 4. 关于ACSA和ACSA BETA的信息 5. 其他链接 15 Top Paying IT Certi ...
- [ML机器学习 - Stanford University] - Week1 - 01 Introduction
What is Machine Learning? Two definitions of Machine Learning are offered. Arthur Samuel described i ...
- Chapter 01—Introduction to R
1.getwd():list the current working directory. (即获得当前工作路径) 2.setwd("mydirectory"):change th ...
- 李宏毅老师机器学习课程笔记_ML Lecture 0-1: Introduction of Machine Learning
引言: 最近开始学习"机器学习",早就听说祖国宝岛的李宏毅老师的大名,一直没有时间看他的系列课程.今天听了一课,感觉非常棒,通俗易懂,而又能够抓住重点,中间还能加上一些很有趣的例子 ...
随机推荐
- 【Scrum】-NO.40.EBook.1.Scrum.1.001-【敏捷软件开发:原则、模式与实践】- Scrum
1.0.0 Summary Tittle:[Scrum]-NO.40.EBook.1.Scrum.1.001-[敏捷软件开发:原则.模式与实践]- Scrum Style:DesignPattern ...
- Python使用suds调用webservice报错解决方法:AttributeError: 'Document' object has no attribute 'set'
使用python的suds包调用webservice服务接口,报错:AttributeError: 'Document' object has no attribute 'set' 调用服务接口代码: ...
- RabbitMq入门详解
因为项目中需要用到RabbitMq,所有花时间研究了下,虽然博客园已经有前辈写了关于RabbitMq的文章.但还是有必要研究下! 什么是RabbitMq? 百度解释:MQ全称为Message Queu ...
- 一个站点配置多个App.config
一个项目一般都只有一个配置文件.web项目中用的是web.config,但项目中有时候需要单独来配置一个文件.比如:app.config,那是否可以呢? 答案是可以的.可以在web.config中指定 ...
- 力攻突破M20的5分钟BOLL
- python--教你做个最简单的tcp通信。。
TCP协议:建立在IP协议之上的,TCP协议,传输控制协议(英语:Transmission Control Protocol,缩写为 TCP)是一种面向连接的.可靠的.基于字节流的传输层通信协议,由I ...
- 在caffe-ssd安装编译环境运行make all时候报错:Makefile:572: recipe for target '.build_release/src/caffe/util/hdf5.o' failed make: *** [.build_release/src/caffe/util/hdf5.o] Error 1
解决办法: 修改:Makefile.config INCLUDE_DIRS /usr/include/hdf5/serial/ 修改:Makefile LIBRARIES hdf5_hl and hd ...
- ubuntu修改时区
1.网上大部分解决办法是命令tzselect,然后选择亚洲-->中国->上海,但很遗憾,一点效果没有: 2.后找到解决办法,运行命令dpkg-reconfigure tzdata,选择As ...
- Java操作队列
Java操作队列 常见的几种模式: 1 简单队列simple 模型:(p + 队列 + c) P:生产者producer,将消息发送到队列 红色:消息队列 C:消费者consumer,从队列消费消 ...
- spring 框架的优点
谈spring 框架的优点就是说spring 框架2大核心技术的优点 1. 控制反转:控制反转是将对象的创建和管理交给spring容器,已经管理对象之间的依赖关系, 那么将对象的创建和生命周期的管理交 ...