All Projects → gogap → Logrus_mate

gogap / Logrus_mate

Licence: apache-2.0
tool for logrus, let it easy to use

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Logrus mate

Quicklogger
Library for logging on files, console, memory, email, rest, eventlog, syslog, slack, telegram, redis, logstash, elasticsearch, influxdb, graylog, Sentry, Twilio, ide debug messages and throw events for Delphi/Firemonkey/freepascal/.NET (Windows/Linux/OSX/IOS/Android).
Stars: ✭ 137 (-7.43%)
Mutual labels:  logstash, logger, graylog
ink
A Logger backend that logs JSON
Stars: ✭ 64 (-56.76%)
Mutual labels:  logstash, logger
Logstash Gelf
Graylog Extended Log Format (GELF) implementation in Java for all major logging frameworks: log4j, log4j2, java.util.logging, logback, JBossAS7 and WildFly 8-12
Stars: ✭ 360 (+143.24%)
Mutual labels:  logstash, graylog
Chipmunk
log analysis tool
Stars: ✭ 247 (+66.89%)
Mutual labels:  logstash, logger
Logger logstash backend
Logstash backend for the Elixir Logger
Stars: ✭ 67 (-54.73%)
Mutual labels:  logstash, logger
Discord Bot
A discord bot that can play music, moderate, log events and more
Stars: ✭ 127 (-14.19%)
Mutual labels:  logger
Elastic Stack
Aprenda Elasticsearch, Logstash, Kibana e Beats do jeito mais fácil ⭐️
Stars: ✭ 135 (-8.78%)
Mutual labels:  logstash
Egg Logger
Egg logger
Stars: ✭ 127 (-14.19%)
Mutual labels:  logger
Docker Elk
The Elastic stack (ELK) powered by Docker and Compose.
Stars: ✭ 12,327 (+8229.05%)
Mutual labels:  logstash
Plug logger json
Elixir Plug that formats http request logs as json
Stars: ✭ 125 (-15.54%)
Mutual labels:  logger
Logdna Agent
LogDNA Agent streams from log files to your LogDNA account. Works with Linux, Windows, and macOS Servers
Stars: ✭ 134 (-9.46%)
Mutual labels:  logger
Vagrant Elastic Stack
Giving the Elastic Stack a try in Vagrant
Stars: ✭ 131 (-11.49%)
Mutual labels:  logstash
Elk Hole
elasticsearch, logstash and kibana configuration for pi-hole visualiziation
Stars: ✭ 136 (-8.11%)
Mutual labels:  logstash
Easylogger
An ultra-lightweight(ROM<1.6K, RAM<0.3k), high-performance C/C++ log library. | 一款超轻量级(ROM<1.6K, RAM<0.3k)、高性能的 C/C++ 日志库
Stars: ✭ 1,968 (+1229.73%)
Mutual labels:  logger
Logstash Filter Verifier
Stars: ✭ 143 (-3.38%)
Mutual labels:  logstash
Docker Logger
Logs collector for docker
Stars: ✭ 126 (-14.86%)
Mutual labels:  logger
Structured Log
A JavaScript implementation of Serilog's hybrid text/structured logging
Stars: ✭ 133 (-10.14%)
Mutual labels:  logger
Ansible Role Logstash
Ansible Role - Logstash
Stars: ✭ 136 (-8.11%)
Mutual labels:  logstash
Documentation
Stars: ✭ 133 (-10.14%)
Mutual labels:  graylog
Android Remote Debugger
A library for remote logging, database debugging, shared preferences and network requests
Stars: ✭ 132 (-10.81%)
Mutual labels:  logger

Logrus Mate :walrus:

Logrus mate is a tool for Logrus, it will help you to initial logger by config, including Formatter, HookLevel and Output .

If you more prefer old version, you could checkout tag v1.0.0

Example

Example 1:

Hijack logrus.StandardLogger()

package main

import (
    "github.com/sirupsen/logrus"
    "github.com/gogap/logrus_mate"
)

func main() {
    logrus_mate.Hijack(
        logrus.StandardLogger(),
        logrus_mate.ConfigString(
            `{formatter.name = "json"}`,
        ),
    )
    
    logrus.WithField("Field", "A").Debugln("Hello JSON")
}

Example 2:

Create new logger from mate:

package main

import (
    "github.com/gogap/logrus_mate"
)

func main() {
    mate, _ := logrus_mate.NewLogrusMate(
        logrus_mate.ConfigString(
            `{ mike {formatter.name = "json"} }`,
        ),
    )
    
    mikeLoger := mate.Logger("mike")
    mikeLoger.Errorln("Hello Error Level from Mike and my formatter is json")
}

Example 3:

Hi jack logger by mate

package main

import (
    "github.com/sirupsen/logrus"
    "github.com/gogap/logrus_mate"
)

func main() {
    mate, _ := logrus_mate.NewLogrusMate(
        logrus_mate.ConfigString(
            `{ mike {formatter.name = "json"} }`,
        ),
    )

    mate.Hijack(
        logrus.StandardLogger(),
        "mike",
    )
    
    logrus.Println("hello std logger is hijack by mike")
}

Example 4:

Fallback the ConfigString

package main

import (
    "github.com/sirupsen/logrus"
    "github.com/gogap/logrus_mate"
)

func main() {
    mate, _ := logrus_mate.NewLogrusMate(
        logrus_mate.ConfigString(
            `{ mike {formatter.name = "json"} }`,
        ),
        logrus_mate.ConfigFile(
            "mate.conf", // { mike {formatter.name = "text"} }
        ),
    )

    mate.Hijack(
        logrus.StandardLogger(),
        "mike",
    )
    
    logrus.Println("hello std logger is hijack by mike")
}

the json formatter is used

Example 5:

Fallback config while hijack

package main

import (
    "github.com/sirupsen/logrus"
    "github.com/gogap/logrus_mate"
)

func main() {
    mate, _ := logrus_mate.NewLogrusMate(
        logrus_mate.ConfigFile(
            "mate.conf", // { mike {formatter.name = "text"} }
        ),
    )

    mate.Hijack(logrus.StandardLogger(),
        "mike",
        logrus_mate.ConfigString(
            `{formatter.name = "json"}`,
        ),
    )

    logrus.Errorln("hello std logger is hijack by mike")
}

the json formatter is used

currently we are using https://github.com/go-akka/configuration for logger config, it will more powerful config format for human read, you also could set your own config provider

Hooks

Hook Options
Airbrake project-id api-key env
Syslog network address priority tag
BugSnag api-key
Slackrus url levels channel emoji username
Graylog address facility extra
Mail app-name host port from to username password
File filename max-lines max-size daily max-days rotate level
BearyChat url levels channel user markdown async
LFSHook path-map { error = "logs/error.log" ... }
sls README

When we need use above hooks, we need import these package as follow:

import _ "github.com/gogap/logrus_mate/hooks/syslog"
import _ "github.com/gogap/logrus_mate/hooks/mail"

If you want write your own hook, you just need todo as follow:

package myhook

import (
    "github.com/gogap/logrus_mate"
)

type MyHookConfig struct {
    Address  string
}

func init() {
    logrus_mate.RegisterHook("myhook", NewMyHook)
}

func NewMyHook(config logrus_mate.Configuration) (hook logrus.Hook, err error) {
    conf := MyHookConfig{}
    if config!=nil {
        conf.Address = config.GetString("address")
    }

    // write your hook logic code here

    return
}

Formatters

internal formatters:

Formatter Options Output Example
null
text force-colors disable-colors disable-timestamp full-timestamp timestamp-format disable-sorting DEBU[0000] Hello Default Logrus Mate
json timestamp-format {"level":"info","msg":"Hello, I am A Logger from jack","time":"2015-10-18T21:24:19+08:00"}

3rd formatters:

Formatter Output Example
logstash [Removed]

When we need use 3rd formatter, we need import these package as follow:

import _ "github.com/gogap/logrus_mate/formatters/xxx"

If you want write your own formatter, you just need todo as follow:

package myformatter

import (
    "github.com/gogap/logrus_mate"
)

type MyFormatterConfig struct {
    Address  string `json:"address"`
}

func init() {
    logrus_mate.RegisterFormatter("myformatter", NewMyFormatter)
}

func NewMyFormatter(config logrus_mate.Configuration) (formatter logrus.Formatter, err error) {
    conf := MyFormatterConfig{}
    if config!=nil {
        conf.Address=config.GetString("address")
    }

    // write your formatter logic code here

    return
}

Writers

internal writers (output):

  • stdout
  • stderr
  • null

3rd writers:

Writer Description
redisio just for demo, it will output into redis, the key type is list
rotatelogs write log to file , configs: clock location link-name rotation-time max-age

When we need use 3rd writer, we need import these package as follow:

import _ "github.com/gogap/logrus_mate/writers/redisio"

If you want write your own writer, you just need todo as follow:

package mywriter

import (
    "io"

    "github.com/gogap/logrus_mate"
)

type MyWriterConfig struct {
    Address  string `json:"address"`
}

func init() {
    logrus_mate.RegisterWriter("mywriter", NewMyWriter)
}

func NewMyWriter(config logrus_mate.Configuration) (writer io.Writer, err error) {
    conf := MyWriterConfig{}
    if config!=nil {
        conf.Address=config.GetString("address")
    }

    // write your writer logic code here

    return
}

Config Provider

The default config provider is HOCON, you could use your own config provider, just implement the following interface{}

type ConfigurationProvider interface {
    LoadConfig(filename string) Configuration
    ParseString(cfgStr string) Configuration
}

type Configuration interface {
    GetBoolean(path string, defaultVal ...bool) bool
    GetByteSize(path string) *big.Int
    GetInt32(path string, defaultVal ...int32) int32
    GetInt64(path string, defaultVal ...int64) int64
    GetString(path string, defaultVal ...string) string
    GetFloat32(path string, defaultVal ...float32) float32
    GetFloat64(path string, defaultVal ...float64) float64
    GetTimeDuration(path string, defaultVal ...time.Duration) time.Duration
    GetTimeDurationInfiniteNotAllowed(path string, defaultVal ...time.Duration) time.Duration
    GetBooleanList(path string) []bool
    GetFloat32List(path string) []float32
    GetFloat64List(path string) []float64
    GetInt32List(path string) []int32
    GetInt64List(path string) []int64
    GetByteList(path string) []byte
    GetStringList(path string) []string
    GetConfig(path string) Configuration
    WithFallback(fallback Configuration)
    HasPath(path string) bool
    Keys() []string
}

set your own config provider

package main

import (
    "github.com/gogap/config"
    "github.com/gogap/logrus_mate"
    "github.com/sirupsen/logrus"
)

func main() {
    mate, _ := logrus_mate.NewLogrusMate(
        logrus_mate.ConfigString(
            `{ mike {formatter.name = "json"} }`,
        ),
        logrus_mate.ConfigFile(
            "mate.conf", // { mike {formatter.name = "text"} }
        ),
        logrus_mate.ConfigProvider(
            &config.HOCONConfigProvider{}, // this is defualt provider if you did not configurate
        ),
    )

    mate.Hijack(
        logrus.StandardLogger(),
        "mike",
    )

    logrus.Println("hello std logger is hijack by mike")
}

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].