依赖包如下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. BBS项目

    一.需求分析 1.首页(显示文章) 文章详情 点赞,点踩 文章评论(子评论,评论的展示) 登录功能(图片验证码) 注册功能(基于form验证,ajax) 个人站点(不同人不同样式,文章过滤) 后台管理 ...

  2. 构造器初始化(static)

    package demo; /* * 在类 的内部,变量定义的先后顺序决定了初始化的顺序.即使变量定义散布于方法定义之间, * 它们仍旧会在任何方法(包括构造器)被调用之前得到初始化. */ publ ...

  3. Scala泛型[T]的使用

    package com.dtspark.scala.basics /** * 1,scala的类和方法.函数都可以是泛型. * * 2,关于对类型边界的限定分为上边界和下边界(对类进行限制) * 上边 ...

  4. char varchar

    对于字符类型的有:char:固定长度,存储ANSI字符,不足的补英文半角空格.nchar:固定长度,存储Unicode字符,不足的补英文半角空格varchar:可变长度,存储ANSI字符,根据数据长度 ...

  5. 15个Node.js项目列表

    前言: Node.js 是一个基于Chrome JavaScript 运行时建立的一个平台,是一个事件驱动I/O服务端JavaScript环境,基于Google的V8引擎,V8引擎执行Javascri ...

  6. 适用于 Windows 7 SP1 和 Windows Server 2008 R2 SP1 的 .NET Framework 4.6、4.6.1、4.6.2 和 4.7 以及适用于 Windows Server 2008 SP2 的 .NET Framework 4.6 仅安全更新说明:2017 年 9 月 12 日

    https://support.microsoft.com/zh-cn/help/4040957/description-of-the-security-only-update-for-the-net ...

  7. Linux df命令详解

    1.命令:df 2.命令功能:显示指定磁盘文件的可用空间. 3.命令参数: -a #全部文件系统列表 -h #方便阅读方式显示 -H #等于“-h”,但是计算式,1K=1000,而不是1K=1024 ...

  8. Python Shell 中敲击方向键显示「^[[C^[[D],问题解决

    碰到问题后,在网上搜索. 有帖子建议:yum install -y ncurses-devel,我这个2.7.13版本的在Linux下不行.估计是解决python3.x的方案. 尝试网上建议的,装了 ...

  9. ida脚本函数

    #打印光标所在位置函数中地址和汇编代码 startaddr=GetFunctionAttr(ea, FUNCATTR_START) items = idautils.FuncItems(startad ...

  10. VS 应用模板 所交税和实发工资的运算

    double SFGZ, SL, SSKCS, YFGZ,a,YJS; //应发工资(基本工资),税率,速算扣除数,应发工资,判断标准,交多少税 //double QZD = 3500;//起征点 无 ...