-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
155 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import logger from './logger'; | ||
export { logger }; |
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 |
---|---|---|
@@ -0,0 +1,135 @@ | ||
// import winston | ||
import { createLogger, format, transports } from 'winston'; | ||
|
||
const logger = () => { | ||
const { | ||
combine, timestamp, json, colorize, simple, | ||
} = format; | ||
|
||
// setup logger | ||
const error = createLogger({ | ||
level: 'error', | ||
format: combine( | ||
timestamp({ | ||
format: 'YYYY-MM-DD HH:mm:ss', | ||
}), | ||
json(), | ||
), | ||
defaultMeta: { service: 'user-service' }, | ||
transports: [ | ||
new transports.Console({ | ||
format: combine(colorize(), simple()), | ||
}), | ||
new transports.File({ | ||
filename: 'logs/error.log', | ||
level: 'error', | ||
}), | ||
], | ||
}); | ||
|
||
const warn = createLogger({ | ||
level: 'warn', | ||
format: combine( | ||
timestamp({ | ||
format: 'YYYY-MM-DD HH:mm:ss', | ||
}), | ||
json(), | ||
), | ||
defaultMeta: { service: 'user-service' }, | ||
transports: [ | ||
new transports.Console({ | ||
format: combine(colorize(), simple()), | ||
}), | ||
new transports.File({ | ||
filename: 'logs/warn.log', | ||
level: 'warn', | ||
}), | ||
], | ||
}); | ||
|
||
const info = createLogger({ | ||
level: 'info', | ||
format: combine( | ||
timestamp({ | ||
format: 'YYYY-MM-DD HH:mm:ss', | ||
}), | ||
json(), | ||
), | ||
defaultMeta: { service: 'user-service' }, | ||
transports: [ | ||
new transports.Console({ | ||
format: combine(colorize(), simple()), | ||
}), | ||
new transports.File({ | ||
filename: 'logs/info.log', | ||
level: 'info', | ||
}), | ||
], | ||
}); | ||
|
||
const verbose = createLogger({ | ||
level: 'verbose', | ||
format: combine( | ||
timestamp({ | ||
format: 'YYYY-MM-DD HH:mm:ss', | ||
}), | ||
json(), | ||
), | ||
defaultMeta: { service: 'user-service' }, | ||
transports: [ | ||
new transports.Console({ | ||
format: combine(colorize(), simple()), | ||
}), | ||
new transports.File({ | ||
filename: 'logs/verbose.log', | ||
level: 'verbose', | ||
}), | ||
], | ||
}); | ||
|
||
const debug = createLogger({ | ||
level: 'debug', | ||
format: combine( | ||
timestamp({ | ||
format: 'YYYY-MM-DD HH:mm:ss', | ||
}), | ||
json(), | ||
), | ||
defaultMeta: { service: 'user-service' }, | ||
transports: [ | ||
new transports.Console({ | ||
format: combine(colorize(), simple()), | ||
}), | ||
new transports.File({ | ||
filename: 'logs/debug.log', | ||
level: 'debug', | ||
}), | ||
], | ||
}); | ||
|
||
const silly = createLogger({ | ||
level: 'silly', | ||
format: combine( | ||
timestamp({ | ||
format: 'YYYY-MM-DD HH:mm:ss', | ||
}), | ||
json(), | ||
), | ||
defaultMeta: { service: 'user-service' }, | ||
transports: [ | ||
new transports.Console({ | ||
format: combine(colorize(), simple()), | ||
}), | ||
new transports.File({ | ||
filename: 'logs/silly.log', | ||
level: 'silly', | ||
}), | ||
], | ||
}); | ||
const winstonLogger = { | ||
error, warn, info, verbose, debug, silly, | ||
}; | ||
return winstonLogger; | ||
}; | ||
|
||
export default logger; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
{"message":"This is a debug message","level":"debug","service":"user-service","timestamp":"2019-05-01 16:37:39"} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
{"message":"This is an error message","level":"error","service":"user-service","timestamp":"2019-05-01 16:37:39"} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{"message":"Db connected successfully","level":"info","service":"user-service","timestamp":"2019-05-01 16:37:39"} | ||
{"message":"App running on port 5000","level":"info","service":"user-service","timestamp":"2019-05-01 16:37:39"} |
Empty file.
Empty file.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
{"message":"This is a warning message","level":"warn","service":"user-service","timestamp":"2019-05-01 16:37:39"} |
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