pino-email-transport
v0.2.1
Published
Pino transport to send logs via email (SMTP)
Downloads
234
Maintainers
Readme
pino-email-transport
Pino transport to send logs via email (SMTP) using nodemailer.
Installation
npm install pino-email-transportUsage
import pino from "pino";
import emailTransport from "pino-email-transport";
const transport = await emailTransport({
smtpFrom: { name: "My App", address: "[email protected]" },
smtpHost: "smtp.example.com",
smtpPort: 587,
smtpUser: "user",
smtpPass: "pass",
debug: false,
logger: false,
sendTo: "[email protected]",
// Optional: Flush every 30 seconds
flushInterval: 30000,
// Optional: Flush when 10 emails are pending
flushThreshold: 10,
});
const logger = pino({
transport: {
targets: [
{
target: "pino/file",
level: "info",
},
{
target: "pino-email-transport",
level: "info",
options: {
smtpFrom: { name: "My App", address: "[email protected]" },
smtpHost: "smtp.example.com",
smtpPort: 587,
smtpUser: "user",
smtpPass: "pass",
debug: false,
logger: false,
sendTo: "[email protected]",
// Optional: Flush every 30 seconds
flushInterval: 30000,
// Optional: Flush when 10 emails are pending
flushThreshold: 10,
},
},
],
},
});Options
smtpFrom: string or{ name?: string; address: string }smtpHost: stringsmtpPort: numbersmtpUser: stringsmtpPass: stringdebug: booleanlogger: booleansendTo: string | string[]flushInterval(optional): number - Flush interval in milliseconds. If set, pending email tasks will be flushed periodically. Set to0orundefinedto disable periodic flushing. Default:undefined(disabled)flushThreshold(optional): number - Maximum number of pending email tasks before triggering an automatic flush. Set to0to disable threshold-based flushing. Default:50
Notes
- This transport formats content with
pino-pretty(no colors) and puts the level in the email subject. - It waits for all send operations to complete on close (Promise.allSettled).
- Memory leak prevention: By default,
flushThresholdis set to50to automatically flush when 50 email tasks are pending. For long-running processes, you can also configureflushIntervalfor periodic flushing. SetflushThresholdto0to disable automatic flushing (not recommended for long-running processes).
