Last active
February 23, 2021 05:59
-
-
Save manjeshpv/106dc2e05d4b9f252dc9f3f41afccb59 to your computer and use it in GitHub Desktop.
Without Restart Dynamically enable/disable debug in runtime via API [NOT IDEAL if u running pm2 cluster mode]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const debug = require('debug'); | |
const log = debug('namespace1') | |
const express = require('express'); | |
const app = express(); | |
app.get('/', (req, res) => { | |
log('Homepage loading') | |
res.json({ title: 'Homepage' }); | |
}) | |
app.get('/enable', (req, res) => { | |
if(!req.query.tag) return res.json({ | |
message: 'req.query.tag missing' | |
}) | |
// - Enable Debug Namespace | |
debug.enable(req.query.tag); | |
log(`Enabled debug namespace: ${req.query.tag} in runtime`). | |
res.json({ | |
status: debug.enabled(req.query.tag) | |
}) | |
}) | |
app.get('/disable', (req, res) => { | |
log('Disabling debug dynamically in runtime'). | |
debug.disable(); | |
res.json({ status: debug.enabled(req.query.tag || '*') }) | |
}) | |
app.listen(8090, () => { | |
console.log('express listeing at http://localhost:8090') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@yogesum flagr solution looks like solving the issue of