Created
July 27, 2018 08:03
-
-
Save chris-peng-1244/ec68abf95b676ee8785bbb8fd6a48535 to your computer and use it in GitHub Desktop.
winston@3.0 customize timestamp
This file contains hidden or 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
| import {createLogger, format, transports } from 'winston'; | |
| const {combine, timestamp, printf } = format; | |
| const myFormat = printf((info, opts) => { | |
| return `${info.time_is_money}: ${info.message}`; | |
| }); | |
| const logger = createLogger({ | |
| format: combine( | |
| timestamp({ | |
| format: 'YYYY-MM-DD HH:mm:ss', | |
| alias: 'time_is_money', | |
| }), | |
| myFormat | |
| ), | |
| transports: [ | |
| new transports.Console(), | |
| ] | |
| }); |
This file contains hidden or 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
| import {createLogger, format, transports } from 'winston'; | |
| const {combine, timestamp, prettyPrint } = format; | |
| import moment from 'moment'; | |
| const logger = createLogger({ | |
| format: combine( | |
| timestamp({ | |
| format: () => { | |
| return moment().format("YYYY-MM-DD HH:mm:ss"); | |
| } | |
| }), | |
| prettyPrint() | |
| ), | |
| transports: [ | |
| new transports.File({ | |
| filename: 'error.log' | |
| }), | |
| ] | |
| }); |
This file contains hidden or 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
| import {createLogger, format, transports } from 'winston'; | |
| const {combine, timestamp, prettyPrint } = format; | |
| const logger = createLogger({ | |
| format: combine( | |
| timestamp({ | |
| format: "YYYY-MM-DD HH:mm:ss" | |
| }), | |
| prettyPrint() | |
| ), | |
| transports: [ | |
| new transports.File({ | |
| filename: 'error.log' | |
| }), | |
| ] | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment