Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to run example code #2

Open
alannaidon opened this issue Apr 1, 2020 · 0 comments
Open

Unable to run example code #2

alannaidon opened this issue Apr 1, 2020 · 0 comments

Comments

@alannaidon
Copy link

alannaidon commented Apr 1, 2020

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant