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

logback prudent, SiftingAppender, layout, encoder的使用

    博客分类:
  • Java
阅读更多
1. 将prudent设置为true 是为了支持多个JVM往同一个日志文件写日志.

参考http://logback.qos.ch/manual/appenders.html#FileAppender里面的prudent描述 

prudent
In prudent mode, FileAppender will safely write to the specified file, even in the presence of other FileAppender instances running in different JVMs, potentially running on different hosts. The default value for prudent mode is false.
Prudent mode can be used in conjunction with RollingFileAppender although some restrictions apply.

Prudent mode implies that append property is automatically set to true.

Prudent more relies on exclusive file locks. Experiments show that file locks approximately triple (x3) the cost of writing a logging event. On an "average" PC writing to a file located on a local hard disk, when prudent mode is off, it takes about 10 microseconds to write a single logging event. When prudent mode is on, it takes approximately 30 microseconds to output a single logging event. This translates to logging throughput of 100'000 events per second when prudent mode is off and approximately 33'000 events per second in prudent mode.

Prudent mode effectively serializes I/O operations between all JVMs writing to the same file. Thus, as the number of JVMs competing to access a file increases so will the delay incurred by each I/O operation. As long as the total number of I/O operations is in the order of 20 log requests per second, the impact on performance should be negligible. Applications generating 100 or more I/O operations per second can see an impact on performance and should avoid using prudent mode.

NETWORKED FILE LOCKS When the log file is located on a networked file system, the cost of prudent mode is even greater. Just as importantly, file locks over a networked file system can be sometimes strongly biased such that the process currently owning the lock immediately re-obtains the lock upon its release. Thus, while one process hogs the lock for the log file, other processes starve waiting for the lock to the point of appearing deadlocked.

The impact of prudent mode is highly dependent on network speed as well as the OS implementation details. We provide an very small application called FileLockSimulator which can help you simulate the behavior of prudent mode in your environment.


2. SiftingAppender: logging different threads to different log files
http://www.nurkiewicz.com/2013/04/siftingappender-logging-different.html


Encoder and Layout-Pattern.
原文:http://logback.qos.ch/codes.html#layoutInsteadOfEncoder
This appender no longer admits a layout as a sub-component, set an encoder instead.

As of logback version 0.9.19, the WriterAppender class has been renamed as OutputStreamAppender, with FileAppender now sub-classing the latter. OutputStreamAppender and sub-classes now take an Encoder as a sub-component instead of a Layout.

In practical terms, this means that configuration files need to be changed

from (DEPRECATED)

<appender name="FILE" class="ch.qos.logback.core.FileAppender">
  <file>testFile.log</file>
  ...
  <layout class="ch.qos.logback.classic.PatternLayout">
    <pattern>%msg%n</pattern>
  </layout>
</appender>  
or the shorter equivalent (DEPRECATED)

<appender name="FILE" class="ch.qos.logback.core.FileAppender">
  <file>testFile.log</file>
  ...
  <!-- layout are assigned the type ch.qos.logback.classic.PatternLayout by default -->
  <layout>
    <pattern>%msg%n</pattern>
  </layout>
</appender>  
to (GOOD)

<appender name="FILE" class="ch.qos.logback.core.FileAppender">
  <file>testFile.log</file>
  ...
  <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
    <pattern>%msg%n</pattern>
  </encoder>
</appender>  
or the shorter equivalent (GOOD)

<appender name="FILE" class="ch.qos.logback.core.FileAppender">
  <file>testFile.log</file>
  ...
  <!-- encoders are assigned the type
       ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
  <encoder>
    <pattern>%msg%n</pattern>
  </encoder>
</appender>  
For layout type other than PatternLayout, for example HTMLLayout, your configuration files need to be changed

from (DEPRECATED)

<appender name="FILE" class="ch.qos.logback.core.FileAppender">
  <file>testFile.log</file>
  ...
  <layout class="ch.qos.logback.classic.html.HTMLLayout">
    <pattern>%msg%n</pattern>
  </layout>
</appender>
to (GOOD)

<appender name="FILE" class="ch.qos.logback.core.FileAppender">
  <file>testFile.log</file>
  ...
  <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
    <layout class="ch.qos.logback.classic.html.HTMLLayout">
      <pattern>%msg%n</pattern>
    </layout>
  </encoder>
</appender>
We hope to make up for this inconvenience with cool new features which are only possible using encoders. During a transition period, layouts passed as parameter will be automatically wrapped by an encoder so that configuration files in the old format (using a layout instead of encoder) will continue to work unmodified.

分享到:
评论

相关推荐

    logstash-logback-encoder:Logback JSON编码器和附加器

    Logstash Logback编码器 提供编码器,布局和附加程序,以JSON和登录。 支持常规LoggingEvents (通过Logger )和AccessEvents (通过记录)。 最初是为了支持的JSON格式的输出而的,但现在已经演变为针对JSON和...

    logstash-logback-encoder-6.1.jar

    java运行依赖jar包

    logback使用方式简单总结

    Logback 使用 `logback.xml` 文件进行配置。配置文件中,你可以定义日志级别、过滤器、appender 和 layout。例如: ```xml &lt;appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"&gt; &lt;encoder&gt; ...

    logback-1.1.2源码包

    - `ch.qos.logback.classic.encoder` 包含了用于格式化日志消息的 Encoder 类,如 PatternLayoutEncoder。 - `ch.qos.logback.classic.filter` 提供了多种过滤器,如 LevelMatchFilter、DenyAllFilter 等,允许...

    Android-logback-android用于Android的可靠通用快速和灵活的日志记录框架

    `logback-android`提供了多种内置Appender和Layout,例如ConsoleAppender、FileAppender、PatternLayout等。开发者可以根据需求自定义Appender和Layout,实现更复杂的功能。 ### 6. 性能优化 考虑到Android设备的...

    logstash-logback-encoder-4.8.jar

    java运行依赖jar包

    Logback中文文档-实用

    Logback中文文档是一份关于Logback使用和配置的全面指南,它提供了深入的理论知识和实用的API应用,覆盖了Logback的几乎所有重要方面。 在这份文档中,首先介绍了Logback的基础概念。文档解释了什么是Logback,它的...

    logback+springboot的基本使用方式.zip

    3. **layout(布局)配置**:定义日志输出的格式,如`&lt;layout class="ch.qos.logback.classic.PatternLayout"&gt;`,并设置模式 `%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n`,将输出时间戳...

    logback+slf4j使用

    以下是使用logback+slf4j自定义Appender的详细步骤: 1. **创建Appender类**:首先,你需要创建一个继承自`ch.qos.logback.core.AppenderBase&lt;ILoggingEvent&gt;`的类。在这个类中,你需要覆盖`append()`方法,该方法...

    logback的使用和logback.xml详解

    标题"Logback的使用和logback.xml详解"暗示了我们要讨论的是一个日志管理框架——Logback,以及它的配置文件`logback.xml`。Logback是Java社区广泛使用的日志处理系统,由Ceki Gülcü创建,作为Log4j的后继者。它...

    logback所需jar包

    在使用Logback之前,首先需要在项目中引入必要的jar包。根据提供的压缩包文件名"logback所需jar包",我们可以推测这个压缩包包含了Logback运行所需的库文件。通常,这些文件包括`logback-classic.jar`, `logback-...

    logstash-logback-encoder-6.3.jar

    logstash-logback-encoder就是转码后向logstash中输入的依赖

    LogBack日志的使用

    在使用LogBack时,需要引入对应的jar包。主要依赖包括`logback-classic`、`logback-core`和`slf4j-api`。`logback-classic`是实现SLF4J接口的具体日志实现,`logback-core`包含了LogBack的基本功能,而`slf4j-api`则...

    logback下载 日志文件jar包

    Logback 是一款广泛使用的日志记录框架,由 Ceki Gülcü 创建,作为其先前作品 Log4j 的改进版。这个压缩包包含了实现 Logback 功能所需的几个关键组件,以及一个配置文件,使得用户能够方便地管理和记录应用程序的...

    Logback使用

    Logback 使用 Logback 是一个流行的 Java 日志记录组件,由 log4j 的创始人 Ceki Gülcü 设计。Logback 当前分成三个模块:logback-core、logback-classic 和 logback-access。Logback 的核心对象包括 Appender、...

    logback 使用

    本文将深入探讨如何使用 Logback 实现日志打印和输出到指定位置。** 首先,我们需要理解 Logback 的核心组件:`Logger`、`Appender` 和 `Layout`。 1. **Logger**: 这是日志记录的入口点,你可以通过 `Logger` ...

    logback.的jar包

    **日志框架Logback简介** Logback 是一个用于日志记录的开源框架,由 Ceki Gülcü(也是 Log4j 的创始人)设计并开发。...对于开发者而言,理解和掌握 Logback 的使用能够提升应用程序的监控和调试能力。

    logback高级使用例子

    **日志系统的重要性** ...通过深入理解和熟练使用Logback,我们可以优化日志记录,提升问题排查效率,为软件系统的稳定运行保驾护航。`logback-advance-demo`压缩包可能包含了上述功能的实践示例,供学习和参考。

    logback使用方法

    Logback 是一个在 Java 应用程序中广泛使用的日志框架,由 Ceki Gülcü 创建,作为 Log4j 的继任者。它提供高效、灵活的日志记录功能,能够满足各种日志处理需求。本篇文章将详细介绍如何使用 logback,并着重讲解...

    logback文档

    排版(Layout)是决定日志最终输出格式的关键组件,文档中详细解释了什么是Layout,以及如何在logback-classic和logback-access中配置和使用自定义layout。Layout中包括PatternLayout、转换符说明、格式修饰符、求值...

Global site tag (gtag.js) - Google Analytics