logconf

package module
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2018 License: Apache-2.0 Imports: 13 Imported by: 0

README

logrus conf

Dependency

dep ensure

Usage

package main

import (
	"flag"
    log "github.com/sirupsen/logrus"
    "github.com/wangxianzhuo/logrus-conf"
)

func main() {
    flag.Parse()
    // auto configure logrus and it's file system hook
    logconf.Configure()

    // print log configs to stdout
    logconf.Configurations()

    // start a log conf admin server
    s := logconf.Server(1)
    s.Start(":9090")

    log.Infof("log file path: %s, line break: %s, segment interval: %d, file name pattern: %s, level: %s", *logconf.FilePath, *logconf.LineBreak, *logconf.SegmentInterval, *logconf.FileNamePattern, *logconf.Level)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	FilePath        = flag.String("log-path", "./logs/", "logrus will store to this path")
	LineBreak       = flag.String("line-break", "\n", "line break")
	SegmentInterval = flag.Int64("segment-interval", 86400, "file segment interval")
	FileNamePattern = flag.String("file-name-pattern", "%YY-%MM-%DD_%HH-%mm-%SS.log", "log file name pattern")
	Level           = flag.String("level", "info", "log level, can be: info, warn, debug, error, fatal, panic")
	Debug           = flag.Bool("debug", false, "debug mode")
	KafkaTopic      = flag.String("log-kafka-topic", "log_msg", "kafka topic for log")
	KafkaBrokers    = flag.String("log-kafka-brokers", "localhost:9092", "kafka brokers for log, it can be like '192.168.1.100:9092,192.168.1.101:9092'")
	ToFileSystem    = flag.Bool("to-file-sys", false, "switch of sending log to local file system")
	ToKafka         = flag.Bool("to-kafka", false, "switch of sending log to kafka")
)

Functions

func Configurations added in v0.0.2

func Configurations()

Configurations print logrus configs to stdout

func Configure

func Configure()

Configure logrus basic represent, log level and add a file hook

func ConfigureKafkaHook added in v0.0.5

func ConfigureKafkaHook()

ConfigureKafkaHook config kafka hook for logrus

func ConfigureLocalFileHook added in v0.0.5

func ConfigureLocalFileHook()

ConfigureLocalFileHook config local file system hook for logrus

func CustomFormatConifgure

func CustomFormatConifgure(formater log.Formatter)

CustomFormatConifgure ...

func LogLevel

func LogLevel(level string)

LogLevel set log level

func PrintConfigs added in v0.0.2

func PrintConfigs(w io.Writer)

PrintConfigs print logrus config to io.writer

Types

type Server added in v0.0.2

type Server int

Server admin server

func (Server) Start added in v0.0.2

func (s Server) Start(address string)

Start server start process

POST /log/level exchange level

query param: level

GET /log/configs print all log configs as json

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL