Install the @logtail/pino npm package:
Set up the Pino logger with the Better Stack transport:
Use the Pino logger as usual:
You should see your logs in Better Stack β Live tail.
The @logtail/pino transport supports Pino v7 and above.
Pino lets you define your own levels with its customLevels option. On Pino 8.21 and newer, those levels reach Better Stack under their own names. On older versions, a custom number falls back to the nearest default level, so pass the same levels to the transport's customLevels option to keep their names:
The transport's customLevels option also accepts a comma-separated string, "notice:35,critical:55", and takes precedence over the names Pino reports, so you can send different names to Better Stack than the ones you use in your code.
The Pino transport sends logs from a worker thread, which serverless platforms like AWS Lambda freeze as soon as your handler returns. Its last logs may never reach Better Stack.
In serverless functions, use LogtailStream instead and flush the logs before the handler returns:
LogtailStream requires @logtail/pino 0.5.12 or newer.
Please let us know at hello@betterstack.com.
We're happy to help! π
Want to learn more about Pino log levels and adding contextual data to your logs?
Check out our Complete Guide to Pino Logging in Node.js.
We use cookies to authenticate users, improve the product user experience, and for personalized ads. Learn more.