Winston logging object

前端 未结 5 1963
轻奢々
轻奢々 2021-02-13 12:23

I use Winston for my backend logging I cannot log the object without using JSON.stringify which is annoying

logger.debug(`Register ${JSON.stringify(         


        
5条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-13 13:01

    You can use format.splat() in your logger config:

    const logger = createLogger({
        format: combine(
            ...
            format.splat(), // <--
            ...
        ),
        ...
    });
    

    ...and log object using string interpolation:

    let myObj = { /* ... */ };
    logger.info('This message will include a complete object: %O', myObj);
    

提交回复
热议问题