`
darrenzhu
  • 浏览: 798027 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

logback的配置文件位置

    博客分类:
  • Java
阅读更多
参考文档:http://logback.qos.ch/manual/configuration.html
对于maven项目,将测试用的配置文件logback-test.xml放在test/resources/下即可.
Logback can be configured either programmatically or with a configuration script expressed in XML or Groovy format. By the way, existing log4j users can convert their log4j.properties files to logback.xml using our PropertiesTranslator web-application.

logback按如下顺序寻找配置文件,
Let us begin by discussing the initialization steps that logback follows to try to configure itself:
1) Logback tries to find a file called logback.groovy in the classpath.
2)If no such file is found, logback tries to find a file called logback-test.xml in the classpath.
3)If no such file is found, it checks for the file logback.xml in the classpath..
4)If neither file is found, logback configures itself automatically using the BasicConfigurator which will cause logging output to be directed to the console.

The fourth and last step is meant to provide a default (but very basic) logging functionality in the absence of a configuration file.
If you are using Maven and if you place the logback-test.xml under the src/test/resources folder, Maven will ensure that it won't be included in the artifact produced. Thus, you can use a different configuration file, namely logback-test.xml during testing, and another file, namely, logback.xml, in production. The same principle applies by analogy for Ant.

配置文件模板:


<configuration>
  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
    <file>myApp.log</file>

    <encoder>
      <pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
    </encoder>
  </appender>

  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%msg%n</pattern>
    </encoder>
  </appender>

  <logger name="org.hibernate">
    <appender-ref ref="STDOUT" />
  </logger>
  
  <logger name="com.test">
    <appender-ref ref="FILE" />
  </logger>  
  
  <root level="debug">
    <appender-ref ref="FILE" />
    <appender-ref ref="STDOUT" />
  </root>
</configuration>
分享到:
评论

相关推荐

    LogBack配置文件

    LogBack配置文件,主要包括LOGBack的配置文件内容

    springboot整合logback配置文件

    springboot整合logback配置文件

    项目中在使用的logback配置文件

    项目中在使用的logback,拿过去直接可以用,带完整的中文说明。

    logback配置文件

    logback学习使用的配置文件,logback入门使用配置

    logback配置文件解析和示例

    该文件包含logback配置文件示例和配置文件内容解析,如果想深入学习的系哦小伙伴可以下载看看,如果只是想实现功能,可以查看我的博客 《整合篇------JAVA项目整合Logback》

    Logback类库含logback.xml配置文件

    `logback.xml` 配置文件是 Logback 框架的核心部分,用于定制日志行为。它允许你定义日志级别(如 TRACE, DEBUG, INFO, WARN, ERROR, FATAL 和 OFF),指定日志输出目的地(控制台、文件、数据库等),以及配置过滤...

    logback配置详解

    logback 的默认配置如果配置文件 logback-test.xml 和 logback.xml 都不存在,那么 logback 默认地会调用 BasicConfigurator,创建一个最小化配置。最小化配置由一个关联到根 logger 的 ConsoleAppender 组成。输出...

    Logback配置文件

    logback配置文件demo,用于在springboot项目中放到resource 目录下即可 logback配置文件demo,用于在springboot项目中放到resource 目录下即可

    logback-slf4j日志配置文件-下载即可使用

    "logback-slf4j日志配置文件下载即可使用" logback-slf4j是Java领域中一种常用的日志记录解决方案,它通过结合slf4j(Simple Logging Facade for Java)来提供了异步日志输出的功能,能够将日志输出到不同的文件中...

    logback配置文件放入resource

    logback配置文件放入resource

    logback jar包和logback.xml配置文件打包下载 小白新手学Java

    在这里,我们关注的是SLF4J的API库`slf4j-api-1.7.26.jar`,以及Logback的两个核心组件`logback-core-1.2.3.jar`和`logback-classic-1.2.3.jar`,以及配置文件`logback.xml`。 首先,`slf4j-api-1.7.26.jar`是SLF4J...

    Logback配置文件根据 LEVEL级别将日志分类保存到不同文件.docx

    《Logback配置文件根据LEVEL级别将日志分类保存到不同文件》 日志管理是软件开发中的重要一环,它能帮助开发者追踪程序运行状态,定位问题,优化性能。Logback是一个广泛使用的日志框架,它允许我们高效地处理日志...

    springboot-logback配置

    springboot-logback日志文件配置

    logbackーslf4j-配置文件实例 难得

    Logback配置文件 Logback的配置主要通过`logback.xml`文件完成,这是一个XML格式的配置文件,用于定义日志级别、日志输出目的地、过滤器等。以下是一份基本的`logback.xml`配置示例: ```xml ...

    logback通用xml配置

    用于logback框架通用xml配置文件

    SpringBoot+tk.Mybatis整合+yml配置+logback配置

    在“SpringBoot+tk.Mybatis整合+yml配置+logback配置”这个主题中,我们将探讨以下几个关键知识点: 1. **SpringBoot整合tk.Mybatis**: tk.Mybatis 是 Mybatis 的一个扩展,提供了很多实用功能,如:动态 SQL、...

Global site tag (gtag.js) - Google Analytics