From 1cada0f34d61a57b0a60bdf2fce0b331473391d8 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Wed, 15 Feb 2017 20:04:46 +0000 Subject: [PATCH] Added logging middleware --- src/middleware/logging.ts | 17 +++++++++++++++++ src/types/fakes.d.ts | 4 +++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/middleware/logging.ts diff --git a/src/middleware/logging.ts b/src/middleware/logging.ts new file mode 100644 index 0000000..c30a728 --- /dev/null +++ b/src/middleware/logging.ts @@ -0,0 +1,17 @@ +import winston from 'winston'; +import expressWinston from 'express-winston'; + +export default expressWinston.logger({ + transports: [ + new winston.transports.Console({ + colorize: true + }) + ], + meta: false, + msg: '{{ req.url }} ' + .concat('status:{{ res.statusCode }} ') + .concat('useragent:{{ req.headers["user-agent"] }} ') + .concat('time:{{ res.responseTime }}ms'), + colorize: true, + statusLevels: true +}); diff --git a/src/types/fakes.d.ts b/src/types/fakes.d.ts index 5089d78..c2a77d8 100644 --- a/src/types/fakes.d.ts +++ b/src/types/fakes.d.ts @@ -2,4 +2,6 @@ declare module 'express-ip-access-control'; declare module 'connect-static-file'; -declare module 'express-basic-auth' +declare module 'express-basic-auth'; +declare module 'winston'; // doesnt like console transport +declare module 'express-winston';