- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 Java 独立应用程序。使用 main 方法,使用这 2 个导入:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
和
private static final Logger log = LoggerFactory.getLogger(PecadorDeLaPradera.class);
在同一个文件夹中,我还有一个 logback.xml
但我不知道如何告诉使用 logback.xml
的程序来配置日志
我找不到任何类似于org.apache.log4j.PropertyConfigurator
的类
我在运行的 Java 类的同一文件夹中有这个 logback.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- trace, debug, info, warn, error, fatal -->
<timestamp key="myTimestamp" datePattern="yyyy-MM-dd'_'HH-mm-ss.SSS"/>
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
<resetJUL>true</resetJUL>
</contextListener>
<!-- To enable JMX Management -->
<jmxConfigurator/>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{"yyyy-MM-dd HH:mm"} [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>pecador.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>handler.%i.log.zip</fileNamePattern>
<minIndex>1</minIndex>
<maxIndex>3</maxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>1MB</maxFileSize>
</triggeringPolicy>
<encoder>
<pattern>%d{"yyyy-MM-dd HH:mm"} [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<!-- <logger name="org.springframework.orm.jpa" level="debug" /> -->
<logger name="com.calzada.pecador" level="debug" />
<root level="info">
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE" />
</root>
</configuration>
我还运行了该应用程序。带有程序参数:
-Dlogback.configurationFile=/Users/calzada/Dev/J2EE/eclipseWSJ2EE/myApp/src/com/calzada/pecador/logback.xml
我得到了这个错误:
java.util.MissingResourceException: Can't find bundle for base name -Dlogback.configurationFile=/Users/nullpointer/Development/J2EE/eclipseWSJ2EE/myApp/src/com/calzada/pecador/logback.xml, locale en_ES
使用的库是logback-classic-1.2.3.jar
最佳答案
这是 logback 如何配置自身的:
Logback tries to find a file called
logback-test.xml
in the classpath.If no such file is found, logback tries to find a file called
logback.groovy
in the classpath.If no such file is found, it checks for the file
logback.xml
in the classpath.If no such file is found, service-provider loading facility (introduced in JDK 1.6) is used to resolve the implementation of
com.qos.logback.classic.spi.Configurator
interface by looking up the fileMETA-INF\services\ch.qos.logback.classic.spi.Configurator
in the class path. Its contents should specify the fully qualified class name of the desired Configurator implementation.If none of the above succeeds, logback configures itself automatically using the
BasicConfigurator
which will cause logging output to be directed to the console.
您还可以使用系统参数 logback.configurationFile
将 Logback 指向特定配置文件。 。来自文档:
You may specify the location of the default configuration file with a system property named "logback.configurationFile". The value of this property can be a URL, a resource on the class path or a path to a file external to the application.
java -Dlogback.configurationFile=/path/to/config.xml chapters.configuration.MyApp1
以上内容均取自docs .
根据您的问题,您有 logback.xml
但该文件与您的类(class)位于“同一文件夹”中。除非您的类位于根包中,否则这意味着 logback.xml
不在类路径的根目录中,因此 Logback 不会发现它。为了让 Logback 通过该文件配置自身,您可以执行以下操作之一:
logback.xml
复制到 src/main/resources
一样简单)-Dlogback.configurationFile=/path/to/logback.xml
运行您的 Java 程序关于JAVA:在独立应用程序中配置 logback,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46057356/
我正在尝试使用 janino 的条件处理来删除冗余的 logback 配置文件。 下面是我添加的条件逻辑
我有三个独立的项目,每个项目都有自己的嵌入式 logback.xml 文件。这些文件中的每一个都在用户的主目录中包含一个通用的日志配置文件: 在包含之后,我有这个规范: 这允许用户配置
我使用这个logback配置文件: %d{HH:mm:ss.SSS} [%-10.-10thread] %-5level %-30logger{1} - %msg%n
我的公司有一个环境管理工具,使您能够以 Java 编程方式从环境中查找属性。我想利用这个工具来配置 logback。例如,假设我有一个如下的 logback.xml(特别是文件 appender 部分
这似乎是一个粗心的错误,但我似乎找不到原因。使用 logback/slf4j(最新版本 slf4j-api-1.6.1,logback core/classic 0.9.24)进行记录。最简单的测试日
这是经典的logback的错误还是我遗漏了一些东西? The documentation非常明确地表明scanPeriod是可选属性: By default, the configuration fi
我正在尝试设置一个 logback 配置,该配置创建一个解压缩的日志文件作为第一卷,然后将压缩文件写入不同的目录。我相信最好的方法是在单个 appender 中创建多个 rollingPolicy 元
我用各种框架(jsf、Spring、Hibernate)编写了一个网络应用程序,我的记录器库是 Logback 和 slf4j。 目前我无法在日志文件中显示未捕获的异常(例如 NullPointers
这似乎是一个粗心错误,但我似乎找不到原因。使用 logback/slf4j 进行日志记录(最新版本 slf4j-api-1.6.1、logback core/classic 0.9.24)。用于测试的
我需要能够在事件中搜索多种模式中的任何一种,并用屏蔽值替换模式中的文本。这是我们应用程序中的一项功能,旨在防止敏感信息落入日志中。由于信息可能来自多种来源,因此对所有输入应用过滤器是不切实际的。此外,
我怎样才能创建一个 RollingFileAppender在接受谨慎标志的 Logback 中,还允许我指定日志文件的位置? 我尝试了以下操作,但正如我从文档中了解到的,logback 不支持 fil
我在文档中看不到任何相关内容,但收到以下异常 Failed to instantiate [ch.qos.logback.classic.LoggerContext] Reported excepti
我是 Logback 的新手,我正在尝试为 Windows 和 Linux 动态添加带有属性文件的文件路径。 这是我拥有的代码 sinppet,我怎样才能获得 ${MY_HOME} 的值 $
由于我必须登录到自定义(单个)数据库表,我编写了一个自定义 logback appender,扩展了 logback DBAppender . 我有一些单元测试来验证 appender 是否正常工作,
我正在尝试在 micronaut 中设置访问日志,但是,由于 logback-access 库使用 servlet 过滤器,我没有看到直接的方法。有不同的解决方案吗?一些隐藏的 Micronaut 配
我想使用 slf4j+logback 来登录 JBossAS7。 此外,我必须解决以下要求: 我需要在多个已部署的应用程序/EAR 中共享一个 logback 配置/上下文 我需要在运行时更改 log
我已经使用 LogbackValve 为 Tomcat 7.0 启用了 logback-access 日志。我的 logback-access 配置如下所示。 access.lo
我正在开发一个应用程序,使用我的另一个项目作为 Maven 依赖项。 期望 我希望我的依赖项使用自己的 logback.xml 来登录自己的文件。我希望应用程序使用自己的 logback.xml 文件
我在给定的 tomcat 中运行了许多相同的应用程序,它们都在不同的 URL 和 web.xml 文件下。 我想为每个文件创建一个相同的logback.xml。但我希望模式中包含服务器名称或显示名称。
它正在输出到控制台。logger.info("你好,世界信息。");//工作得很好... 但是以下代码返回“无法找到资源”错误: Logger logger = LoggerFactory.getLo
我是一名优秀的程序员,十分优秀!