From f3793d59484e8ee06a9816fc4a8537cc18ff26dd Mon Sep 17 00:00:00 2001 From: Neil Kalman Date: Tue, 18 May 2021 22:06:17 +0000 Subject: [PATCH] feat(winston): integrate winston logger add @kibibit/nestjs-winston to support logging with winston, and a mock service for the test to disable logging alltogether for the test applications --- package-lock.json | 295 ++++++++++++++++-- package.json | 5 +- server/package.json | 2 +- server/src/app/app.module.ts | 4 + server/src/bootstrap-application.ts | 10 +- server/src/config/__mocks__/winston.config.ts | 15 + server/src/config/config.service.ts | 27 +- server/src/config/index.ts | 1 + server/src/config/winston.config.ts | 80 +++++ server/test-tools/jest.setup.ts | 4 + 10 files changed, 402 insertions(+), 41 deletions(-) create mode 100644 server/src/config/__mocks__/winston.config.ts create mode 100644 server/src/config/winston.config.ts diff --git a/package-lock.json b/package-lock.json index c3cf2a5f..463cba18 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3430,6 +3430,16 @@ "integrity": "sha512-VoNqai1vR5anRF5Tuh/+SWDFk7xi7oMwHrHrbm1BprYXjB2RJsWLhUrStMssDxEl5lW/z3EUdg8RvH/IUBccSQ==", "dev": true }, + "@dabh/diagnostics": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/@dabh/diagnostics/-/diagnostics-2.0.2.tgz", + "integrity": "sha512-+A1YivoVDNNVCdfozHSR8v/jyuuLTMXwjWuxPFlFlUapXoGc+Gj9mDlTDDfrwl7rXCl2tNZ0kE8sIBO6YOn96Q==", + "requires": { + "colorspace": "1.1.x", + "enabled": "2.0.x", + "kuler": "^2.0.0" + } + }, "@eslint/eslintrc": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.3.0.tgz", @@ -3798,6 +3808,18 @@ "resolved": "https://registry.npmjs.org/@kibibit/kb-error/-/kb-error-1.0.3.tgz", "integrity": "sha512-uA4slhd0M75M6VHXGQmz02sHL3NMPvCXxaJRCL5WKHiztsvDgWTs+XezVt9UkKZwiNeWTJWycCxDd9YFIoaERA==" }, + "@kibibit/nestjs-winston": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/@kibibit/nestjs-winston/-/nestjs-winston-0.5.0.tgz", + "integrity": "sha512-3poBqQXdeFaR3ZtUGAxmjaaSJ783b/cYY1z3VAriJRl4xqRq/dZIX3J/qWzMVXUnhx0xilygNInl7n19mkY7DQ==", + "requires": { + "cli-color": "^2.0.0", + "fast-safe-stringify": "^2.0.7", + "json-colorizer": "^2.2.2", + "lodash": "^4.17.21", + "winston": "^3.2.1" + } + }, "@kwsites/file-exists": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/@kwsites/file-exists/-/file-exists-1.1.1.tgz", @@ -8232,7 +8254,6 @@ "version": "3.2.1", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", - "dev": true, "requires": { "color-convert": "^1.9.0" }, @@ -8241,7 +8262,6 @@ "version": "1.9.3", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", - "dev": true, "requires": { "color-name": "1.1.3" } @@ -8249,8 +8269,7 @@ "color-name": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", - "dev": true + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" } } }, @@ -8498,8 +8517,7 @@ "async": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/async/-/async-3.2.0.tgz", - "integrity": "sha512-TR2mEZFVOj2pLStYxLht7TyfuRzaydfpxr3k9RpHIzMgw7A64dzsdqCxH1WJyQdoe8T10nDXd9wnEigmiuHIZw==", - "dev": true + "integrity": "sha512-TR2mEZFVOj2pLStYxLht7TyfuRzaydfpxr3k9RpHIzMgw7A64dzsdqCxH1WJyQdoe8T10nDXd9wnEigmiuHIZw==" }, "async-each": { "version": "1.0.3", @@ -10256,7 +10274,6 @@ "version": "2.4.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", - "dev": true, "requires": { "ansi-styles": "^3.2.1", "escape-string-regexp": "^1.0.5", @@ -10453,6 +10470,26 @@ "integrity": "sha512-y4coMcylgSCdVinjiDBuR8PCC2bLjyGTwEmPb9NHR/QaNU6EUOXcTY/s6VjGMD6ENSEaeQYHCY0GNGS5jfMwPw==", "dev": true }, + "cli-color": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/cli-color/-/cli-color-2.0.0.tgz", + "integrity": "sha512-a0VZ8LeraW0jTuCkuAGMNufareGHhyZU9z8OGsW0gXd1hZGi1SRuNRXdbGkraBBKnhyUhyebFWnRbp+dIn0f0A==", + "requires": { + "ansi-regex": "^2.1.1", + "d": "^1.0.1", + "es5-ext": "^0.10.51", + "es6-iterator": "^2.0.3", + "memoizee": "^0.4.14", + "timers-ext": "^0.1.7" + }, + "dependencies": { + "ansi-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" + } + } + }, "cli-cursor": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz", @@ -10753,7 +10790,6 @@ "version": "1.5.5", "resolved": "https://registry.npmjs.org/color-string/-/color-string-1.5.5.tgz", "integrity": "sha512-jgIoum0OfQfq9Whcfc2z/VhCNcmQjWbey6qBX0vqt7YICflUmBCh9E9CiQD5GSJ+Uehixm3NUwHVhqUAWRivZg==", - "dev": true, "requires": { "color-name": "^1.0.0", "simple-swizzle": "^0.2.2" @@ -10771,6 +10807,39 @@ "integrity": "sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs=", "dev": true }, + "colorspace": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/colorspace/-/colorspace-1.1.2.tgz", + "integrity": "sha512-vt+OoIP2d76xLhjwbBaucYlNSpPsrJWPlBTtwCpQKIu6/CSMutyzX93O/Do0qzpH3YoHEes8YEFXyZ797rEhzQ==", + "requires": { + "color": "3.0.x", + "text-hex": "1.0.x" + }, + "dependencies": { + "color": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/color/-/color-3.0.0.tgz", + "integrity": "sha512-jCpd5+s0s0t7p3pHQKpnJ0TpQKKdleP71LWcA0aqiljpiuAkOSUFN/dyH8ZwF0hRmFlrIuRhufds1QyEP9EB+w==", + "requires": { + "color-convert": "^1.9.1", + "color-string": "^1.5.2" + } + }, + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" + } + } + }, "combined-stream": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", @@ -12246,7 +12315,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/d/-/d-1.0.1.tgz", "integrity": "sha512-m62ShEObQ39CfralilEQRjH6oAMtNCV1xJyEx5LpRYUVN+EviphDgUc/F3hnYbADmkiNs67Y+3ylmlG7Lnu+FA==", - "dev": true, "requires": { "es5-ext": "^0.10.50", "type": "^1.0.1" @@ -12901,6 +12969,11 @@ "integrity": "sha512-/kyM18EfinwXZbno9FyUGeFh87KC8HRQBQGildHZbEuRyWFOmv1U10o9BBp8XVZDVNNuQKyIGIu5ZYAAXJ0V2Q==", "dev": true }, + "enabled": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/enabled/-/enabled-2.0.0.tgz", + "integrity": "sha512-AKrN98kuwOzMIdAizXGI86UFBoo26CL21UM763y1h/GMSJ4/OHU9k2YlsmBpyScFo/wbLzWQJBMCW4+IO3/+OQ==" + }, "encodeurl": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", @@ -13164,7 +13237,6 @@ "version": "0.10.53", "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.53.tgz", "integrity": "sha512-Xs2Stw6NiNHWypzRTY1MtaG/uJlwCk8kH81920ma8mvN8Xq1gsfhZvpkImLQArw8AHnv8MT2I45J3c0R8slE+Q==", - "dev": true, "requires": { "es6-iterator": "~2.0.3", "es6-symbol": "~3.1.3", @@ -13175,7 +13247,6 @@ "version": "2.0.3", "resolved": "https://registry.npmjs.org/es6-iterator/-/es6-iterator-2.0.3.tgz", "integrity": "sha1-p96IkUGgWpSwhUQDstCg+/qY87c=", - "dev": true, "requires": { "d": "1", "es5-ext": "^0.10.35", @@ -13201,12 +13272,22 @@ "version": "3.1.3", "resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.3.tgz", "integrity": "sha512-NJ6Yn3FuDinBaBRWl/q5X/s4koRHBrgKAu+yGI6JCBeiu3qrcbJhwT2GeR/EXVfylRk8dpQVJoLEFhK+Mu31NA==", - "dev": true, "requires": { "d": "^1.0.1", "ext": "^1.1.2" } }, + "es6-weak-map": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/es6-weak-map/-/es6-weak-map-2.0.3.tgz", + "integrity": "sha512-p5um32HOTO1kP+w7PRnB+5lQ43Z6muuMuIMffvDN8ZB4GcnjLBV6zGStpbASIMk4DCAvEaamhe2zhyCb/QXXsA==", + "requires": { + "d": "1", + "es5-ext": "^0.10.46", + "es6-iterator": "^2.0.3", + "es6-symbol": "^3.1.1" + } + }, "escalade": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", @@ -13220,8 +13301,7 @@ "escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", - "dev": true + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" }, "eslint": { "version": "7.19.0", @@ -13647,6 +13727,15 @@ "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=" }, + "event-emitter": { + "version": "0.3.5", + "resolved": "https://registry.npmjs.org/event-emitter/-/event-emitter-0.3.5.tgz", + "integrity": "sha1-34xp7vFkeSPHFXuc6DhAYQsCzDk=", + "requires": { + "d": "1", + "es5-ext": "~0.10.14" + } + }, "eventemitter3": { "version": "4.0.7", "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz", @@ -13803,7 +13892,6 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/ext/-/ext-1.4.0.tgz", "integrity": "sha512-Key5NIsUxdqKg3vIsdw9dSuXpPCQ297y6wBjL30edxwPgt2E44WcWBZey/ZvUc6sERLTxKdyCu4gZFmUbk1Q7A==", - "dev": true, "requires": { "type": "^2.0.0" }, @@ -13811,8 +13899,7 @@ "type": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/type/-/type-2.5.0.tgz", - "integrity": "sha512-180WMDQaIMm3+7hGXWf12GtdniDEy7nYcyFMKJn/eZz/6tSLXrUN9V0wKSbMjej0I1WHWbpREDEKHtqPQa9NNw==", - "dev": true + "integrity": "sha512-180WMDQaIMm3+7hGXWf12GtdniDEy7nYcyFMKJn/eZz/6tSLXrUN9V0wKSbMjej0I1WHWbpREDEKHtqPQa9NNw==" } } }, @@ -13997,6 +14084,11 @@ "pend": "~1.2.0" } }, + "fecha": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/fecha/-/fecha-4.2.1.tgz", + "integrity": "sha512-MMMQ0ludy/nBs1/o0zVOiKTpG7qMbonKUzjJgQFEuvq6INZ1OraKPRAWkBq5vlKLOUMpmNYG1JoN3oDPUQ9m3Q==" + }, "figgy-pudding": { "version": "3.5.2", "resolved": "https://registry.npmjs.org/figgy-pudding/-/figgy-pudding-3.5.2.tgz", @@ -14281,6 +14373,11 @@ "readable-stream": "^2.3.6" } }, + "fn.name": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/fn.name/-/fn.name-1.1.0.tgz", + "integrity": "sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw==" + }, "follow-redirects": { "version": "1.13.1", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.1.tgz", @@ -16115,6 +16212,11 @@ "isobject": "^3.0.1" } }, + "is-promise": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.2.2.tgz", + "integrity": "sha512-+lP4/6lKUBfQjZ2pdxThZvLUAafmZb8OAxFb8XXtiQmS35INgr85hdOGoEs124ez1FCnZJt6jau/T+alh58QFQ==" + }, "is-regex": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.2.tgz", @@ -16134,8 +16236,7 @@ "is-stream": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.0.tgz", - "integrity": "sha512-XCoy+WlUr7d1+Z8GgSuXmpuUFC9fOhRXglJMx+dwLKTkL44Cjd4W1Z5P+BQZpr+cR93aGP4S/s7Ftw6Nd/kiEw==", - "dev": true + "integrity": "sha512-XCoy+WlUr7d1+Z8GgSuXmpuUFC9fOhRXglJMx+dwLKTkL44Cjd4W1Z5P+BQZpr+cR93aGP4S/s7Ftw6Nd/kiEw==" }, "is-string": { "version": "1.0.5", @@ -16762,6 +16863,15 @@ "integrity": "sha1-Wx85evx11ne96Lz8Dkfh+aPZqJg=", "dev": true }, + "json-colorizer": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/json-colorizer/-/json-colorizer-2.2.2.tgz", + "integrity": "sha512-56oZtwV1piXrQnRNTtJeqRv+B9Y/dXAYLqBBaYl/COcUdoZxgLBLAO88+CnkbT6MxNs0c5E9mPBIb2sFcNz3vw==", + "requires": { + "chalk": "^2.4.1", + "lodash.get": "^4.4.2" + } + }, "json-fixer": { "version": "1.6.8", "resolved": "https://registry.npmjs.org/json-fixer/-/json-fixer-1.6.8.tgz", @@ -16952,6 +17062,11 @@ "integrity": "sha512-ZRbnvdg/NxqzC7L9Uyqzf4psi1OM4Cuc+sJAkQPjO6XkQIJTNbfK2Rsmbw8fx1p2mkZdp2FZYo2+LwXYY/uwIA==", "dev": true }, + "kuler": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/kuler/-/kuler-2.0.0.tgz", + "integrity": "sha512-Xq9nH7KlWZmXAtodXDDRE7vs6DU1gTU8zYDHDiWLSip45Egwq3plLHzPn27NgvzL2r1LMPC1vdqh98sQxtqj4A==" + }, "latest-version": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/latest-version/-/latest-version-5.1.0.tgz", @@ -17190,6 +17305,11 @@ "integrity": "sha1-ZHYsSGGAglGKw99Mz11YhtriA0c=", "dev": true }, + "lodash.get": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", + "integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=" + }, "lodash.groupby": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/lodash.groupby/-/lodash.groupby-4.6.0.tgz", @@ -17307,6 +17427,30 @@ } } }, + "logform": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/logform/-/logform-2.2.0.tgz", + "integrity": "sha512-N0qPlqfypFx7UHNn4B3lzS/b0uLqt2hmuoa+PpuXNYgozdJYAyauF5Ky0BWVjrxDlMWiT3qN4zPq3vVAfZy7Yg==", + "requires": { + "colors": "^1.2.1", + "fast-safe-stringify": "^2.0.4", + "fecha": "^4.2.0", + "ms": "^2.1.1", + "triple-beam": "^1.3.0" + }, + "dependencies": { + "colors": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz", + "integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==" + }, + "ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + } + } + }, "loglevel": { "version": "1.7.1", "resolved": "https://registry.npmjs.org/loglevel/-/loglevel-1.7.1.tgz", @@ -17341,6 +17485,14 @@ "yallist": "^4.0.0" } }, + "lru-queue": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/lru-queue/-/lru-queue-0.1.0.tgz", + "integrity": "sha1-Jzi9nw089PhEkMVzbEhpmsYyzaM=", + "requires": { + "es5-ext": "~0.10.2" + } + }, "macos-release": { "version": "2.4.1", "resolved": "https://registry.npmjs.org/macos-release/-/macos-release-2.4.1.tgz", @@ -17561,6 +17713,28 @@ "fs-monkey": "1.0.3" } }, + "memoizee": { + "version": "0.4.15", + "resolved": "https://registry.npmjs.org/memoizee/-/memoizee-0.4.15.tgz", + "integrity": "sha512-UBWmJpLZd5STPm7PMUlOw/TSy972M+z8gcyQ5veOnSDRREz/0bmpyTfKt3/51DhEBqCZQn1udM/5flcSPYhkdQ==", + "requires": { + "d": "^1.0.1", + "es5-ext": "^0.10.53", + "es6-weak-map": "^2.0.3", + "event-emitter": "^0.3.5", + "is-promise": "^2.2.2", + "lru-queue": "^0.1.0", + "next-tick": "^1.1.0", + "timers-ext": "^0.1.7" + }, + "dependencies": { + "next-tick": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.1.0.tgz", + "integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==" + } + } + }, "memory-fs": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/memory-fs/-/memory-fs-0.4.1.tgz", @@ -18377,8 +18551,7 @@ "next-tick": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz", - "integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw=", - "dev": true + "integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw=" }, "nice-try": { "version": "1.0.5", @@ -22493,6 +22666,14 @@ "wrappy": "1" } }, + "one-time": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/one-time/-/one-time-1.0.0.tgz", + "integrity": "sha512-5DXOiRKwuSEcQ/l0kGCF6Q3jcADFv5tSmRaJck/OqkVFcOzutB134KRSfF0xDrL39MNnqxbHBbUUcjZIhTgb2g==", + "requires": { + "fn.name": "1.x.x" + } + }, "onetime": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz", @@ -27148,7 +27329,6 @@ "version": "0.2.2", "resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz", "integrity": "sha1-pNprY1/8zMoz9w0Xy5JZLeleVXo=", - "dev": true, "requires": { "is-arrayish": "^0.3.1" }, @@ -27156,8 +27336,7 @@ "is-arrayish": { "version": "0.3.2", "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.3.2.tgz", - "integrity": "sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==", - "dev": true + "integrity": "sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==" } } }, @@ -27804,6 +27983,11 @@ "integrity": "sha512-ji9qxRnOVfcuLDySj9qzhGSEFVobyt1kIOSkj1qZzYLzq7Tos/oUUWvotUPQLlrsidqsK6tBH89Bc9kL5zHA6w==", "dev": true }, + "stack-trace": { + "version": "0.0.10", + "resolved": "https://registry.npmjs.org/stack-trace/-/stack-trace-0.0.10.tgz", + "integrity": "sha1-VHxws0fo0ytOEI6hoqFZ5f3eGcA=" + }, "stack-utils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/stack-utils/-/stack-utils-2.0.3.tgz", @@ -28304,7 +28488,6 @@ "version": "5.5.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "dev": true, "requires": { "has-flag": "^3.0.0" }, @@ -28312,8 +28495,7 @@ "has-flag": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", - "dev": true + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=" } } }, @@ -28718,6 +28900,11 @@ "integrity": "sha512-wiBrwC1EhBelW12Zy26JeOUkQ5mRu+5o8rpsJk5+2t+Y5vE7e842qtZDQ2g1NpX/29HdyFeJ4nSIhI47ENSxlQ==", "dev": true }, + "text-hex": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/text-hex/-/text-hex-1.0.0.tgz", + "integrity": "sha512-uuVGNWzgJ4yhRaNSiubPY7OjISw4sw4E5Uv0wbjp+OzcbmVU/rsT8ujgcXJhn9ypzsgr5vlzpPqP+MBBKcGvbg==" + }, "text-table": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", @@ -28755,6 +28942,15 @@ "setimmediate": "^1.0.4" } }, + "timers-ext": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/timers-ext/-/timers-ext-0.1.7.tgz", + "integrity": "sha512-b85NUNzTSdodShTIbky6ZF02e8STtVVfD+fu4aXXShEELpozH+bCpJLYMPZbsABN2wDH7fJpqIoXxJpzbf0NqQ==", + "requires": { + "es5-ext": "~0.10.46", + "next-tick": "1" + } + }, "timsort": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/timsort/-/timsort-0.3.0.tgz", @@ -28905,6 +29101,11 @@ "integrity": "sha1-yy4SAwZ+DI3h9hQJS5/kVwTqYAM=", "dev": true }, + "triple-beam": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/triple-beam/-/triple-beam-1.3.0.tgz", + "integrity": "sha512-XrHUvV5HpdLmIj4uVMxHggLbFSZYIn7HEWsqePZcI50pco+MPqJ50wMGY794X7AOOhxOBAjbkqfAbEe/QMp2Lw==" + }, "ts-node": { "version": "9.1.1", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-9.1.1.tgz", @@ -29069,8 +29270,7 @@ "type": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/type/-/type-1.2.0.tgz", - "integrity": "sha512-+5nt5AAniqsCnu2cEQQdpzCAh33kVx8n0VoFidKpB1dVVLAN/F+bgVOqOJqOnEnrhp222clB5p3vUlD+1QAnfg==", - "dev": true + "integrity": "sha512-+5nt5AAniqsCnu2cEQQdpzCAh33kVx8n0VoFidKpB1dVVLAN/F+bgVOqOJqOnEnrhp222clB5p3vUlD+1QAnfg==" }, "type-check": { "version": "0.4.0", @@ -30729,6 +30929,43 @@ } } }, + "winston": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/winston/-/winston-3.3.3.tgz", + "integrity": "sha512-oEXTISQnC8VlSAKf1KYSSd7J6IWuRPQqDdo8eoRNaYKLvwSb5+79Z3Yi1lrl6KDpU6/VWaxpakDAtb1oQ4n9aw==", + "requires": { + "@dabh/diagnostics": "^2.0.2", + "async": "^3.1.0", + "is-stream": "^2.0.0", + "logform": "^2.2.0", + "one-time": "^1.0.0", + "readable-stream": "^3.4.0", + "stack-trace": "0.0.x", + "triple-beam": "^1.3.0", + "winston-transport": "^4.4.0" + }, + "dependencies": { + "readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + } + } + }, + "winston-transport": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/winston-transport/-/winston-transport-4.4.0.tgz", + "integrity": "sha512-Lc7/p3GtqtqPBYYtS6KCN3c77/2QCev51DvcJKbkFPQNoj1sinkGwLGFDxkXY9J6p9+EPnYs+D90uwbnaiURTw==", + "requires": { + "readable-stream": "^2.3.7", + "triple-beam": "^1.2.0" + } + }, "word-wrap": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", diff --git a/package.json b/package.json index 66d50951..9ed20bd6 100644 --- a/package.json +++ b/package.json @@ -115,6 +115,7 @@ "dependencies": { "@kibibit/consologo": "^1.2.0", "@kibibit/kb-error": "^1.0.3", + "@kibibit/nestjs-winston": "0.5.0", "@nestjs/common": "^7.6.11", "@nestjs/core": "^7.6.11", "@nestjs/mongoose": "^7.0.4", @@ -139,8 +140,10 @@ "rimraf": "^3.0.2", "rxjs": "^6.6.3", "smee-client": "^1.2.2", + "bytes": "^3.1.0", "swagger-ui-express": "^4.1.6", - "uuid": "^8.3.2" + "uuid": "^8.3.2", + "winston": "^3.3.3" }, "config": { "commitizen": { diff --git a/server/package.json b/server/package.json index 1af610b6..78343337 100644 --- a/server/package.json +++ b/server/package.json @@ -8,7 +8,7 @@ "scripts": { "prebuild": "rimraf dist", "build": "nest build", - "generate-barrels": "barrelsby --delete -d ./src -l below -q --exclude spec.ts", + "generate-barrels": "barrelsby --delete -d ./src -l below -q --exclude spec.ts --exclude __mocks__", "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", "start": "nest start", "start:dev": "nest start --watch", diff --git a/server/src/app/app.module.ts b/server/src/app/app.module.ts index a94fbd06..84eb9991 100644 --- a/server/src/app/app.module.ts +++ b/server/src/app/app.module.ts @@ -1,6 +1,9 @@ + import { Module } from '@nestjs/common'; import { ScheduleModule } from '@nestjs/schedule'; +import { WinstonModule } from '@kibibit/nestjs-winston'; + import { ApiModule } from '@kb-api'; import { ConfigModule } from '@kb-config'; import { EventsGateway, EventsModule } from '@kb-events'; @@ -10,6 +13,7 @@ import { AppController } from './app.controller'; @Module({ imports: [ + WinstonModule.forRoot({}), ApiModule, ScheduleModule.forRoot(), EventsModule, diff --git a/server/src/bootstrap-application.ts b/server/src/bootstrap-application.ts index 63de1876..30e8698a 100644 --- a/server/src/bootstrap-application.ts +++ b/server/src/bootstrap-application.ts @@ -6,6 +6,7 @@ import { NestExpressApplication } from '@nestjs/platform-express'; import { WsAdapter } from '@nestjs/platform-ws'; import { terminalConsoleLogo } from '@kibibit/consologo'; +import { WINSTON_MODULE_NEST_PROVIDER } from '@kibibit/nestjs-winston'; import { AppModule } from '@kb-app'; import { ConfigService } from '@kb-config'; @@ -17,10 +18,13 @@ const config = new ConfigService(); const appRoot = config.appRoot; export async function bootstrap(): Promise { - terminalConsoleLogo('kibibit server template', [ - 'change this in server/src/bootstrap-application.ts' + terminalConsoleLogo(config.packageDetails.name, [ + `version ${ config.packageDetails.version }` ]); - const app = await NestFactory.create(AppModule); + const app = await NestFactory.create(AppModule, { + logger: false + }); + app.useLogger(app.get(WINSTON_MODULE_NEST_PROVIDER)); app.useWebSocketAdapter(new WsAdapter(app)); app.useGlobalFilters(new KbNotFoundExceptionFilter(appRoot)); app.useGlobalPipes(new ValidationPipe()); diff --git a/server/src/config/__mocks__/winston.config.ts b/server/src/config/__mocks__/winston.config.ts new file mode 100644 index 00000000..6b8f0180 --- /dev/null +++ b/server/src/config/__mocks__/winston.config.ts @@ -0,0 +1,15 @@ + +import winston, { createLogger } from 'winston'; + +import { + winstonInstance +} from '@kibibit/nestjs-winston'; + +winstonInstance.logger = createLogger({ + transports: [ + new winston.transports.Console({ + silent: true, + level: 'debug' + }) + ] +}); diff --git a/server/src/config/config.service.ts b/server/src/config/config.service.ts index 9f0e78ed..b6d19f5b 100644 --- a/server/src/config/config.service.ts +++ b/server/src/config/config.service.ts @@ -13,13 +13,15 @@ import { camelCase, get } from 'lodash'; import nconf from 'nconf'; import SmeeClient from 'smee-client'; -import { Logger } from '@nestjs/common'; +import { WinstonLogger } from '@kibibit/nestjs-winston'; import { ConfigValidationError } from '@kb-errors'; import { ApiInfo } from '@kb-models'; import { AchievibitConfig } from './achievibit-config.model'; +import './winston.config'; + const appRoot = findRoot(__dirname, (dir) => { const packagePath = join(dir, 'package.json'); const isPackageJsonExists = pathExistsSync(packagePath); @@ -34,14 +36,13 @@ const appRoot = findRoot(__dirname, (dir) => { return false; }); const environment = get(process, 'env.NODE_ENV', 'development'); -const eventLogger: Logger = new Logger('SmeeEvents'); -// eslint-disable-next-line @typescript-eslint/no-explicit-any -(eventLogger as any).info = eventLogger.log; const defaultConfigFilePath = join(appRoot, 'defaults.env.json'); const configFilePath = join(appRoot, `${ environment }.env.json`); const packageDetails = new ApiInfo(readJSONSync(join(appRoot, 'package.json'))); +const eventLogger: WinstonLogger = new WinstonLogger('SmeeEvents'); + interface IEvents { close(): void; } @@ -70,7 +71,7 @@ let configService: ConfigService; */ @Exclude() export class ConfigService extends AchievibitConfig { - private logger: Logger = new Logger('ConfigService'); + private logger: WinstonLogger = new WinstonLogger('ConfigService'); private readonly mode: string = environment; @@ -113,12 +114,24 @@ export class ConfigService extends AchievibitConfig { target: `http://localhost:${ this.port }/${ this.webhookDestinationUrl }`, // eslint-disable-next-line @typescript-eslint/no-explicit-any - logger: eventLogger as any + logger: { + error(...data: any[]) { + const message = data.shift(); + console.log(data); + const metadata = data.length ? { data } : undefined; + eventLogger.error(message, metadata); + }, + info(...data: any[]) { + const message = data.shift(); + const metadata = data.length ? { data } : undefined; + eventLogger.info(message, metadata); + } + } }); } if (!events) { - this.logger.log('Starting to listen to events from Proxy'); + // this.logger.log('Starting to listen to events from Proxy'); events = this.smee.start(); } } else { diff --git a/server/src/config/index.ts b/server/src/config/index.ts index 08ee0048..281b9971 100644 --- a/server/src/config/index.ts +++ b/server/src/config/index.ts @@ -6,3 +6,4 @@ export * from './achievibit-config.model'; export * from './config.module'; export * from './config.service'; export * from './json-schema.validator'; +export * from './winston.config'; diff --git a/server/src/config/winston.config.ts b/server/src/config/winston.config.ts new file mode 100644 index 00000000..fa1ed4f1 --- /dev/null +++ b/server/src/config/winston.config.ts @@ -0,0 +1,80 @@ +import { basename } from 'path'; + +import bytes from 'bytes'; +import winston, { createLogger } from 'winston'; + +import { + utilities as nestWinstonModuleUtilities, + winstonInstance +} from '@kibibit/nestjs-winston'; + +const fiveMegaBytes = bytes('5MB'); + +const omitMeta = [ + 'file', + 'env' +]; + +// console.log(Intl.DateTimeFormat().resolvedOptions().timeZone); + +winstonInstance.logger = createLogger({ + transports: [ + new winston.transports.Console({ + level: 'debug', + format: winston.format.combine( + winston.format.timestamp(), + winston.format.ms(), + nestWinstonModuleUtilities.format.nestLike('achievibit', omitMeta), + ) + }), + new winston.transports.File({ + level: 'debug', + filename: '../logs/server.log', + maxsize: fiveMegaBytes, + maxFiles: 5, + tailable: true + }) + ], + exceptionHandlers: [ + new winston.transports.File({ + level: 'debug', + filename: '../logs/exceptions.log', + maxsize: fiveMegaBytes, + maxFiles: 5, + tailable: true + }) + ], + handleExceptions: true, + format: winston.format.combine( + winston.format((info) => { + info.env = process.env.NODE_ENV; + const filename = getCallerFile(); + + if (filename) { + info.file = basename(getCallerFile()); + } + return info; + })(), + winston.format.timestamp(), + winston.format.splat(), + winston.format.json() + ) +}); + +function getCallerFile(): string { + try { + const err = new Error(); + let callerfile; + Error.prepareStackTrace = function (err, stack) { return stack; }; + const currentfile = (err.stack as any).shift().getFileName(); + + while (err.stack.length) { + callerfile = (err.stack as any).shift().getFileName(); + + if (currentfile !== callerfile && + !callerfile.includes('node_modules') && + !callerfile.includes('internal/process')) return callerfile; + } + } catch (err) { } + return ''; +} diff --git a/server/test-tools/jest.setup.ts b/server/test-tools/jest.setup.ts index 221d5a80..45202591 100644 --- a/server/test-tools/jest.setup.ts +++ b/server/test-tools/jest.setup.ts @@ -1,3 +1,7 @@ +import '../src/config/winston.config'; + +jest.mock('../src/config/winston.config'); + const nativeConsoleError = global.console.warn; global.console.warn = (...args) => {