日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

How to setup SLF4J and LOGBack in a web app - fast--转载

發(fā)布時間:2025/4/5 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 How to setup SLF4J and LOGBack in a web app - fast--转载 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

原文:https://wiki.base22.com/display/btg/How+to+setup+SLF4J+and+LOGBack+in+a+web+app+-+fast

Logback is intended as a successor to the popular log4j project. It was designed, in addition to many individual contributors, by Ceki Gülcü, the founder of log4j. It builds upon experience gained in building industrial-strength logging systems going back as far as 1999. Logback-classic natively implements the SLF4J API so that you can readily switch back and forth between logback and other logging frameworks such as log4j or java.util.logging (JUL).

The Simple Logging Facade for Java or (SLF4J) serves as a simple facade or abstraction for various logging frameworks, e.g. java.util.logging, log4j and logback, allowing the end user to plug in the desired logging framework at deployment time.

If your working with a Maven web-app project, this procedure will get you setup to log with LOGBack through SLF4J super fast.

Step 0 - Add LOGBack dependency libraries.

If you are using Maven skip this step.

Import the following libraries to your WEB-INF/lib folder:

  • WEB-INF
    • lib
      • logback-classic.x.x.x.jar
      • logback-core.x.x.x.jar
      • slf4j-api-x.x.x.jar

Step 1 - Add LOGBack dependency to your Maven POM

Declare the following dependency in your Maven 2 pom.xml and Maven will grab the appropriate libraries for you during the build.

<dependency> ????<groupId>ch.qos.logback</groupId> ????<artifactId>logback-classic</artifactId> ????<version>1.0.13</version> </dependency>

Step 2 - Import existing (starter) XML configuration files

You will likely want to start with a base configuration file that you can build upon. In Maven you can have a logging configuration for your main source and another for your testing. You can download starter configuration files for your project by clicking the links in the hierarchy below. Put them in your project according to the position indicated by the hierarchy shown.

  • src
    • main
      • resources
        • logback.xml
    • test
      • resources
        • logback-test.xml

Step 3 - Customize the XML configuration just enough to test

Open up the logback.xml file. If you used the starter provided in the link above, you'll find the following:

<?xml?version="1.0"?encoding="UTF-8"?> <configuration> ??<appender?name="STDOUT"?class="ch.qos.logback.core.ConsoleAppender"> ????<layout?class="ch.qos.logback.classic.PatternLayout"> ??????<Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern> ????</layout> ??</appender> ??? ??<logger?name="com.base22"?level="TRACE"/> ??? ??<root?level="debug"> ????<appender-ref?ref="STDOUT"?/> ??</root> </configuration>

You will notice that one logger is defined at a package level ("com.base22"). You can simply change that to match your application's package base. You can also declare additional loggers (packages and/or classes) if desired.

Step 4 - Put logging code in your classes

The last thing you need to do is drop some logging code in a class and test this whole setup.

Add the following to the imports section of your java code:

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

Add the following at the top of your class in the global section (just under the line that declares your class public class Whatever extends Whatever). Change the name of the class (MyClassName) in the getLogger method call, of course. Name it the same as the class you're dropping this code into.

static?final?Logger LOG = LoggerFactory.getLogger(MyClassName.class);

Throw some logging statements in your code somewhere where you know they'll be fired right away when you run your app. For example:

LOG.trace("Hello World!"); LOG.debug("How are you today?"); LOG.info("I am fine."); LOG.warn("I love programming."); LOG.error("I am programming.");

Alternatively, you can just download this simple console test app and run it as a Java app from the command line or from within your IDE:

SLF4JConsoleTest.java

This class has a main method so it runs as a Java app and it will log one statement at each level.

Step 5 - Run your app and make sure it works

Finally, run your app and make sure it works. You should see log lines in your console. If it doesn't work, just review these steps a little more carefully and fiddle with it.

轉(zhuǎn)載于:https://www.cnblogs.com/davidwang456/p/4344758.html

總結(jié)

以上是生活随笔為你收集整理的How to setup SLF4J and LOGBack in a web app - fast--转载的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 伊人综合影院 | 桃谷绘里香番号 | 伊人婷婷在线 | 韩国黄色网址 | 一区二区三区在线电影 | 亚洲成肉网 | 97人人澡| 日本无遮挡边做边爱边摸 | 免费观看h片 | 日本精品免费在线观看 | 99蜜桃臀久久久欧美精品网站 | 美女久久精品 | 福利在线观看 | 美女校花脱精光 | 成人xxxxx | 国产色播av在线 | 亚洲国产精品视频在线 | 中国亚洲女人69内射少妇 | 亚洲精品国产精品乱码视色 | 欧美日韩一区二区三 | 人与动物2免费观看完整版电影高清 | 国产一级做a爱片久久毛片a | 欧洲高潮三级做爰 | 无人在线观看的免费高清视频 | 久久久亚洲综合 | 亚洲欧美va天堂人熟伦 | 精品播放 | 成人综合站 | 色一区二区三区四区 | av片国产| 大白屁股一区二区视频 | 人人做人人爱人人爽 | 天堂影视在线观看 | 男人爽女人下面动态图 | 久久久电影 | 中文字幕女优 | 经典毛片| 黑人玩弄人妻一区二区三区 | 秋霞成人午夜鲁丝一区二区三区 | 草的我好爽 | 很色的网站 | 一直草| 久久久三级视频 | 欧美日韩三级 | 日韩aaaaaa | 国产香蕉在线观看 | 欧美精品一区二区三区蜜臀 | 欧美激情免费视频 | 久久久国产精品免费 | 青草国产 | 亚洲第一视频在线 | 亚洲福利天堂 | 国产盗摄精品一区二区酒店 | 久久精品视频18 | 国产偷v国产偷v亚洲高清 | 奇米影视播放器 | 看毛片网| 人体内射精一区二区三区 | 亚洲AV无码成人精品区先锋 | 日韩中文字幕一区二区三区 | 亚洲在线激情 | 男人天堂五月天 | 欧美亚洲韩国 | 久久久精品日本 | 中国女人一级一次看片 | 少妇野外性xx老女人野外性xx | 国产激情图片 | 久久aaaa片一区二区 | 亚洲乱亚洲乱妇 | 69人妻精品久久无人专区 | 国产黑丝一区 | 久久成人免费视频 | 国产成人精品视频一区二区 | 欧美激情一区二区三区p站 欧美mv日韩mv国产网站app | 又粗又猛又爽又黄少妇视频网站 | 禁断介护老人中文字幕 | 日朝毛片 | 欧美精品一区二区三区四区 | 国模吧一区二区三区 | 富二代成人短视频 | 精品久久精品 | 一二三区精品 | avtt在线播放 | 欧美成人免费大片 | 国产精品视频亚洲 | 新婚若妻侵犯中文字幕 | 超碰一区二区 | 蜜桃香蕉视频 | 日本一区精品视频 | 两性午夜视频 | 亚州国产精品 | 亚洲情在线| 丰满岳妇乱一区二区三区 | 久草视频在线资源 | 国内外成人激情视频 | 福利视频一区二区三区 | 中文在线免费看视频 | 人人爱人人 | 欧美日韩视频在线观看免费 |