-
Notifications
You must be signed in to change notification settings - Fork 13
Change Log level at runtime #11
Comments
hi @nigampatel see http://npm.im/pino-arborsculpture (with thanks to @jsumners for creating it) |
And if you really want to emulate that Winston wrapper, all you have to do is implement an end point in your application that sets Note: not the |
Thank you for the quick response. I don't have an option to use the pino-arborsculpture. I'll try to see if I can get it work using the log.level approach. |
Can I get a little more info on this? In server.js I:
So in "routes\changelevel.js" how would I set
@jsumners How do I get access to log from server.js? I am assuming you are talking about the initial instantiation of pino? -Markus |
I know nothing of Express. But I imagine it is attached to the request like |
The level change does not persist when using the following:
@nigampatel did you find a way? Markus |
I run into the same problem today. It's a bit late to answer but anyway :) If you want the level change to be persisted, you need to change Here is an example, how you can do it: const express = require('express')
const bodyParser = require('body-parser')
const pinoExpress = require('express-pino-logger')
const app = express()
app.use(bodyParser.json())
const pinoExpressMiddleware = pinoExpress()
app.use(pinoExpressMiddleware)
app.route('/log-level')
// get current log level
.get((req, res) => {
res.json({ level: req.log.level })
})
// update log level
.put((req, res) => {
const newLogLevel = req.body.level
pinoExpressMiddleware.logger.level = newLogLevel
res.json({ status: `Log level changed to ${newLogLevel}` })
})
app.listen(3000, () => console.log('Server started.')) |
Is there a way in pino to change Log level at runtime?
My goal is to create an endpoint where we can change log level without restarting an app.
Similar to this.
https://github.com/yannvr/Winston-dynamic-loglevel
The text was updated successfully, but these errors were encountered: