Skip to content

How can I overriding the default logger (with logrus or pick your prefered logging library) #551

Answered by bsergean
bsergean asked this question in Q&A
Discussion options

You must be logged in to vote

I figured it out, here's what I did:

Calling the thing:

package mypackage_name
...
clientConfig := torrent.NewDefaultClientConfig()
clientConfig.Logger = GetTorrentLogger()

Override logic

// Override torrent log library with logrus
// See https://github.com/anacrolix/torrent/discussions/551

package mypackage_name

import (
	torrentlog "github.com/anacrolix/log"
	log "github.com/sirupsen/logrus"
)

type LogRusAdapterLogger struct{}

func (l LogRusAdapterLogger) Log(msg torrentlog.Msg) {
	if level, ok := msg.GetLevel(); ok {
		// A "DEBUG" is available, we ignore it as it's very noisy, but we should expose it
		switch level.LogString() {
		case "INFO":
			log.Info("⛲ " + msg.Text())
		cas…

Replies: 4 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@anacrolix
Comment options

Answer selected by anacrolix
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@anacrolix
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants