Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Logging Layout and Marker context integration with Scribe #425

Merged
merged 1 commit into from Nov 3, 2020

Conversation

REDNBLACK
Copy link
Contributor

Tofu Logging integration for Scribe

Basically just a copypasta from tofu logback layout and scribe-slf4j with minor changes, bringing Marker context and Args Array support. Made for fun.

Example of logback.xml rewrite into Scribe dsl:

<configuration>
  <appender name="rolling" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>logs/data.log</file>

    <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
      <fileNamePattern>logs/data.%i.log</fileNamePattern>
      <minIndex>0</minIndex>
      <maxIndex>8</maxIndex>
    </rollingPolicy>

    <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
      <maxFileSize>50MB</maxFileSize>
    </triggeringPolicy>

    <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
      <charset>UTF-8</charset>
      <layout class="tofu.logging.ELKLayout"/>
    </encoder>
  </appender>

  <appender name="async" class="ch.qos.logback.classic.AsyncAppender">
    <queueSize>500</queueSize>
    <discardingThreshold>0</discardingThreshold>
    <appender-ref ref="rolling" />
  </appender>

  <logger name="io.netty" level="WARN"/>
  <logger name="com.twitter.finagle" level="WARN"/>

  <statusListener class="ch.qos.logback.core.status.NopStatusListener"/>

  <root level="debug">
    <appender-ref ref="async"/>
  </root>
</configuration>
import java.nio.file.Paths

import scribe.{Level, Logger}
import scribe.writer.FileWriter
import scribe.writer.file.{LogPath, FlushMode}
import scribe.handler.{AsynchronousLogHandler, Overflow}
import scribe.filter
import scribe.filter.{className, level}

import tofu.logging.ELKFormatter

Logger
    .root
    .clearHandlers()
    .clearModifiers()
    .withMinimumLevel(Level.Debug)
    .withHandler(AsynchronousLogHandler(
      maxBuffer = 500,
      overflow  = Overflow.Block,

      writer    = FileWriter()
        .io
        .withFlushMode(FlushMode.AsynchronousFlush(1.second))
        .path(LogPath.simple(
          directory = Paths.get("logs"),
          name = "data.log"
        ))
        .maxLogs(9)
        .maxSize(50_000_000),

      formatter = ELKFormatter.merge,

      modifiers = List(
        filter
          .select(
            className startsWith "com.twitter.finagle",
            className startsWith "io.netty"
          )
          .include(level >= Level.Warn)
      )
    ))
    .replace()

@Odomontois Odomontois added the wip label Oct 29, 2020
@Odomontois Odomontois merged commit 5ece28c into master Nov 3, 2020
@Odomontois Odomontois deleted the scribe-logging branch March 3, 2021 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants