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

How to change default log level #46

Closed
eloo opened this issue Jul 3, 2020 · 3 comments · Fixed by #47
Closed

How to change default log level #46

eloo opened this issue Jul 3, 2020 · 3 comments · Fixed by #47

Comments

@eloo
Copy link

eloo commented Jul 3, 2020

Hi,
i'm just digging around how i can adjust the log level of the bot.

Maybe you can add a simple example how the log-level can be adjusted?

Thanks

@fgrosse
Copy link
Contributor

fgrosse commented Jul 26, 2020

Hey eloo, seems like there is currently no simple option to set the log level but you can create your own logger and then inject it via the joe.WithLogger(…) option.

package main

import (
	"github.com/go-joe/joe"
	"go.uber.org/zap"
)

func main() {
	conf := zap.NewProductionConfig()
	conf.Level = zap.NewAtomicLevelAt(zap.InfoLevel)
	logger, err := conf.Build()
	if err != nil {
		panic(err)
	}

	b := joe.New("example-bot", joe.WithLogger(logger))
	b.Respond("ping", Pong)

	err = b.Run()
	if err != nil {
		b.Logger.Fatal(err.Error())
	}
}

func Pong(msg joe.Message) error {
	msg.Respond("PONG")
	return nil
}

@fgrosse
Copy link
Contributor

fgrosse commented Jul 26, 2020

I implemented a new WithLogLevel(…) option to make it easier to just change the log level without having to worry about the rest of the logger config :)

Also starting with v0.11.0 the default log level is now info (not debug).

@eloo
Copy link
Author

eloo commented Jul 26, 2020

That sounds good.
Thanks a lot!

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

Successfully merging a pull request may close this issue.

2 participants