什么字五行属金| 感冒不能吃什么| 胆固醇高不能吃什么食物| 02年属什么的| 漏尿是什么原因引起的| 什么属相不能摆放大象| 眼睛干涩有异物感用什么眼药水| 打篮球有什么好处| 瑀字五行属什么| 将军指什么生肖| sj是什么| 什么是烂桃花| 儿保做些什么检查项目| 犀利是什么意思| 老而弥坚是什么意思| 以什么之名| 酵素是什么| 清明节吃什么好| 补办港澳通行证需要什么材料| 套牌车是什么意思| 喜欢一个人会有什么表现| 天空像什么| 消化不良吃什么| 洗劫一空是什么意思| 太阳是什么| 结核杆菌dna检测是检查什么| 什么是玄关| 屁股一侧疼是什么原因| juicy是什么意思| 11月29号什么星座| 揩油是什么| 什么水果败火| 鳖是什么动物| 猪脆肠是什么器官| 怀孕一个月有什么症状| q热是什么病| 尿液结晶是什么意思| com什么意思| 帕金森是什么原因引起的| 湿气重能吃什么水果| 沆瀣一气是什么意思| 什么是回避型依恋人格| 美食家是什么意思| 无产阶级是什么意思| 什么体质容易高原反应| 夏天适合种什么植物| mcn是什么意思| 早上八点到九点属于什么时辰| 猫猴子是什么| 牛肉配什么菜好吃| 掉头发缺少什么维生素| 肝外胆管扩张什么意思| 消炎药是什么药| 金色配什么颜色好看| 天上的云像什么| 间接胆红素偏高吃什么药| 感染幽门螺旋杆菌会出现什么症状| 吃葡萄对身体有什么好处| 245阳性是什么意思| 中国最大的海是什么海| 什么水| 第二视角是什么意思| 梦到掉牙齿是什么意思| 1964属什么生肖| 什么能减肚子上的脂肪| 神经性头疼吃什么药| 后脚跟疼是什么原因| 阴吹是什么意思| 石楠花是什么| 牛肚是什么部位| 知进退明得失什么意思| 鸡内金有什么功效| 干呕是什么病的前兆| 李宇春父亲是干什么的| 志趣相投是什么意思| 掉头发严重是什么原因| 生物工程专业学什么| 维生素c是补什么的| 限高是什么意思| peter是什么意思| 9999是什么意思| 什么头什么尾| 血糖高去医院挂什么科| 肿瘤患者不能吃什么| 1976年属什么生肖| 美团和美团外卖有什么区别| 梅花代表什么象征意义| 什么是胃肠型更年期| 什么可以减肥| b超和阴超有什么区别| 吃什么水果对嗓子好| 轶事是什么意思| 妙赞是什么意思| 热泪盈眶的盈是什么意思| 社会很单纯复杂的是人是什么歌| 近视是什么原因造成的| 嗷呜是什么意思| 金牛座女和什么座最配对| 为什么一个月来两次姨妈| 什么样的女人最吸引男人的心| 萎谢是什么意思| 办身份证需要带什么| 支原体肺炎吃什么药| 吃什么补肺| 猫薄荷是什么| 舌头挂什么科| 湿疹为什么要查肝功能| 喝豆腐脑有什么好处和坏处| 冰激凌和冰淇淋有什么区别| 手电筒什么牌子的好| 今年50岁属什么| 为什么会做春梦| 无什么不什么的成语| 给事中是什么官| 思量是什么意思| 梦见脱发是什么征兆| 劲酒是什么酒| bug是什么意思中文翻译| 尿潴留是什么症状| 蚊子怕什么味道| 师傅是什么意思| 打哈欠为什么会传染| 用盐刷牙有什么好处和坏处| 黄体酮吃了有什么副作用| 开水烫伤用什么药膏好得快| 咖啡加奶叫什么| 喝杨梅酒对身体有什么好处| 胸口容易出汗是什么原因| 唐僧的袈裟叫什么| 肝结节是什么病严重吗| 母仪天下什么意思| 葡萄胎是什么意思| 教是什么生肖| 血脂高什么意思| 琛字五行属什么| 橄榄色是什么颜色| 头晕为什么做眼震检查| 更年期吃什么药| 想吃辣的是什么原因| pu是什么元素| 什么的勇气| 嗜酸性粒细胞偏高是什么原因| 下连是什么意思| 什么颜色加什么颜色等于什么颜色| 新生儿溶血是什么意思| 什么的帽子| 做梦被打了是什么意思| 内窥镜是做什么检查| 梦见网鱼是什么征兆| 乳腺结节和乳腺增生有什么区别| 以貌取人是什么意思| 老人手抖是什么病的预兆| 轻度溶血是什么意思| 中暑有什么症状| 微波炉蒸鸡蛋羹几分钟用什么火| 四五行属什么| 贫血三项是指什么检查| 盆腔少量积液什么意思| gif什么意思| 白细胞偏高是什么意思| 91年属什么的| L是什么| 黄瓜有什么好处| 93岁属什么生肖| 葡萄上的白霜是什么| 红米有什么功效和作用| 距骨在什么位置| 如果怀孕了会有什么预兆| 负利率是什么意思| 阳痿什么症状| 宫颈ca什么意思| 查血管堵塞做什么检查| 牙医靠什么吃饭| 皮下囊肿是什么原因引起的| 一什么香蕉| 头皮屑多用什么洗发水效果好| 胸闷什么原因| 加百列是什么天使| 汗手适合盘什么手串| 孩子脾虚内热大便干吃什么药| 梦见自己嫁人了预示着什么| ABB式的词语有什么| 孤帆远影碧空尽的尽是什么意思| 纲是什么意思| 亚五行属什么| 血小板低是什么原因引起的| 硬度不够是什么原因| 湿疹吃什么食物好| 冒昧打扰是什么意思| 甘胆酸偏高是什么原因| 做美甲师容易得什么病| 脑垂体挂什么科| 喜鹊吃什么| 兔死狗烹是什么生肖| 水煮肉片放什么配菜| 拉血是什么病| 看心脏挂什么科| 什么是应激反应| 新生儿什么时候剪头发| 总是拉肚子是什么原因| 昂热为什么认识路鸣泽| 晨对什么| 手足口病吃什么药| 临床路径是什么意思| 小孩出汗多是什么原因| 黄疸高是什么原因引起的| 皮试是什么| 潜能什么意思| 吃什么尿酸高| 271是什么意思| 绿茶女是什么意思| 什么的玻璃| 五行属金什么字最好| 巫山云雨是什么意思| 一月二十五号是什么星座| 新生儿dha什么时候开始吃| 什么动物跑得快| 口臭是什么原因导致的呢| 色丁布是什么面料| 牛鞭是什么东西| 乳贴是什么| 婆婆妈妈什么意思| religion什么意思| 吃火龙果有什么好处| 颈部彩超能检查出什么| 赶尽杀绝什么意思| pbg是什么意思| 2月4号是什么星座| 胡子变白是什么原因| 貔貅长什么样| 晚上减肥吃什么| 三高人群适合吃什么| 土龙是什么| 小苏打有什么作用| 为什么晚上睡不着觉| 双肺钙化灶是什么意思| 尴尬什么意思| 女人吃葛根粉有什么好处| 物质是由什么组成的| 天蝎女喜欢什么样的男生| 肉桂茶是什么茶| 氢氧化钠是什么| 大意失荆州是什么意思| 为什么会得荨麻疹呢| 电磁炉上可以放什么锅| adh是什么激素| 红沙日是什么意思| 吃维生素b2有什么好处和副作用| 顺其自然是什么意思| 南屏晚钟什么意思| 来月经前胸胀痛什么原因| 洗纹身去医院挂什么科| 痛经不能吃什么| 五月二十六是什么星座| 蛋白糖是什么糖| 禁的拼音是什么| 气场是什么意思| 舒克是什么职业| 牙龈充血是什么原因| 鼻炎吃什么| 2月28号是什么星座| 谨记是什么意思| 什么是腹式呼吸的正确方法| 阴囊潮湿用什么药| 百度
DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Attention Kubernetes users! DZone is researching how K8s usage is evolving in 2025 — tell us the good, the bad, + the frustrating.

Getting Started With DevSecOps: This Refcard provides actionable insights for embedding security into your DevOps culture and workflows.

Data Engineering: Not your average "AI is changing everything" report. Dive into tooling, strategy, + systems in scalable data ecosystems.

Java Caching: This Refcard explores core caching concepts and demonstrates how to implement them using Java’s JCache API.

Related

  • Top Microservices Frameworks
  • How to Debug the Spring Boot Application in Eclipse? [Video]
  • Dependency Injection in Spring
  • Spring Boot - Microservice- JaxRS Jersey - HATEOAS - JerseyTest - Integration

Trending

  • Should You Switch to a Monorepo? A Developer’s No-Fluff Guide
  • Building a VS Code-Like Online IDE With Next.js 15, TypeScript, Tailwind CSS, and Goose AI
  • Securing Software Created by AI Agents: The Next Security Paradigm
  • Immutable Objects Using Record in Java
  1. DZone
  2. Coding
  3. Frameworks
  4. An Introduction to Logback: a Logging Framework From the Creator of Log4J

肺结节吃什么药最好

Monitoring, diagnosing, and troubleshooting are key activities in any enterprise application lifecycle, and logging is the core part of these activities. Meet Logback, a logging framework from the creator of Log4J.

By 
John Thompson user avatar
John Thompson
·
Apr. 14, 16 · Analysis
Likes (8)
Comment
Save
Tweet
Share
14.4K Views
百度 据介绍,新视界眼科主要从事眼科医院的投资与管理,在全国多地开设了多家眼科医院,是一家全国连锁眼科机构。

Join the DZone community and get the full member experience.

Join For Free
Monitoring, diagnosing, and troubleshooting are key activities in any enterprise application lifecycle, and logging is the core part of these activities. Through logging you get to see what the application code is actually doing during these activities at runtime. Using System.out to print messages to the console is simply not sufficient for enterprise applications. Enterprise applications have logging requirements with varied degree of complexities. You will need generating logs with different levels of importance, such as ERROR, WARN, INFO, and DEBUG. You’ll also have requirements to send logs to different destinations, such as console, file, database, SMTP server, or JMS queue destination. These requirements are not possible with simple System.out statements. Logging frameworks such as Logback are designed to meet the needs of logging in the enterprise.

Logback Architecture

Ceki Gülcü the founder of the Log4J along with Sébastien Pennec, another Log4J contributor, designed logback. With decades of experience with logging frameworks, they designed logback to be fast and generic enough to work under different environments. Logback is comprised of three modules:

  • logback-core: Forms the foundation of logback-classic and logback-access. To perform logging, you need the more specialized logback-classic or logback-access.
  • logback-classic: Relies on logback-core for logging services.
  • logback-access: Provides HTTP-access log functionalities to servlets containers, such as Tomcat and Jetty.

In this post we will explore logback-classic, which in going forward I’ll refer to as logback. Logback natively implements the Simple Logging Facade for Java (SL4J) API. In a nutshell, SL4J is a fa?ade for various logging frameworks. As a developer, you’ll write logging code against the SL4J API. At deployment time, you have the flexibility to plug-in a desired logging framework, made possible through an intermediate SL4J bridge layer. As logback natively implements SL4J, the additional SL4J API layer doesn’t incur any performance overhead, a slight advantage that Logback has over other frameworks.

This figure illustrates the interaction of an application with Logback.

Interaction of a Java application with the Logback logging framework

The key Logback components are loggers, appenders, and encoders/layouts. The components work together to provide the developer full control on how messages are logged, formatted, and where they are reported.

Logger

Loggers are the components that do the heavy work in logging. They capture the logging data and output it to a destination using appenders. The loggers used in an application are typically organized into a hierarchy and a root logger resides at the top of the hierarchy. It is the LoggerContext that is responsible for creating loggers and arranging them in a hierarchy.

Loggers maintain a hierarchical naming rule. As an example, a logger named guru is the parent of the logger named guru.springframework, and the ancestor of the logger named guru.springframework.blog.
 Logger Hierarchy

Apart from logger inheritance, an important logback concept is level inheritance, also referred as effective level. You can assign levels to loggers. Logback supports the TRACE, DEBUG, INFO, WARN, and ERROR levels, as shown in this figure.

Log Levels

As you can see in the figure above, TRACE is the lowest level and the level moves up through, DEBUG, INFO, WARN, until ERROR, the highest level. This means that if you set the logger level to WARN, then only the WARN and ERROR level log messages will be displayed and the rest will be ignored.

In addition to the above levels, there are two special levels:

  • ALL: Turns on all levels.
  • OFF: Turns off all levels.

If a logger is not assigned a level, then level inheritance comes into play. The logger will inherit the level from its nearest ancestor with an assigned level. If none of the application loggers in the hierarchy have assigned a level, the level of the root logger will be inherited. The default level of the root logger is DEBUG.

Note: While developing on your local machine, it is common to set the log level to DEBUG. This will give you detailed log messages for your development use. When deployed to a production environment, it’s typical to set the log level to ERROR. This is to avoid filling your logs with excessive debug information. Also, while logging is very efficient, there is still a cost to system resources.

Appenders

Once you capture logging information through a logger, you need to send it to an output destination. The output destination is called an appender, and it’s attached to the logger. Logback provides appenders for the console, files, remote socket servers, SMTP servers, many popular databases (such as MySQL, PostgreSQL, and Oracle), JMS, remote UNIX Syslog daemons, and more.

Layouts/Encoders

An appender uses a layout to format a log event. A layout, which is an implementation of the Layout interface of logback-core, transforms a log event to a string. A layout can’t control when log events get written out, and therefore can’t group events into batches. To address the limitations of layouts, logback introduced encoders in version 0.9.19. Encoders, which are implementations of the Encoder interface, transform an incoming log event into a byte array and write out the resulting array onto the appropriate output stream. Encoders have total control over the format of the bytes written out. In addition, encoders can control whether (and when) those bytes get written out. I’ll discuss more about layouts and encoders in upcoming posts on logback configuration.

Using Logback

We will start with a simple application that uses Logback for logging. To start with, we need the logback dependencies in our project. Out of the box, both Spring Boot core and web projects include the logback classic dependencies. This figure shows the logback dependencies included in Spring Boot.

Logback Dependencies via Sprint Boot
As shown in the figure above, the latest SpringBoot 1.3.3RELEASE version as of writing this post uses Logback classic 1.1.5.

If you want to use different Logback and SL4J versions or if you are not using SpringBoot, define their dependencies in your Maven POM, like this.

. . .
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-api</artifactId>
  <version>1.7.21</version>
</dependency>
<dependency>
  <groupId>ch.qos.logback</groupId>
  <artifactId>logback-classic</artifactId>
  <version>1.1.7</version>
</dependency>
. . .

In an application, you can retrieve a logger by calling the getLogger() method of the SL4J LoggerFactory class. There are two overloaded getLogger() methods. One returns a Logger instance named according to the string value passed as a parameter. The other returns a Logger instance named corresponding to the class passed as a parameter. The recommended strategy is to use the latter one. This is because in a large application with thousands of log statements, you will find it easy to identify the origin of a log message as the log output bears the name of the generating logger. Once you retrieve a Logger, you can call the log methods on it, like this.

LogbackDemo.java

package guru.springframework.blog.logbackoverview;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LogbackDemo {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    public void performTask(){
        logger.info("This is an {} message.","info");
        logger.warn("This is a warn message.");
        logger.error("This is an error message.");
        logger.debug("This is a debug message.");
    }
}

In Line 8 of the LogbackDemo class above, we retrieved a Logger object with a call to the static Loggerfactory.getLogger() method. Passing LogbackDemo.class to getLogger() instead of this.getClass() will produce the same result. But I suggest passing this.getClass() to decouple the statement from a particular class, thereby making it reusable across other logging classes. From Line 10 – Line 13, we called the log methods on the retrieved logger. Notice Line 10 that uses parameterized message in the info() method. You can use such parameterized log messages in the other logging methods too.

To test the preceding logger, we will use JUnit. The test class is this.

LogbackDemoTest.java

package guru.springframework.blog.logbackoverview;

import org.junit.Test;

import static org.junit.Assert.*;

public class LogbackDemoTest {

    @Test
    public void testPerformTask() throws Exception {
        LogbackDemo logBackDemo = new LogbackDemo();
        logBackDemo.performTask();
    }
}

When you run the test class, the log messages of LogbackDemo are sent to the console.
 Log Output in Console

Summary

In the example in this post, you may have noticed that I did not specify any appender/encoder or layout for the logger. Rather, I relied upon defaults inherited from the logback root logger. By default, the root logger is associated with the console appender and has the DEBUG level, and our logger inherited both. Therefore, debug and higher log messages were sent to the IntelliJ console. However, in enterprise applications it's likely you’ll work with external configuration files to use more advanced features of Logback. These configuration files can be XML or Groovy to specify Logback configuration options. In upcoming posts, I’ll discuss using both XML and Groovy external configuration files to help you explore what a powerful logging tool Logback is.

Framework application Log4j Spring Framework Debug (command) Creator (software)

Published at DZone with permission of John Thompson, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Top Microservices Frameworks
  • How to Debug the Spring Boot Application in Eclipse? [Video]
  • Dependency Injection in Spring
  • Spring Boot - Microservice- JaxRS Jersey - HATEOAS - JerseyTest - Integration

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

头发掉的厉害是什么原因 sat是什么考试 耳朵长疙瘩是什么原因 后背出汗多是什么原因 becky是什么意思
壬午是什么生肖 无妄之灾什么意思 面肌痉挛是什么原因引起的 利多卡因是什么 睾丸疼什么原因
蛋白粉和胶原蛋白粉有什么区别 猪沙肝是什么部位 chanel是什么牌子 肝内血管瘤是什么意思 卉字五行属什么
腰间盘突出用什么药好 熟地黄是什么 货值是什么意思 柳树的叶子像什么 为什么晚上睡不着觉
流年是什么意思hcv8jop0ns7r.cn 中暑喝什么好hcv8jop7ns8r.cn 取什么网名好听bfb118.com 5公里25分钟什么水平520myf.com 牙龈萎缩用什么牙膏好wzqsfys.com
吃夏枯草有什么副作用hcv9jop4ns6r.cn 棱长是什么意思hcv8jop7ns0r.cn 子宫肌瘤做什么检查能查出来hcv7jop4ns8r.cn 早上打碎碗是什么兆头ff14chat.com 反应蛋白高是什么原因hcv9jop8ns3r.cn
胎儿肾积水是什么原因引起的hcv9jop5ns4r.cn 头臂长是什么意思hcv9jop3ns0r.cn 泪腺堵塞是什么症状hcv8jop6ns0r.cn 连襟什么意思ff14chat.com 红颜知己代表什么关系hcv9jop4ns5r.cn
义举是什么意思hcv8jop4ns3r.cn 梦见黄狗是什么意思hcv8jop7ns2r.cn 肌层回声均匀是什么意思hcv8jop8ns6r.cn 喝什么汤下奶最快最多hcv9jop0ns5r.cn 绩效工资是什么意思hcv9jop5ns0r.cn
百度