-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrated most of the logging to winston
- Loading branch information
Showing
7 changed files
with
112 additions
and
107 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,49 @@ | ||
import winston = require('winston'); | ||
import * as winston from 'winston'; | ||
|
||
const timezone = () => { | ||
return new Date().toLocaleString('en-US', { | ||
timeZone: 'America/New_York' | ||
}); | ||
} | ||
|
||
const consoleFormat = (info: winston.Logform.TransformableInfo) => { | ||
return `${[info.timestamp]}: ${info.level}: ${info.message}`; | ||
} | ||
|
||
const fileFormat = (info: winston.Logform.TransformableInfo) => { | ||
let meta = info.metadata; | ||
let timestamp = meta.timestamp | ||
|
||
if (Object.keys(meta).length === 1) { | ||
return `${meta.timestamp}: ${info.level}: ${info.message}`; | ||
} | ||
|
||
delete info.timestamp; | ||
|
||
return `${timestamp}: ${info.level}: ${info.message}\nData:` + JSON.stringify(info.metadata, null, '\t') + '\n'; | ||
} | ||
|
||
export const logger = winston.createLogger({ | ||
level: 'info', | ||
format: winston.format.combine( | ||
winston.format.timestamp({format: 'MMM-DD-YYYY HH:mm:ss'}), | ||
winston.format.align(), | ||
winston.format.printf(info => `${info.level}: ${[info.timestamp]}: ${info.message}`), | ||
), | ||
transports: [ | ||
new winston.transports.Console({ | ||
level: 'error' | ||
level: 'info', | ||
format: winston.format.combine( | ||
winston.format.colorize({ all: true }), | ||
winston.format.timestamp({format: timezone}), | ||
winston.format.prettyPrint(), | ||
winston.format.printf(info => consoleFormat(info)), | ||
) | ||
}), | ||
new winston.transports.File({ | ||
level: 'info', | ||
filename: './logs/ffs.log' | ||
filename: `${__dirname}/logs/ffs.log`, | ||
format: winston.format.combine( | ||
winston.format.timestamp({format: timezone}), | ||
winston.format.metadata(), | ||
winston.format.prettyPrint(), | ||
winston.format.printf(info => fileFormat(info)), | ||
) | ||
}) | ||
] | ||
}); |
Oops, something went wrong.