From c35760d95eecf187ff0cc1cc6a899ef258a27113 Mon Sep 17 00:00:00 2001 From: Jake Date: Thu, 15 Mar 2018 20:58:16 +0000 Subject: [PATCH] Use express logger compatible with nginx --- package-lock.json | 129 +++++++++++++------------------------- package.json | 6 +- src/middleware/logging.ts | 17 ----- src/server.ts | 5 +- 4 files changed, 50 insertions(+), 107 deletions(-) delete mode 100644 src/middleware/logging.ts diff --git a/package-lock.json b/package-lock.json index c99c12c..ec2631c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -77,6 +77,15 @@ "integrity": "sha512-v/lko8AvmTt1K8p+ebdhdiHJE7zpPBYsDKjJSNCl8GwPGkKe5xND7s6M36LKye/USbWSPA7gYCDL0+DZ5h0L6Q==", "dev": true }, + "@types/morgan": { + "version": "1.7.35", + "resolved": "https://registry.npmjs.org/@types/morgan/-/morgan-1.7.35.tgz", + "integrity": "sha512-E9qFi0seOkdlQnCTPv54brNfGWeFdRaEhI5tSue4pdx/V+xfxvMETsxXhOEcj1cYL+0n/jcTEmj/jD2gjzCwMg==", + "dev": true, + "requires": { + "@types/express": "4.11.0" + } + }, "@types/node": { "version": "9.4.0", "resolved": "https://registry.npmjs.org/@types/node/-/node-9.4.0.tgz", @@ -122,11 +131,6 @@ "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", "dev": true }, - "ansi-styles": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-1.0.0.tgz", - "integrity": "sha1-yxAt8cVvUSPquLZ817mAJ6AnkXg=" - }, "array-flatten": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", @@ -144,11 +148,6 @@ "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", "dev": true }, - "async": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/async/-/async-1.0.0.tgz", - "integrity": "sha1-+PwEyjoTeErenhZBr5hXjPvWR6k=" - }, "async-cache": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/async-cache/-/async-cache-1.1.0.tgz", @@ -275,16 +274,6 @@ "check-error": "1.0.2" } }, - "chalk": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-0.4.0.tgz", - "integrity": "sha1-UZmj3c0MHv4jvAjBsCewYXbgxk8=", - "requires": { - "ansi-styles": "1.0.0", - "has-color": "0.1.7", - "strip-ansi": "0.1.1" - } - }, "check-error": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", @@ -306,11 +295,6 @@ "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", "dev": true }, - "colors": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/colors/-/colors-1.0.3.tgz", - "integrity": "sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs=" - }, "combined-stream": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.5.tgz", @@ -456,11 +440,6 @@ "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" }, - "cycle": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/cycle/-/cycle-1.0.3.tgz", - "integrity": "sha1-IegLK+hYD5i0aPN5QwZisEbDStI=" - }, "dasherize": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/dasherize/-/dasherize-2.0.0.tgz", @@ -688,26 +667,12 @@ "ipaddr.js": "1.4.0" } }, - "express-winston": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/express-winston/-/express-winston-2.4.0.tgz", - "integrity": "sha1-J6ts2TBT4t/cNbzuoUoHfcfVLkk=", - "requires": { - "chalk": "0.4.0", - "lodash": "4.11.2" - } - }, "extend": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.1.tgz", "integrity": "sha1-p1Xqe8Gt/MWjHOfnYtuq3F5jZEQ=", "dev": true }, - "eyes": { - "version": "0.1.8", - "resolved": "https://registry.npmjs.org/eyes/-/eyes-0.1.8.tgz", - "integrity": "sha1-Ys8SAjTGg3hdkCNIqADvPgzCC8A=" - }, "fast-safe-stringify": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-1.2.3.tgz", @@ -821,11 +786,6 @@ "ansi-regex": "2.1.1" } }, - "has-color": { - "version": "0.1.7", - "resolved": "https://registry.npmjs.org/has-color/-/has-color-0.1.7.tgz", - "integrity": "sha1-ZxRKUmDDT8PMpnfQQdr1L+e3iy8=" - }, "has-flag": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-1.0.0.tgz", @@ -988,11 +948,6 @@ "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", "dev": true }, - "isstream": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", - "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=" - }, "js-tokens": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz", @@ -1015,11 +970,6 @@ "source-map": "0.5.7" } }, - "lodash": { - "version": "4.11.2", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.11.2.tgz", - "integrity": "sha1-1rQzixEKWOIdrlzrz9u/0rxM2zs=" - }, "lodash._baseassign": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/lodash._baseassign/-/lodash._baseassign-3.2.0.tgz", @@ -1206,6 +1156,41 @@ "resolved": "https://registry.npmjs.org/module-details-from-path/-/module-details-from-path-1.0.3.tgz", "integrity": "sha1-EUyUlnPiqKNenTV4hSeqN7Z52is=" }, + "morgan": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/morgan/-/morgan-1.9.0.tgz", + "integrity": "sha1-0B+mxlhZt2/PMbPLU6OCGjEdgFE=", + "requires": { + "basic-auth": "2.0.0", + "debug": "2.6.9", + "depd": "1.1.2", + "on-finished": "2.3.0", + "on-headers": "1.0.1" + }, + "dependencies": { + "basic-auth": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.0.tgz", + "integrity": "sha1-AV2z81PgLlY3d1X5YnQuiYHnu7o=", + "requires": { + "safe-buffer": "5.1.1" + } + }, + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "requires": { + "ms": "2.0.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + } + } + }, "ms": { "version": "0.7.1", "resolved": "https://registry.npmjs.org/ms/-/ms-0.7.1.tgz", @@ -1441,8 +1426,7 @@ "safe-buffer": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", - "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==", - "dev": true + "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==" }, "semver": { "version": "5.5.0", @@ -1598,11 +1582,6 @@ "resolved": "https://registry.npmjs.org/sql-summary/-/sql-summary-1.0.0.tgz", "integrity": "sha1-OeOlHY2F5Gc5g2/H1n0GVLFzo58=" }, - "stack-trace": { - "version": "0.0.10", - "resolved": "https://registry.npmjs.org/stack-trace/-/stack-trace-0.0.10.tgz", - "integrity": "sha1-VHxws0fo0ytOEI6hoqFZ5f3eGcA=" - }, "stackman": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/stackman/-/stackman-2.0.1.tgz", @@ -1630,11 +1609,6 @@ "safe-buffer": "5.1.1" } }, - "strip-ansi": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-0.1.1.tgz", - "integrity": "sha1-OeipjQRNFQZgq+SmgIrPcLt7yZE=" - }, "strip-bom": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", @@ -1908,19 +1882,6 @@ "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" }, - "winston": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/winston/-/winston-2.3.1.tgz", - "integrity": "sha1-C0hCDZeMAYBM8CMLZIhhWYIloRk=", - "requires": { - "async": "1.0.0", - "colors": "1.0.3", - "cycle": "1.0.3", - "eyes": "0.1.8", - "isstream": "0.1.2", - "stack-trace": "0.0.10" - } - }, "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", diff --git a/package.json b/package.json index 57dddc6..735b806 100644 --- a/package.json +++ b/package.json @@ -33,12 +33,11 @@ "express": "4.15.3", "express-basic-auth": "1.0.1", "express-ip-access-control": "1.0.5", - "express-winston": "2.4.0", "helmet": "3.6.1", + "morgan": "1.9.0", "opbeat": "4.14.0", "open": "0.0.5", - "serve-index": "1.9.0", - "winston": "2.3.1" + "serve-index": "1.9.0" }, "devDependencies": { "@types/chai": "4.1.2", @@ -46,6 +45,7 @@ "@types/express": "4.11.0", "@types/helmet": "0.0.37", "@types/mocha": "2.2.47", + "@types/morgan": "1.7.35", "@types/serve-index": "1.7.29", "chai": "4.0.2", "chai-as-promised": "7.1.1", diff --git a/src/middleware/logging.ts b/src/middleware/logging.ts deleted file mode 100644 index a036dd7..0000000 --- a/src/middleware/logging.ts +++ /dev/null @@ -1,17 +0,0 @@ -import * as expressWinston from 'express-winston'; -import * as winston from 'winston'; - -export default expressWinston.logger({ - colorize: true, - meta: false, - msg: '{{ req.url }} ' - .concat('status:{{ res.statusCode }} ') - .concat('useragent:{{ req.headers["user-agent"] }} ') - .concat('time:{{ res.responseTime }}ms'), - statusLevels: true, - transports: [ - new winston.transports.Console({ - colorize: true - }) - ], -}); diff --git a/src/server.ts b/src/server.ts index 0187abb..2136574 100644 --- a/src/server.ts +++ b/src/server.ts @@ -6,9 +6,8 @@ import * as helmet from 'helmet'; import * as opbeat from 'opbeat'; import * as expectCt from 'expect-ct'; import * as referrerPolicy from 'referrer-policy'; +import * as morgan from 'morgan'; - -import logging from './middleware/logging'; import basicAuthHandler from './middleware/basic-auth'; import { serveIndexHandle, indexHandle, staticFileHandle } from './middleware/static-files'; import handle404 from './middleware/404'; @@ -36,7 +35,7 @@ export default function createServer(opts : Options) : express.Application { } if (process.env.NODE_ENV !== 'test') { - app.use(logging); + app.use(morgan('combined')); } if (opts.allowed_ips.length) {