Giter VIP home page Giter VIP logo

bobbin's Introduction

Introduction

Bobbin is a high-performance Slf4j-compatible logger designed for multi-threaded applications (especially those with persistent threads like batch, stream and messaging applications).

Bobbin leverages the concept of Logback/Log4j2 sifting appenders while providing much more easier configuration using native Groovy/Java scripting expressions.

Bobbin is available in JCenter repository.

Maven

โ— Note that there is no <type>pom</type>

Example Maven project with Bobbin

...
<repositories>
    <repository>
        <id>jcenter</id>
        <name>jcenter</name>
        <url>https://jcenter.bintray.com</url>
    </repository>
</repositories>
...
<dependency>
    <groupId>io.i-t</groupId>
    <artifactId>bobbin</artifactId>
    <version>4.1.0</version>
</dependency>
...

Gradle

repositories {
    jcenter()
}
dependencies {
    compile "org.codehaus.groovy:groovy-all:2.5.4"
    compile "io.i-t:bobbin:4.1.0"
}

Sample configurations

Examples of Bobbin.yml for different use cases.

General usage

destinations:
  - name: io.infinite.bobbin.config.ConsoleDestinationConfig
    levels: [warn, error, info]
  - name: io.infinite.bobbin.config.FileDestinationConfig
    packages: [io.infinite]
    fileName: ("./LOGS/INFINITE/${className}/${level}/${className}_${level}_${date}.log")
  - name: io.infinite.bobbin.config.FileDestinationConfig
    fileName: ("./LOGS/PACKAGES/${className}/${level}/${className}_${level}_${date}.log")
    format: dateTime + delimiter + level + delimiter + threadName + delimiter + className + delimiter + message

Spring Boot

Logging Spring Boot HTTP with Bobbin

destinations:
  - name: io.infinite.bobbin.config.ConsoleDestinationConfig
    formatThrowable: "%format% + delimiter + throwable"
    levels: [warn, error, info]
  - name: io.infinite.bobbin.config.FileDestinationConfig
    levels: [warn]
    fileName: ("./LOGS/WARNINGS_${date}.log")
  - name: io.infinite.bobbin.config.FileDestinationConfig
    levels: [error]
    fileName: ("./LOGS/ERRORS_${date}.log")
  - name: io.infinite.bobbin.config.FileDestinationConfig
    packages: [org.springframework.web]
    fileName: ("./LOGS/SPRING_WEB/SPRING_WEB_${date}.log")

Logstash

Pass named parameters to Logstash without using MDC (using positioned logging arguments indexes instead).

levels: [info, warn, error, debug]
destinations:
  - name: io.infinite.bobbin.config.ConsoleDestinationConfig
    packages: [com.acme.logstash]
    dateTimeFormat: "yyyy-MM-dd'T'HH:mm:ss:SSSZ"
    lineBreak: ",\r\n"
    formatArgs: |-
      """{
        "@timestamp": "$dateTime",
        "@version": "1",
        "message": "$message",
        "logger_name": "$className",
        "thread_name": "$threadName",
        "level": "$level",
        "username": "${args[0]}",
        "URI": "${args[1]}",
        "sessionId": "${args[2]}",
        "transactionId": "${args[3]}",
        "instanceId": "${MDC.get('instanceUUID')}"
      }"""

MDC and log formatting

Use MDC and change formatting of individual logging signatures - like formatThrowable in this case.

%format% placeholder helps to reuse the base formatting (which itself can be also redefined using format parameter).

format: dateTime + delimiter + MDC.get("instanceUUID") + delimiter + level + delimiter + threadName + delimiter + className + delimiter + message
destinations:
  - name: io.infinite.bobbin.config.ConsoleDestinationConfig
    formatThrowable: "%format% + delimiter + throwable"
    levels: [warn, error, info]
  - name: io.infinite.bobbin.config.FileDestinationConfig
    levels: [warn]
    fileName: ("./LOGS/WARNINGS_${date}.log")
  - name: io.infinite.bobbin.config.FileDestinationConfig
    levels: [error]
    fileName: ("./LOGS/ERRORS_${date}.log")
  - name: io.infinite.bobbin.config.FileDestinationConfig
    packages: [org.springframework.web]
    fileName: ("./LOGS/SPRING_WEB/SPRING_WEB_${date}.log")
  - name: io.infinite.bobbin.config.FileDestinationConfig
    packages: [io.infinite]
    fileName: ("./LOGS/THREADS/${threadGroupName}/${threadName}/${threadName}_${date}.log")
  - name: io.infinite.bobbin.config.FileDestinationConfig
    packages: [conf.plugins.output]
    fileName: ("./LOGS/PLUGINS/OUTPUT/${className}/${className}_${date}.log")
  - name: io.infinite.bobbin.config.FileDestinationConfig
    packages: [conf.plugins.input]
    fileName: ("./LOGS/PLUGINS/INPUT/${className}/${className}_${date}.log")

bobbin's People

Contributors

apryamostanov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

bobbin's Issues

Bug: SLF4J 1.8+ (recent) versions support

The problem:

If we add some dependency with a transitive dependency to "org.slf4j:slf4j-api:1.8.0" and more recent, the Bobbin does not work

Expected behavior:

Logs

Bobbin          : main: Application working dir: /Users/%username%/Desktop/%project%
Bobbin          : main: Searching for Bobbin.yml in: ./Bobbin.yml (full path: /Users/%username%/Desktop/%project%/Bobbin.yml)
Bobbin          : main: Found: /Users/%username%/Desktop/%project%/Bobbin.yml

Actual behavior:

Logs

SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#noProviders for further details.
SLF4J: Class path contains SLF4J bindings targeting slf4j-api versions prior to 1.8.
SLF4J: Ignoring binding found at [jar:file:/Users/%username%/Desktop/%project%/%project%/build/distributions/%project%-1.0.1/lib/bobbin-4.1.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#ignoredBindings for an explanation.

Example Gradle configuration:

build.gradle

def kotlin_version = '1.3.71'
def groovy_version = '2.5.4'
def bobbin_version = '4.1.0'
def textio_version = '3.4.1'
dependencies {
    implementation     "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    implementation     "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"  
    implementation     "org.codehaus.groovy:groovy-all:$groovy_version" 
    implementation     "io.i-t:bobbin:$bobbin_version"  
    // the library below depends on a more recent slf4j artifact  
    implementation     "org.beryx:text-io:$textio_version"  
}

Please, if you have any questions regarding configuration details, leave a comment and I will reply with more information on the problem.

Groovy 2.4.x not working

I imagine this is a Won't Fix but it looks like this doesn't work on groovy 2.4.x (maybe I need to upgrade?). Writing this up just so someone else can find this when searching the repo / google.

Error I get back is

java.lang.NoSuchMethodError: org.codehaus.groovy.runtime.memoize.EvictableCache.getAndPut(Ljava/lang/Object;Lorg/codehaus/groovy/runtime/memoize/MemoizeCache$ValueProvider;)Ljava/lang/Object;

After running

@Grab(group='io.infinite', module='bobbin', version='2.0.0')
import io.infinite.blackbox.BlackBox
import io.infinite.carburetor.CarburetorLevel
@BlackBox(level = CarburetorLevel.EXPRESSION)
String foobar(String foo) {
    String bar = "bar"
    String foobar = foo + bar
    return foobar
}
foobar("foo")

When running on Groovy 2.4.12

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.