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
引言: 最近开始学习"机器学习",早就听说祖国宝岛的李宏毅老师的大名,一直没有时间看他的系列课程.今天听了一课,感觉非常棒,通俗易懂,而又能够抓住重点,中间还能加上一些很有趣的例子 ...
随机推荐
- 进程间通信IPC机制和生产者消费者模型
1.由于进程之间内存隔离,那么要修改共享数据时可以利用IPC机制 我们利用队列去处理相应数据 #管道 #队列=管道+锁 from multiprocessing import Queue # q=Qu ...
- [django]django model的查询和更新
再分享Django系列的另外几篇文章: Django model select的各种用法详解:https://mp.weixin.qq.com/s/JVh4UnS2Tql9gUVaBSoGuA Dja ...
- sqlserver把数据导入mysql
sqlserver库 navicat逆向表到模型 转换模型为... 选择mysql 建模转换后导出sql 导出sql后,再mysql库中执行该sql(该sql为表结构)执行sql后,使用navicat ...
- Python 命名笔记
类名开头大写,驼峰命名 函数名,变量名都小写, 全局常量 如COUNT, 使用全部大写 https://www.cnblogs.com/lytwajue/p/7324724.html 这个是全局变量关 ...
- gerrit设置非小组成员禁止下载代码
对gerrit有所了解的同学,都知道gerrit 是我们常用的一个来做代码审核的工具,其中的权限管理,是一个非常重要的环节,关于每个权限的使用范围,可以参考博客https://blog.csdn.ne ...
- [LeetCode] questions conlusion_InOrder, PreOrder, PostOrder traversal
Pre: node 先, Inorder: node in, Postorder: node 最后 PreOrder Inorde ...
- js中var a=new Object()和var a={}有什么区别吗?
应该是没有区别的,两者都是生成一个默认的Object对象.js和其它语言一样,一切对象的基类都是Object,所以,new Object()和简易的{}是同样的空对象,就是默认的对象.本来我以为{}应 ...
- UVa-1025城市里的间谍 A Spy in the Metro
原题 城市里的间谍 分析 动态规划,dp[i][j]表示你在时刻i,车站j,最少还要等待的时间. 边界条件d[T][n]=0 已经到达,其他d[T][i]=inf不可达. 在一个站点时,有以下三种决策 ...
- JS中常用的输出方式(五种)
1.alert("要输出的内容"); ->在浏览器中弹出一个对话框,然后把要输出的内容展示出来 ->alert都是把要输出的内容首先转换为字符串然后在输出的 2.doc ...
- ling join 报错The specified LINQ expression contains references to queries that are associated with different cont
The specified LINQ expression contains references to queries that are associated with different cont ...