依赖包如下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的更多相关文章

  1. ML Lecture 0-1: Introduction of Machine Learning

    本博客是针对李宏毅教授在Youtube上上传的课程视频<ML Lecture 0-1: Introduction of Machine Learning>的学习笔记.在Github上也po ...

  2. Docker 01 Introduction

    Docker的组成: Docker Engine,一个轻量级.强大的开源容器虚拟化平台,使用包含了工作流的虚拟化技术,帮助用户建立.并容器化一个应用. Docker Hub,提供的一个SaaS服务,用 ...

  3. 01——Introduction to Android介绍

    Introduction to Android Android provides a rich application framework that allows you to build innov ...

  4. The logback manual #03# Configuration

    索引 Configuration in logback Automatically configuring logback Automatic configuration with logback-t ...

  5. The logback manual #02# Architecture

    索引 Logback's architecture Logger, Appenders and Layouts Effective Level(有效等级)又名Level Inheritance Ret ...

  6. ACSA Associate -- 01 Introduction To The Course

    1. 为什么要学习AWS认证? 2. AWS认证的考试是如何组织的? 3. 你需要做些什么? 4. 关于ACSA和ACSA BETA的信息 5. 其他链接 15 Top Paying IT Certi ...

  7. [ML机器学习 - Stanford University] - Week1 - 01 Introduction

    What is Machine Learning? Two definitions of Machine Learning are offered. Arthur Samuel described i ...

  8. Chapter 01—Introduction to R

    1.getwd():list the current working directory. (即获得当前工作路径) 2.setwd("mydirectory"):change th ...

  9. 李宏毅老师机器学习课程笔记_ML Lecture 0-1: Introduction of Machine Learning

    引言: 最近开始学习"机器学习",早就听说祖国宝岛的李宏毅老师的大名,一直没有时间看他的系列课程.今天听了一课,感觉非常棒,通俗易懂,而又能够抓住重点,中间还能加上一些很有趣的例子 ...

随机推荐

  1. [django]http请求

    请求参数 http基本认证 https://zxc0328.github.io/2015/11/04/http-basic-auth/ 我们看到在http请求的header里有一个Authorizat ...

  2. Node.js学习看这里:基础、进阶、文章

    Node.js是基于Chrome JavaScript运行时建立的一个平台,实际上它是对Google Chrome V8引擎进行了封装,它主要用于创建快速的.可扩展的网络应用. Node.js采用事件 ...

  3. xshell 禁用铃声 提示音

    xshell 的铃声在操作时比较烦,所以通常会关闭. 操作方法: 工具 > 选项 > 高级, 在“终端”选项下的 “禁用铃声” 前面打上勾, 确定即可.

  4. cocos2d JS touch(触摸监听)-快速添加事件监听器到管理器

    cc.eventManager.addListener({ event: cc.EventListener.TOUCH_ALL_AT_ONCE, onTouchesMoved: function (t ...

  5. json_decode 转数组

    json_decode($json); 直接转义json数据后会发现转义后的数据时对象类型, 想要获得数组型,加一个参数 json_decode($json,true);

  6. Spark以yarn-client提交任务时报错超时,Connection to 192.168.. /has been quiet forms while there are outstanding requests. Failed to send RPC.....

    报错信息如上,具体是运行FusionInsight给的样例SparkPi,在local环境下是可以的,但是如果以yarn-client模式就会卡住,然后120s以后超时,其实以yarn-cluster ...

  7. python拼接变量、字符串的3种方法

    第一种,加号(“+”): print 'py'+'thon' # output python str = 'py' print str+'thon' # output python 第二种 ,空格: ...

  8. jQuery清除数组中的空值

    var aa = ["12", "34", "", "423", " "];   console.l ...

  9. Python记录8:函数的嵌套

    #函数的嵌套分为两类:# 1.函数的嵌套定义: 在函数内部又定义了一个函数# def foo():# x=1# # print(x)# def bar():# print('from bar')## ...

  10. Unity shader学习之半兰伯特光照模型

    半兰伯特光照模型,为Valve公司在开发游戏<半条命>时提出的一种技术,用于解决漫反射光无法到达区域无任凭明暗变化,丢失模型细节表现的问题. 其公式如下: Cdiffuse = Cligh ...