Categorygithub.com/jiangxin/multi-log
modulepackage
0.3.0
Repository: https://github.com/jiangxin/multi-log.git
Documentation: pkg.go.dev

# README

Multi-log

Travis Build Status

Multi-log is based on logrus, and provides logging in two directions at the same time. One for logging on console and one for file logging.

Usage

Log on console with builtin logger

import "github.com/jiangxin/multi-log"

func main() {
    log.Trace("trace ...")
    log.Debug("debug ...")
    log.Info("info ...")
    log.Warn("warn ...")
    log.Error("error ...")
    log.Fatal("fatal ...")
}

To log on console and file, call Init() first

import "github.com/jiangxin/multi-log"

func main() {
    log.Init(log.Options{
            Quiet: false,
            Verbose: 2,
            LogFile: "/var/log/my-app.log",
            LogLevel: "warn",
    })

    log.Tracef("trace %s", "...")
    log.Debugf("debug %s", "...")
    log.Infof("info %s", "...")
    log.Warningf("info %s", "...")
    log.Errorf("info %s", "...")
    log.Fatalf("info %s", "...")
}

Logging with fields

import (
    "github.com/jiangxin/multi-log"
    "time"
)

func main() {
    logger := log.WithFields(map[string]interface{}{
        "size":   "10MB",
        "period": 2 * time.Minute,
    })

    logger.Traceln("trace", "...")
    logger.Debugln("debug", "...")
    logger.Infoln("info", "...")
    logger.Warnln("warn", "...")
    logger.Errorln("error", "...")
    logger.Panicln("panic", "...")
}

Always show notes on console, unless quiet

import (
    "github.com/jiangxin/multi-log"
)

func main() {
    log.Init(log.Options{
            Quiet: false,
    })

    log.Notef("note %s", "...")
    log.Note("note ", "...")
    log.Noteln("note", "...")

    log.Printf("print %s", "...")
    log.Print("print ", "...")
    log.Println("print", "...")
}

# Packages

No description provided by the author
No description provided by the author

# Functions

Debug is Log with DebugLevel.
Debugf is Logf with DebugLevel.
Debugln is Logln with DebugLevel.
Error is Log with ErrorLevel.
Errorf is Logf with ErrorLevel.
Errorln is Logln with ErrorLevel.
Fatal is Log with FatalLevel.
Fatalf is Logf with FatalLevel.
Fatalln is Logln with FatalLevel.
Info is Log with InfoLevel.
Infof is Logf with InfoLevel.
Infoln is Logln with InfoLevel.
Init must run first to initialize logger.
Log is the base function to show message with specific log level.
Logf is the base function to show message with specific log level.
Logln is the base function to show message with specific log level.
Note will show message on console only if not quiet.
Notef is printf version of Note.
Noteln is println version of Note.
Panic is Log with PanicLevel.
Panicf is Logf with PanicLevel.
Panicln is Logln with PanicLevel.
Print is alias of Note.
Printf is alias of Notef.
Println is alias of Noteln.
Sdebug is sprint with DebugLevel.
Sdebugf is sprint with DebugLevel.
Sdebugln is sprint with DebugLevel.
Serror is sprint with ErrorLevel.
Serrorf is sprint with ErrorLevel.
Serrorln is sprint with ErrorLevel.
Sinfo is sprint with InfoLevel.
Sinfof is sprint with InfoLevel.
Sinfoln is sprint with InfoLevel.
Snote will return the output message to display as note.
Snotef is printf version of Snote.
Snoteln is println version of Snote.
Sprint is alias of Snote.
Sprintf is alias of Snotef.
Sprintln is alias of Snoteln.
Strace is sprint with TraceLevel.
Stracef is sprint with TraceLevel.
Straceln is sprint with TraceLevel.
Swarn is sprint with WarnLevel.
Swarnf is sprint with WarnLevel.
Swarning is alias of Warn.
Swarningf is alias of Warnf.
Swarningln is alias of Swarnln.
Swarnln is sprint with WarnLevel.
Trace is Log with TraceLevel.
Tracef is Logf with TraceLevel.
Traceln is Logln with TraceLevel.
Warn is Log with WarnLevel.
Warnf is Logf with WarnLevel.
Warning is alias of Warn.
Warningf is alias of Warnf.
Warningln is alias of Warnln.
Warnln is Logln with WarnLevel.
WithField writes log with only one field.
WithFields writes log with fields.

# Structs

MultiLogger implements Logger interface.
MultiLoggerWithFields extend MultiLogger with fields.
Options defines options to initial log.

# Interfaces

Logger defines our custom basic logger interface.