From 8b00c12ad9b4df399ff06f867fb7f3bc98f922fb Mon Sep 17 00:00:00 2001 From: zheyanyu Date: Thu, 29 Apr 2021 12:56:27 -0400 Subject: [PATCH 1/4] add winston --- package.json | 4 +- src/index.ts | 1 + src/loggerBuilder.ts | 22 +++++ yarn.lock | 201 +++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 220 insertions(+), 8 deletions(-) create mode 100644 src/loggerBuilder.ts diff --git a/package.json b/package.json index d857108..60260d7 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,9 @@ "local": "node .", "prepublish": "tsc" }, - "dependencies": {}, + "dependencies": { + "winston": "^3.3.3" + }, "devDependencies": { "@types/jest": "^26.0.19", "@types/node": "^12", diff --git a/src/index.ts b/src/index.ts index 23c7b8d..ac43c81 100644 --- a/src/index.ts +++ b/src/index.ts @@ -23,4 +23,5 @@ export * from './errors/UnauthorizedError'; export * from './errors/TooManyConcurrentExportRequestsError'; export * from './errors/InvalidSearchParameterError'; export * from './validator'; +export { getLogger } from './loggerBuilder'; export { stubs } from './stubs'; diff --git a/src/loggerBuilder.ts b/src/loggerBuilder.ts new file mode 100644 index 0000000..b4fea35 --- /dev/null +++ b/src/loggerBuilder.ts @@ -0,0 +1,22 @@ +import { createLogger, format, transports } from 'winston'; + +const { combine, splat, timestamp, printf } = format; + +const myFormat = printf(info => { + let msg = `[${info.level}] : ${info.message} ${info.timestamp} `; + if (info.metadata) { + msg += JSON.stringify(info.metadata); + } + return msg; +}); + +// eslint-disable-next-line import/prefer-default-export +export function getLogger(metadata?: any) { + const logger = createLogger({ + level: 'debug', + format: combine(format.colorize(), splat(), timestamp(), myFormat), + transports: [new transports.Console()], + defaultMeta: metadata, + }); + return logger; +} diff --git a/yarn.lock b/yarn.lock index 3e142ce..9ddb615 100644 --- a/yarn.lock +++ b/yarn.lock @@ -296,6 +296,15 @@ exec-sh "^0.3.2" minimist "^1.2.0" +"@dabh/diagnostics@^2.0.2": + version "2.0.2" + resolved "https://registry.yarnpkg.com/@dabh/diagnostics/-/diagnostics-2.0.2.tgz#290d08f7b381b8f94607dc8f471a12c675f9db31" + integrity sha512-+A1YivoVDNNVCdfozHSR8v/jyuuLTMXwjWuxPFlFlUapXoGc+Gj9mDlTDDfrwl7rXCl2tNZ0kE8sIBO6YOn96Q== + dependencies: + colorspace "1.1.x" + enabled "2.0.x" + kuler "^2.0.0" + "@istanbuljs/load-nyc-config@^1.0.0": version "1.1.0" resolved "https://registry.yarnpkg.com/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz#fd3db1d59ecf7cf121e80650bb86712f9b55eced" @@ -866,6 +875,11 @@ astral-regex@^1.0.0: resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-1.0.0.tgz#6c8c3fb827dd43ee3918f27b82782ab7658a6fd9" integrity sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg== +async@^3.1.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/async/-/async-3.2.0.tgz#b3a2685c5ebb641d3de02d161002c60fc9f85720" + integrity sha512-TR2mEZFVOj2pLStYxLht7TyfuRzaydfpxr3k9RpHIzMgw7A64dzsdqCxH1WJyQdoe8T10nDXd9wnEigmiuHIZw== + asynckit@^0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" @@ -1179,7 +1193,7 @@ collection-visit@^1.0.0: map-visit "^1.0.0" object-visit "^1.0.0" -color-convert@^1.9.0: +color-convert@^1.9.0, color-convert@^1.9.1: version "1.9.3" resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.3.tgz#bb71850690e1f136567de629d2d5471deda4c1e8" integrity sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg== @@ -1198,16 +1212,45 @@ color-name@1.1.3: resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25" integrity sha1-p9BVi9icQveV3UIyj3QIMcpTvCU= -color-name@~1.1.4: +color-name@^1.0.0, color-name@~1.1.4: version "1.1.4" resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== +color-string@^1.5.2: + version "1.5.5" + resolved "https://registry.yarnpkg.com/color-string/-/color-string-1.5.5.tgz#65474a8f0e7439625f3d27a6a19d89fc45223014" + integrity sha512-jgIoum0OfQfq9Whcfc2z/VhCNcmQjWbey6qBX0vqt7YICflUmBCh9E9CiQD5GSJ+Uehixm3NUwHVhqUAWRivZg== + dependencies: + color-name "^1.0.0" + simple-swizzle "^0.2.2" + +color@3.0.x: + version "3.0.0" + resolved "https://registry.yarnpkg.com/color/-/color-3.0.0.tgz#d920b4328d534a3ac8295d68f7bd4ba6c427be9a" + integrity sha512-jCpd5+s0s0t7p3pHQKpnJ0TpQKKdleP71LWcA0aqiljpiuAkOSUFN/dyH8ZwF0hRmFlrIuRhufds1QyEP9EB+w== + dependencies: + color-convert "^1.9.1" + color-string "^1.5.2" + colorette@^1.2.1: version "1.2.2" resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.2.2.tgz#cbcc79d5e99caea2dbf10eb3a26fd8b3e6acfa94" integrity sha512-MKGMzyfeuutC/ZJ1cba9NqcNpfeqMUcYmyF1ZFY6/Cn7CNSAKx6a+s48sqLqyAiZuaP2TcqMhoo+dlwFnVxT9w== +colors@^1.2.1: + version "1.4.0" + resolved "https://registry.yarnpkg.com/colors/-/colors-1.4.0.tgz#c50491479d4c1bdaed2c9ced32cf7c7dc2360f78" + integrity sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA== + +colorspace@1.1.x: + version "1.1.2" + resolved "https://registry.yarnpkg.com/colorspace/-/colorspace-1.1.2.tgz#e0128950d082b86a2168580796a0aa5d6c68d8c5" + integrity sha512-vt+OoIP2d76xLhjwbBaucYlNSpPsrJWPlBTtwCpQKIu6/CSMutyzX93O/Do0qzpH3YoHEes8YEFXyZ797rEhzQ== + dependencies: + color "3.0.x" + text-hex "1.0.x" + combined-stream@^1.0.6, combined-stream@~1.0.6: version "1.0.8" resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f" @@ -1247,7 +1290,7 @@ copy-descriptor@^0.1.0: resolved "https://registry.yarnpkg.com/copy-descriptor/-/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d" integrity sha1-Z29us8OZl8LuGsOpJP1hJHSPV40= -core-util-is@1.0.2: +core-util-is@1.0.2, core-util-is@~1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac= @@ -1445,6 +1488,11 @@ emoji-regex@^8.0.0: resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37" integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A== +enabled@2.0.x: + version "2.0.0" + resolved "https://registry.yarnpkg.com/enabled/-/enabled-2.0.0.tgz#f9dd92ec2d6f4bbc0d5d1e64e21d61cd4665e7c2" + integrity sha512-AKrN98kuwOzMIdAizXGI86UFBoo26CL21UM763y1h/GMSJ4/OHU9k2YlsmBpyScFo/wbLzWQJBMCW4+IO3/+OQ== + end-of-stream@^1.1.0: version "1.4.4" resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-1.4.4.tgz#5ae64a5f45057baf3626ec14da0ca5e4b2431eb0" @@ -1841,6 +1889,11 @@ fast-levenshtein@~2.0.6: resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917" integrity sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc= +fast-safe-stringify@^2.0.4: + version "2.0.7" + resolved "https://registry.yarnpkg.com/fast-safe-stringify/-/fast-safe-stringify-2.0.7.tgz#124aa885899261f68aedb42a7c080de9da608743" + integrity sha512-Utm6CdzT+6xsDk2m8S6uL8VHxNwI6Jub+e9NYTcAms28T84pTa25GJQV9j0CY0N1rM8hK4x6grpF2BQf+2qwVA== + fastq@^1.6.0: version "1.11.0" resolved "https://registry.yarnpkg.com/fastq/-/fastq-1.11.0.tgz#bb9fb955a07130a918eb63c1f5161cc32a5d0858" @@ -1855,6 +1908,11 @@ fb-watchman@^2.0.0: dependencies: bser "2.1.1" +fecha@^4.2.0: + version "4.2.1" + resolved "https://registry.yarnpkg.com/fecha/-/fecha-4.2.1.tgz#0a83ad8f86ef62a091e22bb5a039cd03d23eecce" + integrity sha512-MMMQ0ludy/nBs1/o0zVOiKTpG7qMbonKUzjJgQFEuvq6INZ1OraKPRAWkBq5vlKLOUMpmNYG1JoN3oDPUQ9m3Q== + figures@^3.0.0: version "3.2.0" resolved "https://registry.yarnpkg.com/figures/-/figures-3.2.0.tgz#625c18bd293c604dc4a8ddb2febf0c88341746af" @@ -1915,6 +1973,11 @@ flatted@^2.0.0: resolved "https://registry.yarnpkg.com/flatted/-/flatted-2.0.2.tgz#4575b21e2bcee7434aa9be662f4b7b5f9c2b5138" integrity sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA== +fn.name@1.x.x: + version "1.1.0" + resolved "https://registry.yarnpkg.com/fn.name/-/fn.name-1.1.0.tgz#26cad8017967aea8731bc42961d04a3d5988accc" + integrity sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw== + for-in@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80" @@ -2217,7 +2280,7 @@ inflight@^1.0.4: once "^1.3.0" wrappy "1" -inherits@2: +inherits@2, inherits@^2.0.3, inherits@~2.0.3: version "2.0.4" resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== @@ -2260,6 +2323,11 @@ is-arrayish@^0.2.1: resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d" integrity sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0= +is-arrayish@^0.3.1: + version "0.3.2" + resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.3.2.tgz#4574a2ae56f7ab206896fb431eaeed066fdf8f03" + integrity sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ== + is-bigint@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/is-bigint/-/is-bigint-1.0.1.tgz#6923051dfcbc764278540b9ce0e6b3213aa5ebc2" @@ -2458,7 +2526,7 @@ is-wsl@^2.2.0: dependencies: is-docker "^2.0.0" -isarray@1.0.0, isarray@^1.0.0: +isarray@1.0.0, isarray@^1.0.0, isarray@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11" integrity sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE= @@ -3039,6 +3107,11 @@ kleur@^3.0.3: resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e" integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w== +kuler@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/kuler/-/kuler-2.0.0.tgz#e2c570a3800388fb44407e851531c1d670b061b3" + integrity sha512-Xq9nH7KlWZmXAtodXDDRE7vs6DU1gTU8zYDHDiWLSip45Egwq3plLHzPn27NgvzL2r1LMPC1vdqh98sQxtqj4A== + leven@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/leven/-/leven-3.1.0.tgz#77891de834064cccba82ae7842bb6b14a13ed7f2" @@ -3087,6 +3160,17 @@ lodash@4.x, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.7.0: resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== +logform@^2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/logform/-/logform-2.2.0.tgz#40f036d19161fc76b68ab50fdc7fe495544492f2" + integrity sha512-N0qPlqfypFx7UHNn4B3lzS/b0uLqt2hmuoa+PpuXNYgozdJYAyauF5Ky0BWVjrxDlMWiT3qN4zPq3vVAfZy7Yg== + dependencies: + colors "^1.2.1" + fast-safe-stringify "^2.0.4" + fecha "^4.2.0" + ms "^2.1.1" + triple-beam "^1.3.0" + lru-cache@^6.0.0: version "6.0.0" resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94" @@ -3221,6 +3305,11 @@ ms@2.1.2: resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== +ms@^2.1.1: + version "2.1.3" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" + integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== + mute-stream@0.0.8: version "0.0.8" resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d" @@ -3396,6 +3485,13 @@ once@^1.3.0, once@^1.3.1, once@^1.4.0: dependencies: wrappy "1" +one-time@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/one-time/-/one-time-1.0.0.tgz#e06bc174aed214ed58edede573b433bbf827cb45" + integrity sha512-5DXOiRKwuSEcQ/l0kGCF6Q3jcADFv5tSmRaJck/OqkVFcOzutB134KRSfF0xDrL39MNnqxbHBbUUcjZIhTgb2g== + dependencies: + fn.name "1.x.x" + onetime@^5.1.0: version "5.1.2" resolved "https://registry.yarnpkg.com/onetime/-/onetime-5.1.2.tgz#d0e96ebb56b07476df1dd9c4806e5237985ca45e" @@ -3612,6 +3708,11 @@ pretty-format@^26.0.0, pretty-format@^26.6.2: ansi-styles "^4.0.0" react-is "^17.0.1" +process-nextick-args@~2.0.0: + version "2.0.1" + resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2" + integrity sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag== + progress@^2.0.0: version "2.0.3" resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8" @@ -3694,6 +3795,28 @@ read-pkg@^5.2.0: parse-json "^5.0.0" type-fest "^0.6.0" +readable-stream@^2.3.7: + version "2.3.7" + resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.7.tgz#1eca1cf711aef814c04f62252a36a62f6cb23b57" + integrity sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw== + dependencies: + core-util-is "~1.0.0" + inherits "~2.0.3" + isarray "~1.0.0" + process-nextick-args "~2.0.0" + safe-buffer "~5.1.1" + string_decoder "~1.1.1" + util-deprecate "~1.0.1" + +readable-stream@^3.4.0: + version "3.6.0" + resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.0.tgz#337bbda3adc0706bd3e024426a286d4b4b2c9198" + integrity sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA== + dependencies: + inherits "^2.0.3" + string_decoder "^1.1.1" + util-deprecate "^1.0.1" + regex-not@^1.0.0, regex-not@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/regex-not/-/regex-not-1.0.2.tgz#1f4ece27e00b0b65e0247a6810e6a85d83a5752c" @@ -3865,12 +3988,12 @@ rxjs@^6.6.0: dependencies: tslib "^1.9.0" -safe-buffer@^5.0.1, safe-buffer@^5.1.2: +safe-buffer@^5.0.1, safe-buffer@^5.1.2, safe-buffer@~5.2.0: version "5.2.1" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6" integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ== -safe-buffer@~5.1.1: +safe-buffer@~5.1.0, safe-buffer@~5.1.1: version "5.1.2" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d" integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g== @@ -3975,6 +4098,13 @@ signal-exit@^3.0.0, signal-exit@^3.0.2: resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.3.tgz#a1410c2edd8f077b08b4e253c8eacfcaf057461c" integrity sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA== +simple-swizzle@^0.2.2: + version "0.2.2" + resolved "https://registry.yarnpkg.com/simple-swizzle/-/simple-swizzle-0.2.2.tgz#a4da6b635ffcccca33f70d17cb92592de95e557a" + integrity sha1-pNprY1/8zMoz9w0Xy5JZLeleVXo= + dependencies: + is-arrayish "^0.3.1" + sisteransi@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-1.0.5.tgz#134d681297756437cc05ca01370d3a7a571075ed" @@ -4116,6 +4246,11 @@ sshpk@^1.7.0: safer-buffer "^2.0.2" tweetnacl "~0.14.0" +stack-trace@0.0.x: + version "0.0.10" + resolved "https://registry.yarnpkg.com/stack-trace/-/stack-trace-0.0.10.tgz#547c70b347e8d32b4e108ea1a2a159e5fdde19c0" + integrity sha1-VHxws0fo0ytOEI6hoqFZ5f3eGcA= + stack-utils@^2.0.2: version "2.0.3" resolved "https://registry.yarnpkg.com/stack-utils/-/stack-utils-2.0.3.tgz#cd5f030126ff116b78ccb3c027fe302713b61277" @@ -4178,6 +4313,20 @@ string.prototype.trimstart@^1.0.4: call-bind "^1.0.2" define-properties "^1.1.3" +string_decoder@^1.1.1: + version "1.3.0" + resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.3.0.tgz#42f114594a46cf1a8e30b0a84f56c78c3edac21e" + integrity sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA== + dependencies: + safe-buffer "~5.2.0" + +string_decoder@~1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.1.1.tgz#9cf1611ba62685d7030ae9e4ba34149c3af03fc8" + integrity sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg== + dependencies: + safe-buffer "~5.1.0" + strip-ansi@^5.1.0, strip-ansi@^5.2.0: version "5.2.0" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-5.2.0.tgz#8c9a536feb6afc962bdfa5b104a5091c1ad9c0ae" @@ -4271,6 +4420,11 @@ test-exclude@^6.0.0: glob "^7.1.4" minimatch "^3.0.4" +text-hex@1.0.x: + version "1.0.0" + resolved "https://registry.yarnpkg.com/text-hex/-/text-hex-1.0.0.tgz#69dc9c1b17446ee79a92bf5b884bb4b9127506f5" + integrity sha512-uuVGNWzgJ4yhRaNSiubPY7OjISw4sw4E5Uv0wbjp+OzcbmVU/rsT8ujgcXJhn9ypzsgr5vlzpPqP+MBBKcGvbg== + text-table@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4" @@ -4359,6 +4513,11 @@ tr46@^2.0.2: dependencies: punycode "^2.1.1" +triple-beam@^1.2.0, triple-beam@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/triple-beam/-/triple-beam-1.3.0.tgz#a595214c7298db8339eeeee083e4d10bd8cb8dd9" + integrity sha512-XrHUvV5HpdLmIj4uVMxHggLbFSZYIn7HEWsqePZcI50pco+MPqJ50wMGY794X7AOOhxOBAjbkqfAbEe/QMp2Lw== + ts-essentials@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/ts-essentials/-/ts-essentials-4.0.0.tgz#506c42b270bbd0465574b90416533175b09205ab" @@ -4503,6 +4662,11 @@ use@^3.1.0: resolved "https://registry.yarnpkg.com/use/-/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f" integrity sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ== +util-deprecate@^1.0.1, util-deprecate@~1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" + integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8= + uuid@^3.3.2: version "3.4.0" resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee" @@ -4626,6 +4790,29 @@ which@^2.0.1, which@^2.0.2: dependencies: isexe "^2.0.0" +winston-transport@^4.4.0: + version "4.4.0" + resolved "https://registry.yarnpkg.com/winston-transport/-/winston-transport-4.4.0.tgz#17af518daa690d5b2ecccaa7acf7b20ca7925e59" + integrity sha512-Lc7/p3GtqtqPBYYtS6KCN3c77/2QCev51DvcJKbkFPQNoj1sinkGwLGFDxkXY9J6p9+EPnYs+D90uwbnaiURTw== + dependencies: + readable-stream "^2.3.7" + triple-beam "^1.2.0" + +winston@^3.3.3: + version "3.3.3" + resolved "https://registry.yarnpkg.com/winston/-/winston-3.3.3.tgz#ae6172042cafb29786afa3d09c8ff833ab7c9170" + integrity sha512-oEXTISQnC8VlSAKf1KYSSd7J6IWuRPQqDdo8eoRNaYKLvwSb5+79Z3Yi1lrl6KDpU6/VWaxpakDAtb1oQ4n9aw== + dependencies: + "@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" + word-wrap@~1.2.3: version "1.2.3" resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c" From 79aebf31af571f6476e944734eadcb7a3c020e1b Mon Sep 17 00:00:00 2001 From: zheyanyu Date: Mon, 3 May 2021 18:22:43 -0400 Subject: [PATCH 2/4] feat: add Winston logger --- CHANGELOG.md | 102 +++++++++++++++++++++++-------------------- package.json | 5 ++- src/fhirConfig.ts | 5 --- src/loggerBuilder.ts | 48 ++++++++++++++++---- 4 files changed, 96 insertions(+), 64 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 373f5e6..9df59b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### Features + +* Add Winston logger builder for other components to use + +### [8.2.1](https://github.com/awslabs/fhir-works-on-aws-interface/compare/v8.2.1...v8.1.1) (2021-04-06) + ### [8.1.1](https://github.com/awslabs/fhir-works-on-aws-interface/compare/v8.1.0...v8.1.1) (2021-04-06) @@ -56,51 +62,51 @@ All notable changes to this project will be documented in this file. See [standa * add getCapabilities method to Search interface ([#42](https://github.com/awslabs/fhir-works-on-aws-interface/issues/42)) ([b274566](https://github.com/awslabs/fhir-works-on-aws-interface/commit/b274566c71899a2bd7c7d9112bfd85c889678ad4)) -## [6.0.1] - 2021-01-06 - -### Updated -* `GetSearchFilterBasedOnIdentityRequest.operation` now includes `history-instance` - -## [6.0.0] - 2020-12-21 - -### Added -- `SearchFilter` interface to allow `fhir-works-on-aws-search` to filter search results -- `GetSearchFilterBasedOnIdentity` interface so `fhir-works-on-aws-authz` can provide `SearchFilter` that can be used for filtering search results -- `InvalidSearchParameterError`: A new error for search to throw when search parameters are invalid - -## [5.0.0] - 2020-12-11 - -### Added -- `ProductInfo` interface to collect product and business information about the FHIR server - -## [4.0.0] - 2020-11-20 - -### Added -- `SmartStrategy` for passing in SMART Auth configurations -- `SmartAuthorization` for class implementing SMART Auth - -### Updated -- Authorization interfaces to use `userIdentity` instead of `accessToken` -- isAuthorized renamed to verifyAccessToken -- getRequesterUserId method removed - -## [3.0.0] - 2020-11-11 - -### Added -- Required methods for SMART on FHIR interactions -- Export UnauthorizedError to be usable -- Required interfaces and types for bulk data export - -## [2.0.0] - 2020-09-25 - -### Added -- `getAllowedResourceTypesForOperation` method to `Authorization` interface. - -### Updated -- `Authorization.isAuthorized` to return a promise. - -## [1.0.0] - 2020-08-31 - -### Added - -- Initial launch! :rocket: +## [6.0.1] - 2021-01-06 + +### Updated +* `GetSearchFilterBasedOnIdentityRequest.operation` now includes `history-instance` + +## [6.0.0] - 2020-12-21 + +### Added +- `SearchFilter` interface to allow `fhir-works-on-aws-search` to filter search results +- `GetSearchFilterBasedOnIdentity` interface so `fhir-works-on-aws-authz` can provide `SearchFilter` that can be used for filtering search results +- `InvalidSearchParameterError`: A new error for search to throw when search parameters are invalid + +## [5.0.0] - 2020-12-11 + +### Added +- `ProductInfo` interface to collect product and business information about the FHIR server + +## [4.0.0] - 2020-11-20 + +### Added +- `SmartStrategy` for passing in SMART Auth configurations +- `SmartAuthorization` for class implementing SMART Auth + +### Updated +- Authorization interfaces to use `userIdentity` instead of `accessToken` +- isAuthorized renamed to verifyAccessToken +- getRequesterUserId method removed + +## [3.0.0] - 2020-11-11 + +### Added +- Required methods for SMART on FHIR interactions +- Export UnauthorizedError to be usable +- Required interfaces and types for bulk data export + +## [2.0.0] - 2020-09-25 + +### Added +- `getAllowedResourceTypesForOperation` method to `Authorization` interface. + +### Updated +- `Authorization.isAuthorized` to return a promise. + +## [1.0.0] - 2020-08-31 + +### Added + +- Initial launch! :rocket: diff --git a/package.json b/package.json index 60260d7..5f99786 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fhir-works-on-aws-interface", - "version": "8.1.1", + "version": "8.2.1", "description": "FHIR Works on AWS hosted on AWS Lambda", "main": "lib/index.js", "types": "lib/index.d.ts", @@ -28,7 +28,8 @@ "prepublish": "tsc" }, "dependencies": { - "winston": "^3.3.3" + "winston": "^3.3.3", + "winston-transport": "^4.4.0" }, "devDependencies": { "@types/jest": "^26.0.19", diff --git a/src/fhirConfig.ts b/src/fhirConfig.ts index befb848..a5cdb7b 100644 --- a/src/fhirConfig.ts +++ b/src/fhirConfig.ts @@ -82,10 +82,6 @@ export interface Server { url: string; } -export interface Logging { - level: 'debug' | 'info' | 'warn' | 'error'; -} - export interface Resource { operations: TypeOperation[]; fhirVersions: FhirVersion[]; @@ -160,7 +156,6 @@ export interface FhirConfig { productInfo: ProductInfo; auth: Auth; server: Server; - logging: Logging; profile: Profile; validators: Validator[]; } diff --git a/src/loggerBuilder.ts b/src/loggerBuilder.ts index b4fea35..3659e89 100644 --- a/src/loggerBuilder.ts +++ b/src/loggerBuilder.ts @@ -1,22 +1,52 @@ -import { createLogger, format, transports } from 'winston'; +import { createLogger, format } from 'winston'; +import Transport from 'winston-transport'; const { combine, splat, timestamp, printf } = format; const myFormat = printf(info => { - let msg = `[${info.level}] : ${info.message} ${info.timestamp} `; - if (info.metadata) { - msg += JSON.stringify(info.metadata); + let msg = `${info.message} ${info.timestamp} `; + if (info.meta) { + msg += JSON.stringify(info.meta); } return msg; }); +class SimpleConsole extends Transport { + log(info: any, callback: () => void) { + setImmediate(() => this.emit('logged', info)); + const msg = info[Symbol.for('message')]; + + // Use console here so request ID and log level can be automatically attached in CloudWatch log + switch (info[Symbol.for('level')]) { + case 'debug': + console.debug(msg); + break; + case 'info': + console.info(msg); + break; + case 'warn': + console.warn(msg); + break; + case 'error': + console.error(msg); + break; + default: + console.log(msg); + break; + } + + if (callback) { + callback(); + } + } +} + // eslint-disable-next-line import/prefer-default-export export function getLogger(metadata?: any) { - const logger = createLogger({ - level: 'debug', - format: combine(format.colorize(), splat(), timestamp(), myFormat), - transports: [new transports.Console()], + return createLogger({ + level: process.env.LOG_LEVEL, + format: combine(format.colorize(), splat(), timestamp(), format.json(), myFormat), + transports: [new SimpleConsole({})], defaultMeta: metadata, }); - return logger; } From 804cdf78ac29a2c5557b6dda14f744c9da5db7d9 Mon Sep 17 00:00:00 2001 From: Yanyu Zheng Date: Tue, 4 May 2021 09:38:42 -0400 Subject: [PATCH 3/4] Update src/loggerBuilder.ts Co-authored-by: Robert Smayda --- src/loggerBuilder.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/loggerBuilder.ts b/src/loggerBuilder.ts index 3659e89..9646e3a 100644 --- a/src/loggerBuilder.ts +++ b/src/loggerBuilder.ts @@ -42,7 +42,7 @@ class SimpleConsole extends Transport { } // eslint-disable-next-line import/prefer-default-export -export function getLogger(metadata?: any) { +export function makeLogger(metadata?: any) { return createLogger({ level: process.env.LOG_LEVEL, format: combine(format.colorize(), splat(), timestamp(), format.json(), myFormat), From 3baa9fd9e8add990f85d78a382b3ebac93b6488a Mon Sep 17 00:00:00 2001 From: zheyanyu Date: Wed, 5 May 2021 20:31:51 -0400 Subject: [PATCH 4/4] Update formatting, revert changelog update --- CHANGELOG.md | 6 ------ package.json | 2 +- src/index.ts | 2 +- src/loggerBuilder.ts | 38 ++++++++++++++++---------------------- 4 files changed, 18 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9df59b8..33969ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,12 +2,6 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. -### Features - -* Add Winston logger builder for other components to use - -### [8.2.1](https://github.com/awslabs/fhir-works-on-aws-interface/compare/v8.2.1...v8.1.1) (2021-04-06) - ### [8.1.1](https://github.com/awslabs/fhir-works-on-aws-interface/compare/v8.1.0...v8.1.1) (2021-04-06) diff --git a/package.json b/package.json index 5f99786..0436f3a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fhir-works-on-aws-interface", - "version": "8.2.1", + "version": "8.1.1", "description": "FHIR Works on AWS hosted on AWS Lambda", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/index.ts b/src/index.ts index ac43c81..23eb69f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -23,5 +23,5 @@ export * from './errors/UnauthorizedError'; export * from './errors/TooManyConcurrentExportRequestsError'; export * from './errors/InvalidSearchParameterError'; export * from './validator'; -export { getLogger } from './loggerBuilder'; +export { makeLogger } from './loggerBuilder'; export { stubs } from './stubs'; diff --git a/src/loggerBuilder.ts b/src/loggerBuilder.ts index 9646e3a..62e150b 100644 --- a/src/loggerBuilder.ts +++ b/src/loggerBuilder.ts @@ -1,39 +1,34 @@ -import { createLogger, format } from 'winston'; +import { createLogger, Logger } from 'winston'; import Transport from 'winston-transport'; -const { combine, splat, timestamp, printf } = format; - -const myFormat = printf(info => { - let msg = `${info.message} ${info.timestamp} `; - if (info.meta) { - msg += JSON.stringify(info.meta); - } - return msg; -}); - class SimpleConsole extends Transport { log(info: any, callback: () => void) { setImmediate(() => this.emit('logged', info)); - const msg = info[Symbol.for('message')]; + const msg = [info.meta, info.message]; + if (info[Symbol.for('splat')]) { + msg.push(...info[Symbol.for('splat')]); + } // Use console here so request ID and log level can be automatically attached in CloudWatch log + /* eslint-disable no-console */ switch (info[Symbol.for('level')]) { case 'debug': - console.debug(msg); + console.debug(...msg); break; case 'info': - console.info(msg); + console.info(...msg); break; case 'warn': - console.warn(msg); + console.warn(...msg); break; case 'error': - console.error(msg); + console.error(...msg); break; default: - console.log(msg); + console.log(...msg); break; } + /* eslint-enable no-console */ if (callback) { callback(); @@ -42,11 +37,10 @@ class SimpleConsole extends Transport { } // eslint-disable-next-line import/prefer-default-export -export function makeLogger(metadata?: any) { +export function makeLogger(metadata?: any, logLevel: string | undefined = process.env.LOG_LEVEL): Logger { return createLogger({ - level: process.env.LOG_LEVEL, - format: combine(format.colorize(), splat(), timestamp(), format.json(), myFormat), - transports: [new SimpleConsole({})], - defaultMeta: metadata, + level: logLevel, + transports: [new SimpleConsole()], + defaultMeta: { meta: metadata }, }); }