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

[PoC] support both logrus logger and entity #188

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

makasim
Copy link

@makasim makasim commented Sep 23, 2019

I am embedding Guerrilla SMTP server into my code and there is a need to pass Logrus Entry as a logger to the daemon. The problem is that HookedLogger accepts a Logger struct so it is not possible to pass Entry. Consider next code

        d := guerrilla.Daemon{}
	if err := d.SetConfig(cfg); err != nil {
		return nil, err
	}

	smtpLogger, err := guerrillaLog.GetLogger(LogFile, LogLevel)
	if err != nil {
		return nil, errors.New("cannot init guerrila logger")
	}

	hookedLogger, ok := smtpLogger.(*guerrillaLog.HookedLogger)
	if !ok {
		return nil, errors.New("guerrila logger must be hooked logger")
	}
	hookedLogger.Logger = logger // logrus.Entry
        // works atm but I lost fields associated with entry
	// hookedLogger.Logger = logger.Logger 
	d.Logger = hookedLogger

	return &Server{
		daemon: &d,
	}, nil

I am going to add tests and fix code review comments if it makes sense to you in general and is going to be merged. Just let me know.

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 this pull request may close these issues.

1 participant