nodemailer / smtp-server

Create custom SMTP servers on the fly
Other
846 stars 145 forks source link

Get Debug and Info #126

Open wosubtil opened 5 years ago

wosubtil commented 5 years ago

Hi,

I need to store the complete transaction log between the SMTP servers. I saw that I have these logs on screen, when I have debug and logger option set to true.

Is there any way to get this same output so that I can be stored in some variable?

xdevnull commented 4 years ago

Nope. You can't.

As you can see https://github.com/nodemailer/nodemailer/blob/master/lib/shared/index.js#L491 The message gets formatted then printed to the console directly.

@andris9 Is there any plans to add onLog(message) to SMTPServer options?

andris9 commented 4 years ago

@xdevnull No plans but PRs are welcomed in that area

dex4er commented 4 years ago

I don't see any point. If you want to have full log stored in files or with custom format, then real bunyan logger object should be used.

xdevnull commented 4 years ago

@dex4er Your suggestion would work. but it requires a good amount of time. To achieve the same formatting as the SMTPServer internal logger, Implementing the correct methods to print the same log.

Instead, Adding onLog() which by default will log messages to the console. Unless you override it. Sounds a better one.

const opts = {
    onLog(level, message) {
        console.log(message)
    }
}