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

Logging in hooks creates a deadlock #807

Closed
haeky opened this issue Aug 21, 2018 · 3 comments
Closed

Logging in hooks creates a deadlock #807

haeky opened this issue Aug 21, 2018 · 3 comments

Comments

@haeky
Copy link

haeky commented Aug 21, 2018

GoVersion: 1.10
Version: 1.0.7

How do you create a log from the same level in a hook?

The example below seems to create a deadlock.

main.go

package main

import (
	"fmt"
	"github.com/sirupsen/logrus"
)

func main() {
	logrus.AddHook(NewHook())
	logrus.Info("Something")
}

hook.go

package main

import (
	"github.com/sirupsen/logrus"
)

type testHook struct {
}

func NewHook() *testHook {
	return &testHook{}
}

func (t *testHook) Fire(entry *logrus.Entry) error {
	entry.Logger.Info("Something")

	return nil
}

func (t *testHook) Levels() []logrus.Level {
	return logrus.AllLevels
}
@haeky haeky changed the title Logging in Hooks creates a deadlock. Logging in hooks creates a deadlock Aug 21, 2018
@dgsb
Copy link
Collaborator

dgsb commented Aug 25, 2018

The mutex is used to protect the entry from concurrent access. What are you trying to achieve ? A solution would to perform this log in another goroutine, another would be to use another logger instance. The current implementation does not allow to very easily add a per Entry mutex.

@dgsb
Copy link
Collaborator

dgsb commented Sep 25, 2018

@haeky did you succeed to overcome your issue ?

@stale
Copy link

stale bot commented Feb 26, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants