fallais / logrus-lumberjack-hook

Logrus hook for Lumberjack
2 stars 3 forks source link

Unable to run example code #2

Open alannaidon opened 4 years ago

alannaidon commented 4 years ago

Hi! I just started with g Go and I believe your solution May solve my problem.

BUt I'm unable to run the example code you gave.

Code:

package main

import (
    logrus_lumberjack "github.com/fallais/logrus-lumberjack-hook"
    "github.com/natefinch/lumberjack"
    "github.com/rifflock/lfshook"
    "github.com/sirupsen/logrus"
    log "github.com/sirupsen/logrus"
)

// Create new instance of logger.
//var log = logrus.New()

func main() {
    //log.Out = os.Stdout

    pathMap := lfshook.PathMap{
        log.InfoLevel: "/home/alan/Documents/dev/GO Tests/File IO/info/info.log",
        log.WarnLevel: "/home/alan/Documents/dev/GO Tests/File IO/warn/warn.log",
    }

    // Set the Lumberjack logger
    lumberjackLogger := &lumberjack.Logger{
        Filename:   "/var/log/misc.log",
        MaxSize:    10,
        MaxBackups: 3,
        MaxAge:     3,
        LocalTime:  true,
    }
    // Add Lumberjack hook
    hook, err := logrus_lumberjack.NewLumberjackHook(lumberjackLogger)
    if err != nil {
        logrus.Fatalln("Unable to add the Lumberjack hook :", err)
    } else {
        logrus.AddHook(hook)
    }

    myLog := log.New()
    myLog.Hooks.Add(lfshook.NewHook(
        pathMap,
        &log.TextFormatter{},
    ))

    //requestLogger := log.WithFields(log.Fields{"nome": "Name", "sobrenome": "LastName"})
    myLog.WithField("Nome", "Alan").Info("This is an INFO log level.")
    myLog.WithField("Nome", "Alan").Warn("Hello WOrld")

}

The error:

# command-line-arguments
./main.go:31:50: cannot use lumberjackLogger (type *"github.com/natefinch/lumberjack".Logger) as type *"gopkg.in/natefinch/lumberjack.v2".Logger in argument to logrus_lumberjack.NewLumberjackHoo