slog

package module
v0.0.0-...-8f14017 Latest Latest
Warning

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

Go to latest
Published: May 15, 2020 License: MIT Imports: 5 Imported by: 10

README

slog

simple logger: a wrapper of logrus

Usage

The first param is the message which you want to output, the rest params should be key-value pairs. This is a simple way to realize the .WithField(key, value) of logrus.

  • supported write logs to file
  • supported log rotation

like below:


package log_test

import (
    log "slog/slog"
    "testing"

    "github.com/sirupsen/logrus"
)

func TestLog(t *testing.T) {

    log.SetLevel(logrus.DebugLevel)

    log.Info("Hello")
    log.Info("Hello", "field", "field value")

    log.Info("Hello", "field1", "field1 value", "field2", 2)

    // set path
    log.SetLogPath("/tmp/test.log")

    // set rotationTime
    log.SetRotationTime(time.Second)
}


Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(msg interface{}, args ...interface{})

Debug level

func Error

func Error(msg interface{}, args ...interface{})

Error level

func Fatal

func Fatal(msg interface{}, args ...interface{})

Fatal level

func Info

func Info(msg interface{}, args ...interface{})

Info level

func SetLevel

func SetLevel(level logrus.Level)

SetLevel set log level

func SetLogPath

func SetLogPath(path string)

SetLogPath set path

func SetRotationTime

func SetRotationTime(rotationTime time.Duration) error

SetRotationTime set rotation time, at least 1 second

func Warn

func Warn(msg interface{}, args ...interface{})

Warn level

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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