Click here to Skip to main content
15,886,810 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am learning by myself how to use node js express and pino for logger, but What should I do if the logger throws an error?
This is my example.


What I have tried:

JavaScript
const express = require("express");
const pino = require("pino");
const ApiServerConfig = require("./apiServerConfig");

const logger = pino({
    level: ApiServerConfig.IS_PRODUCTION ? 'info' : 'debug',
    prettyPrint: true,
    timestamp: true,
})

const app = express();


const initApp = () => {
    app.listen(4000, () => {
        logger.info("server up in port 4000") // if this function throw error, what should I do?
    })
}

initApp();
Posted
Comments
[no name] 1-Apr-21 12:41pm    
Add an error handler / fix the error.

https://stackify.com/node-js-error-handling/
the_nanometer 1-Apr-21 13:24pm    
yes I know but,
how do I do that
without having to leave the normal flow of execution of my application?
i need use try catch to prevent error?

[no name] 1-Apr-21 23:45pm    
You should create a wrapper for the logger; then wrap any further calls (i.e. to the actual logger) in a "try catch". Your regular flow doesn't get interrupted
the_nanometer 2-Apr-21 10:56am    
OK thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900