Comments (7)
hi @nigampatel see http://npm.im/pino-arborsculpture
(with thanks to @jsumners for creating it)
from express-pino-logger.
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 log.level = level
.
Note: not the req.logger
. That one exists only for the life time of the request.
from express-pino-logger.
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.
from express-pino-logger.
Can I get a little more info on this?
(I am relatively new to nodejs)
In server.js I:
const pino = require('pino');
const log = pino({ level: process.env.LOG_LEVEL || 'info' });
const expressPino = require('express-pino-logger');
const expressLogger = expressPino({ logger:log });
const app = express();
app.use(expressLogger);
So in "routes\changelevel.js" how would I set
"log.level = level"
@jsumners How do I get access to log from server.js? I am assuming you are talking about the initial instantiation of pino?
-Markus
from express-pino-logger.
I know nothing of Express. But I imagine it is attached to the request like req.log
. So req.log.info('foo')
would log the string "foo" and req.log.level = 'debug'
would change the level to "debug".
from express-pino-logger.
The level change does not persist when using the following:
router.get('/level/:level', async function(req, res) {
req.log.level = req.params.level
res.send(200, 'Update log level to: ' + req.params.level);
});
router.get('/level', async function(req, res) {
res.send(200, 'log level: ' + req.log.level);
});
@nigampatel did you find a way?
Markus
from express-pino-logger.
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 loggingMiddleware.logger.level
.
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.'))
from express-pino-logger.
Related Issues (20)
- why use this instead of pino-http? HOT 1
- express not responding
- What are the differences with pino-http? HOT 3
- Appending to every request. HOT 1
- ignore routes HOT 3
- QUESTION: pino and pino-express HOT 4
- How to find file and line that caused the error? HOT 6
- Unable to redact certain information from existing log files
- Update to Pino 6.x and pino-http 5.x
- Keys added to req/res not available to serializers HOT 5
- Exclude specific URLs from pino logs HOT 2
- Update new pino-http version HOT 2
- How to avoid the entire request being logged every time using pino? HOT 3
- how to filter by http status code HOT 2
- how to log cdn cloudflare ip address? HOT 2
- What is unit of measurement for the responseTime in logs HOT 1
- Clarify this is just a "clone" of pino-http HOT 2
- how to remove this "REQUEST COMPLETED" from pino HOT 1
- Incorrect readme.md example HOT 1
- Upgrade pino-http dependency to 6.0.0 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from express-pino-logger.