Skip to content
Snippets Groups Projects
Unverified Commit 29c9eeaa authored by Timothy Carambat's avatar Timothy Carambat Committed by GitHub
Browse files

Add `winston` logging for production (#1811)

parent 06fb9bdd
No related branches found
No related tags found
No related merge requests found
Showing
with 310 additions and 92 deletions
...@@ -2,6 +2,7 @@ process.env.NODE_ENV === "development" ...@@ -2,6 +2,7 @@ process.env.NODE_ENV === "development"
? require("dotenv").config({ path: `.env.${process.env.NODE_ENV}` }) ? require("dotenv").config({ path: `.env.${process.env.NODE_ENV}` })
: require("dotenv").config(); : require("dotenv").config();
require("./utils/logger")();
const express = require("express"); const express = require("express");
const bodyParser = require("body-parser"); const bodyParser = require("body-parser");
const cors = require("cors"); const cors = require("cors");
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
"url-pattern": "^1.0.3", "url-pattern": "^1.0.3",
"uuid": "^9.0.0", "uuid": "^9.0.0",
"wavefile": "^11.0.0", "wavefile": "^11.0.0",
"winston": "^3.13.0",
"youtubei.js": "^9.1.0" "youtubei.js": "^9.1.0"
}, },
"devDependencies": { "devDependencies": {
......
const winston = require("winston");
class Logger {
logger = console;
static _instance;
constructor() {
if (Logger._instance) return Logger._instance;
this.logger = process.env.NODE_ENV === 'production' ? this.getWinstonLogger() : console;
Logger._instance = this;
}
getWinstonLogger() {
const logger = winston.createLogger({
level: "info",
defaultMeta: { service: "collector" },
transports: [
new winston.transports.Console({
format: winston.format.combine(
winston.format.colorize(),
winston.format.printf(
({ level, message, service, origin = "" }) => {
return `\x1b[36m[${service}]\x1b[0m${origin ? `\x1b[33m[${origin}]\x1b[0m` : ""
} ${level}: ${message}`;
}
)
),
}),
],
});
console.log = function () {
return logger.info.apply(logger, arguments);
};
console.error = function () {
return logger.error.apply(logger, arguments);
};
console.info = function () {
return logger.warn.apply(logger, arguments);
};
return logger;
}
}
/**
* Sets and overrides Console methods for logging when called.
* This is a singleton method and will not create multiple loggers.
* @returns {winston.Logger | console} - instantiated logger interface.
*/
function setLogger() {
return new Logger().logger;
}
module.exports = setLogger;
...@@ -40,6 +40,20 @@ ...@@ -40,6 +40,20 @@
js-tokens "^4.0.0" js-tokens "^4.0.0"
picocolors "^1.0.0" picocolors "^1.0.0"
"@colors/colors@1.6.0", "@colors/colors@^1.6.0":
version "1.6.0"
resolved "https://registry.yarnpkg.com/@colors/colors/-/colors-1.6.0.tgz#ec6cd237440700bc23ca23087f513c75508958b0"
integrity sha512-Ir+AOibqzrIsL6ajt3Rz3LskB7OiMVHqltZmspbW/TJuTVuyOMirVqAkjfY6JISiLHgyNqicAC8AyHHGzNd/dA==
"@dabh/diagnostics@^2.0.2":
version "2.0.3"
resolved "https://registry.yarnpkg.com/@dabh/diagnostics/-/diagnostics-2.0.3.tgz#7f7e97ee9a725dffc7808d93668cc984e1dc477a"
integrity sha512-hrlQOIi7hAfzsMqlGSFyVucrx38O+j6wiGOf//H2ecvIEqYN4ADBSS2iLMh5UFyDunCNniUIPk/q3riFv45xRA==
dependencies:
colorspace "1.1.x"
enabled "2.0.x"
kuler "^2.0.0"
"@fastify/busboy@^2.0.0": "@fastify/busboy@^2.0.0":
version "2.1.1" version "2.1.1"
resolved "https://registry.yarnpkg.com/@fastify/busboy/-/busboy-2.1.1.tgz#b9da6a878a371829a0502c9b6c1c143ef6663f4d" resolved "https://registry.yarnpkg.com/@fastify/busboy/-/busboy-2.1.1.tgz#b9da6a878a371829a0502c9b6c1c143ef6663f4d"
...@@ -247,6 +261,11 @@ ...@@ -247,6 +261,11 @@
resolved "https://registry.yarnpkg.com/@types/retry/-/retry-0.12.0.tgz#2b35eccfcee7d38cd72ad99232fbd58bffb3c84d" resolved "https://registry.yarnpkg.com/@types/retry/-/retry-0.12.0.tgz#2b35eccfcee7d38cd72ad99232fbd58bffb3c84d"
integrity sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA== integrity sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA==
"@types/triple-beam@^1.3.2":
version "1.3.5"
resolved "https://registry.yarnpkg.com/@types/triple-beam/-/triple-beam-1.3.5.tgz#74fef9ffbaa198eb8b588be029f38b00299caa2c"
integrity sha512-6WaYesThRMCl19iryMYP7/x2OVgCtbIVflDGFpWnb9irXI3UjYE4AzmYuiUKY1AJstGijoY+MgUszMgRxIYTYw==
"@types/uuid@^9.0.1": "@types/uuid@^9.0.1":
version "9.0.8" version "9.0.8"
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-9.0.8.tgz#7545ba4fc3c003d6c756f651f3bf163d8f0f29ba" resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-9.0.8.tgz#7545ba4fc3c003d6c756f651f3bf163d8f0f29ba"
...@@ -413,7 +432,7 @@ ast-types@^0.13.4: ...@@ -413,7 +432,7 @@ ast-types@^0.13.4:
dependencies: dependencies:
tslib "^2.0.1" tslib "^2.0.1"
async@>=0.2.9: async@>=0.2.9, async@^3.2.3:
version "3.2.5" version "3.2.5"
resolved "https://registry.yarnpkg.com/async/-/async-3.2.5.tgz#ebd52a8fdaf7a2289a24df399f8d8485c8a46b66" resolved "https://registry.yarnpkg.com/async/-/async-3.2.5.tgz#ebd52a8fdaf7a2289a24df399f8d8485c8a46b66"
integrity sha512-baNZyqaaLhyLVKm/DlvdW051MSgO6b8eVfIezl9E5PqWxFgzLm/wQntEW4zOytVburDEr0JlALEpdOFwvErLsg== integrity sha512-baNZyqaaLhyLVKm/DlvdW051MSgO6b8eVfIezl9E5PqWxFgzLm/wQntEW4zOytVburDEr0JlALEpdOFwvErLsg==
...@@ -708,7 +727,7 @@ cliui@^8.0.1: ...@@ -708,7 +727,7 @@ cliui@^8.0.1:
strip-ansi "^6.0.1" strip-ansi "^6.0.1"
wrap-ansi "^7.0.0" wrap-ansi "^7.0.0"
color-convert@^1.9.0: color-convert@^1.9.0, color-convert@^1.9.3:
version "1.9.3" version "1.9.3"
resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.3.tgz#bb71850690e1f136567de629d2d5471deda4c1e8" resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.3.tgz#bb71850690e1f136567de629d2d5471deda4c1e8"
integrity sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg== integrity sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==
...@@ -732,7 +751,7 @@ color-name@^1.0.0, color-name@~1.1.4: ...@@ -732,7 +751,7 @@ color-name@^1.0.0, color-name@~1.1.4:
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==
color-string@^1.9.0: color-string@^1.6.0, color-string@^1.9.0:
version "1.9.1" version "1.9.1"
resolved "https://registry.yarnpkg.com/color-string/-/color-string-1.9.1.tgz#4467f9146f036f855b764dfb5bf8582bf342c7a4" resolved "https://registry.yarnpkg.com/color-string/-/color-string-1.9.1.tgz#4467f9146f036f855b764dfb5bf8582bf342c7a4"
integrity sha512-shrVawQFojnZv6xM40anx4CkoDP+fZsw/ZerEMsW/pyzsRbElpsL/DBVW7q3ExxwusdNXI3lXpuhEZkzs8p5Eg== integrity sha512-shrVawQFojnZv6xM40anx4CkoDP+fZsw/ZerEMsW/pyzsRbElpsL/DBVW7q3ExxwusdNXI3lXpuhEZkzs8p5Eg==
...@@ -745,6 +764,14 @@ color-support@^1.1.2: ...@@ -745,6 +764,14 @@ color-support@^1.1.2:
resolved "https://registry.yarnpkg.com/color-support/-/color-support-1.1.3.tgz#93834379a1cc9a0c61f82f52f0d04322251bd5a2" resolved "https://registry.yarnpkg.com/color-support/-/color-support-1.1.3.tgz#93834379a1cc9a0c61f82f52f0d04322251bd5a2"
integrity sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg== integrity sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg==
color@^3.1.3:
version "3.2.1"
resolved "https://registry.yarnpkg.com/color/-/color-3.2.1.tgz#3544dc198caf4490c3ecc9a790b54fe9ff45e164"
integrity sha512-aBl7dZI9ENN6fUGC7mWpMTPNHmWUSNan9tuWN6ahh5ZLNk9baLJOnSMlrQkHcrfFgz2/RigjUVAjdx36VcemKA==
dependencies:
color-convert "^1.9.3"
color-string "^1.6.0"
color@^4.2.3: color@^4.2.3:
version "4.2.3" version "4.2.3"
resolved "https://registry.yarnpkg.com/color/-/color-4.2.3.tgz#d781ecb5e57224ee43ea9627560107c0e0c6463a" resolved "https://registry.yarnpkg.com/color/-/color-4.2.3.tgz#d781ecb5e57224ee43ea9627560107c0e0c6463a"
...@@ -753,6 +780,14 @@ color@^4.2.3: ...@@ -753,6 +780,14 @@ color@^4.2.3:
color-convert "^2.0.1" color-convert "^2.0.1"
color-string "^1.9.0" color-string "^1.9.0"
colorspace@1.1.x:
version "1.1.4"
resolved "https://registry.yarnpkg.com/colorspace/-/colorspace-1.1.4.tgz#8d442d1186152f60453bf8070cd66eb364e59243"
integrity sha512-BgvKJiuVu1igBUF2kEjRCZXol6wiiGbY5ipL/oVPwm0BL9sIpMIzM8IK7vwuxIIzOXMV3Ey5w+vxhm0rR/TN8w==
dependencies:
color "^3.1.3"
text-hex "1.0.x"
combined-stream@^1.0.8: combined-stream@^1.0.8:
version "1.0.8" version "1.0.8"
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f" resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
...@@ -1105,6 +1140,11 @@ emoji-regex@^8.0.0: ...@@ -1105,6 +1140,11 @@ emoji-regex@^8.0.0:
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37" resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37"
integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A== 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==
encodeurl@~1.0.2: encodeurl@~1.0.2:
version "1.0.2" version "1.0.2"
resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59" resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59"
...@@ -1299,6 +1339,11 @@ fd-slicer@~1.1.0: ...@@ -1299,6 +1339,11 @@ fd-slicer@~1.1.0:
dependencies: dependencies:
pend "~1.2.0" pend "~1.2.0"
fecha@^4.2.0:
version "4.2.3"
resolved "https://registry.yarnpkg.com/fecha/-/fecha-4.2.3.tgz#4d9ccdbc61e8629b259fdca67e65891448d569fd"
integrity sha512-OP2IUU6HeYKJi3i0z4A19kHMQoLVs4Hc+DPqqxI2h/DPZHTm/vjsfC6P0b4jCMy14XizLBqvndQ+UilD7707Jw==
file-type@^16.5.4: file-type@^16.5.4:
version "16.5.4" version "16.5.4"
resolved "https://registry.yarnpkg.com/file-type/-/file-type-16.5.4.tgz#474fb4f704bee427681f98dd390058a172a6c2fd" resolved "https://registry.yarnpkg.com/file-type/-/file-type-16.5.4.tgz#474fb4f704bee427681f98dd390058a172a6c2fd"
...@@ -1361,6 +1406,11 @@ fluent-ffmpeg@^2.1.2: ...@@ -1361,6 +1406,11 @@ fluent-ffmpeg@^2.1.2:
async ">=0.2.9" async ">=0.2.9"
which "^1.1.1" which "^1.1.1"
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==
form-data-encoder@1.7.2: form-data-encoder@1.7.2:
version "1.7.2" version "1.7.2"
resolved "https://registry.yarnpkg.com/form-data-encoder/-/form-data-encoder-1.7.2.tgz#1f1ae3dccf58ed4690b86d87e4f57c654fbab040" resolved "https://registry.yarnpkg.com/form-data-encoder/-/form-data-encoder-1.7.2.tgz#1f1ae3dccf58ed4690b86d87e4f57c654fbab040"
...@@ -1925,6 +1975,11 @@ jws@^4.0.0: ...@@ -1925,6 +1975,11 @@ jws@^4.0.0:
jwa "^2.0.0" jwa "^2.0.0"
safe-buffer "^5.0.1" safe-buffer "^5.0.1"
kuler@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/kuler/-/kuler-2.0.0.tgz#e2c570a3800388fb44407e851531c1d670b061b3"
integrity sha512-Xq9nH7KlWZmXAtodXDDRE7vs6DU1gTU8zYDHDiWLSip45Egwq3plLHzPn27NgvzL2r1LMPC1vdqh98sQxtqj4A==
langchain@0.1.36: langchain@0.1.36:
version "0.1.36" version "0.1.36"
resolved "https://registry.yarnpkg.com/langchain/-/langchain-0.1.36.tgz#2f201f681d83fb265716e28e7dfcfe61fbeef2c2" resolved "https://registry.yarnpkg.com/langchain/-/langchain-0.1.36.tgz#2f201f681d83fb265716e28e7dfcfe61fbeef2c2"
...@@ -2034,6 +2089,18 @@ lodash@^4.17.21: ...@@ -2034,6 +2089,18 @@ lodash@^4.17.21:
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
logform@^2.3.2, logform@^2.4.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/logform/-/logform-2.6.0.tgz#8c82a983f05d6eaeb2d75e3decae7a768b2bf9b5"
integrity sha512-1ulHeNPp6k/LD8H91o7VYFBng5i1BDE7HoKxVbZiGFidS1Rj65qcywLxX+pVfAPoQJEjRdvKcusKwOupHCVOVQ==
dependencies:
"@colors/colors" "1.6.0"
"@types/triple-beam" "^1.3.2"
fecha "^4.2.0"
ms "^2.1.1"
safe-stable-stringify "^2.3.1"
triple-beam "^1.3.0"
long@^4.0.0: long@^4.0.0:
version "4.0.0" version "4.0.0"
resolved "https://registry.yarnpkg.com/long/-/long-4.0.0.tgz#9a7b71cfb7d361a194ea555241c92f7468d5bf28" resolved "https://registry.yarnpkg.com/long/-/long-4.0.0.tgz#9a7b71cfb7d361a194ea555241c92f7468d5bf28"
...@@ -2472,6 +2539,13 @@ once@^1.3.0, once@^1.3.1, once@^1.4.0: ...@@ -2472,6 +2539,13 @@ once@^1.3.0, once@^1.3.1, once@^1.4.0:
dependencies: dependencies:
wrappy "1" 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"
onnx-proto@^4.0.4: onnx-proto@^4.0.4:
version "4.0.4" version "4.0.4"
resolved "https://registry.yarnpkg.com/onnx-proto/-/onnx-proto-4.0.4.tgz#2431a25bee25148e915906dda0687aafe3b9e044" resolved "https://registry.yarnpkg.com/onnx-proto/-/onnx-proto-4.0.4.tgz#2431a25bee25148e915906dda0687aafe3b9e044"
...@@ -2960,6 +3034,11 @@ safe-buffer@~5.1.0, safe-buffer@~5.1.1: ...@@ -2960,6 +3034,11 @@ safe-buffer@~5.1.0, safe-buffer@~5.1.1:
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g== integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==
safe-stable-stringify@^2.3.1:
version "2.4.3"
resolved "https://registry.yarnpkg.com/safe-stable-stringify/-/safe-stable-stringify-2.4.3.tgz#138c84b6f6edb3db5f8ef3ef7115b8f55ccbf886"
integrity sha512-e2bDA2WJT0wxseVd4lsDP4+3ONX6HpMXQa1ZhFQ7SU+GjvORCmShbCMltrtIDfkYhVHrOcPtj+KhmDBdPdZD1g==
"safer-buffer@>= 2.1.2 < 3", "safer-buffer@>= 2.1.2 < 3.0.0": "safer-buffer@>= 2.1.2 < 3", "safer-buffer@>= 2.1.2 < 3.0.0":
version "2.1.2" version "2.1.2"
resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a"
...@@ -3170,6 +3249,11 @@ sprintf-js@~1.0.2: ...@@ -3170,6 +3249,11 @@ sprintf-js@~1.0.2:
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c" resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
integrity sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g== integrity sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==
stack-trace@0.0.x:
version "0.0.10"
resolved "https://registry.yarnpkg.com/stack-trace/-/stack-trace-0.0.10.tgz#547c70b347e8d32b4e108ea1a2a159e5fdde19c0"
integrity sha512-KGzahc7puUKkzyMt+IqAep+TVNbKP+k2Lmwhub39m1AsTSkaDutx56aDCo+HLDzf/D26BIHTJWNiTG1KAJiQCg==
statuses@2.0.1: statuses@2.0.1:
version "2.0.1" version "2.0.1"
resolved "https://registry.yarnpkg.com/statuses/-/statuses-2.0.1.tgz#55cb000ccf1d48728bd23c685a063998cf1a1b63" resolved "https://registry.yarnpkg.com/statuses/-/statuses-2.0.1.tgz#55cb000ccf1d48728bd23c685a063998cf1a1b63"
...@@ -3322,6 +3406,11 @@ tar@^6.1.11: ...@@ -3322,6 +3406,11 @@ tar@^6.1.11:
mkdirp "^1.0.3" mkdirp "^1.0.3"
yallist "^4.0.0" yallist "^4.0.0"
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==
through@^2.3.8: through@^2.3.8:
version "2.3.8" version "2.3.8"
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5" resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
...@@ -3369,6 +3458,11 @@ tr46@~0.0.3: ...@@ -3369,6 +3458,11 @@ tr46@~0.0.3:
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a" resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw== integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==
triple-beam@^1.3.0:
version "1.4.1"
resolved "https://registry.yarnpkg.com/triple-beam/-/triple-beam-1.4.1.tgz#6fde70271dc6e5d73ca0c3b24e2d92afb7441984"
integrity sha512-aZbgViZrg1QNcG+LULa7nhZpJTZSLm/mXnHXnbAbjmN5aSa0y7V+wvv6+4WaBtpISJzThKy+PIPxc1Nq1EJ9mg==
ts-type@>=2: ts-type@>=2:
version "3.0.1" version "3.0.1"
resolved "https://registry.yarnpkg.com/ts-type/-/ts-type-3.0.1.tgz#b52e7623065e0beb43c77c426347d85cf81dff84" resolved "https://registry.yarnpkg.com/ts-type/-/ts-type-3.0.1.tgz#b52e7623065e0beb43c77c426347d85cf81dff84"
...@@ -3535,6 +3629,32 @@ wide-align@^1.1.2: ...@@ -3535,6 +3629,32 @@ wide-align@^1.1.2:
dependencies: dependencies:
string-width "^1.0.2 || 2 || 3 || 4" string-width "^1.0.2 || 2 || 3 || 4"
winston-transport@^4.7.0:
version "4.7.0"
resolved "https://registry.yarnpkg.com/winston-transport/-/winston-transport-4.7.0.tgz#e302e6889e6ccb7f383b926df6936a5b781bd1f0"
integrity sha512-ajBj65K5I7denzer2IYW6+2bNIVqLGDHqDw3Ow8Ohh+vdW+rv4MZ6eiDvHoKhfJFZ2auyN8byXieDDJ96ViONg==
dependencies:
logform "^2.3.2"
readable-stream "^3.6.0"
triple-beam "^1.3.0"
winston@^3.13.0:
version "3.13.0"
resolved "https://registry.yarnpkg.com/winston/-/winston-3.13.0.tgz#e76c0d722f78e04838158c61adc1287201de7ce3"
integrity sha512-rwidmA1w3SE4j0E5MuIufFhyJPBDG7Nu71RkZor1p2+qHvJSZ9GYDA81AyleQcZbh/+V6HjeBdfnTZJm9rSeQQ==
dependencies:
"@colors/colors" "^1.6.0"
"@dabh/diagnostics" "^2.0.2"
async "^3.2.3"
is-stream "^2.0.0"
logform "^2.4.0"
one-time "^1.0.0"
readable-stream "^3.4.0"
safe-stable-stringify "^2.3.1"
stack-trace "0.0.x"
triple-beam "^1.3.0"
winston-transport "^4.7.0"
wrap-ansi@^7.0.0: wrap-ansi@^7.0.0:
version "7.0.0" version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
......
...@@ -115,7 +115,7 @@ function apiDocumentEndpoints(app) { ...@@ -115,7 +115,7 @@ function apiDocumentEndpoints(app) {
}); });
response.status(200).json({ success: true, error: null, documents }); response.status(200).json({ success: true, error: null, documents });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -213,7 +213,7 @@ function apiDocumentEndpoints(app) { ...@@ -213,7 +213,7 @@ function apiDocumentEndpoints(app) {
}); });
response.status(200).json({ success: true, error: null, documents }); response.status(200).json({ success: true, error: null, documents });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -346,7 +346,7 @@ function apiDocumentEndpoints(app) { ...@@ -346,7 +346,7 @@ function apiDocumentEndpoints(app) {
await EventLogs.logEvent("api_raw_document_uploaded"); await EventLogs.logEvent("api_raw_document_uploaded");
response.status(200).json({ success: true, error: null, documents }); response.status(200).json({ success: true, error: null, documents });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -391,7 +391,7 @@ function apiDocumentEndpoints(app) { ...@@ -391,7 +391,7 @@ function apiDocumentEndpoints(app) {
const localFiles = await viewLocalFiles(); const localFiles = await viewLocalFiles();
response.status(200).json({ localFiles }); response.status(200).json({ localFiles });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
}); });
...@@ -447,7 +447,7 @@ function apiDocumentEndpoints(app) { ...@@ -447,7 +447,7 @@ function apiDocumentEndpoints(app) {
response.status(200).json({ types }); response.status(200).json({ types });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -497,7 +497,7 @@ function apiDocumentEndpoints(app) { ...@@ -497,7 +497,7 @@ function apiDocumentEndpoints(app) {
}, },
}); });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -555,7 +555,7 @@ function apiDocumentEndpoints(app) { ...@@ -555,7 +555,7 @@ function apiDocumentEndpoints(app) {
} }
response.status(200).json({ document }); response.status(200).json({ document });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
}); });
......
...@@ -75,7 +75,7 @@ function apiOpenAICompatibleEndpoints(app) { ...@@ -75,7 +75,7 @@ function apiOpenAICompatibleEndpoints(app) {
} }
return response.status(200).json({ data }); return response.status(200).json({ data });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
}); });
...@@ -187,7 +187,7 @@ function apiOpenAICompatibleEndpoints(app) { ...@@ -187,7 +187,7 @@ function apiOpenAICompatibleEndpoints(app) {
}); });
response.end(); response.end();
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.status(500).end(); response.status(500).end();
} }
} }
...@@ -245,7 +245,7 @@ function apiOpenAICompatibleEndpoints(app) { ...@@ -245,7 +245,7 @@ function apiOpenAICompatibleEndpoints(app) {
model: Embedder.model, model: Embedder.model,
}); });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.status(500).end(); response.status(500).end();
} }
} }
...@@ -321,7 +321,7 @@ function apiOpenAICompatibleEndpoints(app) { ...@@ -321,7 +321,7 @@ function apiOpenAICompatibleEndpoints(app) {
has_more: false, has_more: false,
}); });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.status(500).end(); response.status(500).end();
} }
} }
......
...@@ -29,7 +29,7 @@ function apiSystemEndpoints(app) { ...@@ -29,7 +29,7 @@ function apiSystemEndpoints(app) {
dumpENV(); dumpENV();
response.sendStatus(200).end(); response.sendStatus(200).end();
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
}); });
...@@ -66,7 +66,7 @@ function apiSystemEndpoints(app) { ...@@ -66,7 +66,7 @@ function apiSystemEndpoints(app) {
const settings = await SystemSettings.currentSettings(); const settings = await SystemSettings.currentSettings();
response.status(200).json({ settings }); response.status(200).json({ settings });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
}); });
...@@ -98,7 +98,7 @@ function apiSystemEndpoints(app) { ...@@ -98,7 +98,7 @@ function apiSystemEndpoints(app) {
const vectorCount = await VectorDb.totalVectors(); const vectorCount = await VectorDb.totalVectors();
response.status(200).json({ vectorCount }); response.status(200).json({ vectorCount });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
}); });
...@@ -147,7 +147,7 @@ function apiSystemEndpoints(app) { ...@@ -147,7 +147,7 @@ function apiSystemEndpoints(app) {
const { newValues, error } = await updateENV(body); const { newValues, error } = await updateENV(body);
response.status(200).json({ newValues, error }); response.status(200).json({ newValues, error });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -201,7 +201,7 @@ function apiSystemEndpoints(app) { ...@@ -201,7 +201,7 @@ function apiSystemEndpoints(app) {
response.setHeader("Content-Type", contentType); response.setHeader("Content-Type", contentType);
response.status(200).send(data); response.status(200).send(data);
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -267,7 +267,7 @@ function apiSystemEndpoints(app) { ...@@ -267,7 +267,7 @@ function apiSystemEndpoints(app) {
.json({ success: true, message: "Documents removed successfully" }) .json({ success: true, message: "Documents removed successfully" })
.end(); .end();
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
......
...@@ -55,7 +55,7 @@ function apiUserManagementEndpoints(app) { ...@@ -55,7 +55,7 @@ function apiUserManagementEndpoints(app) {
})); }));
response.status(200).json({ users: filteredUsers }); response.status(200).json({ users: filteredUsers });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
}); });
......
...@@ -79,7 +79,7 @@ function apiWorkspaceEndpoints(app) { ...@@ -79,7 +79,7 @@ function apiWorkspaceEndpoints(app) {
}); });
response.status(200).json({ workspace, message }); response.status(200).json({ workspace, message });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
}); });
...@@ -121,7 +121,7 @@ function apiWorkspaceEndpoints(app) { ...@@ -121,7 +121,7 @@ function apiWorkspaceEndpoints(app) {
const workspaces = await Workspace.where(); const workspaces = await Workspace.where();
response.status(200).json({ workspaces }); response.status(200).json({ workspaces });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
}); });
...@@ -170,7 +170,7 @@ function apiWorkspaceEndpoints(app) { ...@@ -170,7 +170,7 @@ function apiWorkspaceEndpoints(app) {
const workspace = await Workspace.get({ slug }); const workspace = await Workspace.get({ slug });
response.status(200).json({ workspace }); response.status(200).json({ workspace });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
}); });
...@@ -221,7 +221,7 @@ function apiWorkspaceEndpoints(app) { ...@@ -221,7 +221,7 @@ function apiWorkspaceEndpoints(app) {
} }
response.sendStatus(200).end(); response.sendStatus(200).end();
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -301,7 +301,7 @@ function apiWorkspaceEndpoints(app) { ...@@ -301,7 +301,7 @@ function apiWorkspaceEndpoints(app) {
); );
response.status(200).json({ workspace, message }); response.status(200).json({ workspace, message });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -362,7 +362,7 @@ function apiWorkspaceEndpoints(app) { ...@@ -362,7 +362,7 @@ function apiWorkspaceEndpoints(app) {
const history = await WorkspaceChats.forWorkspace(workspace.id); const history = await WorkspaceChats.forWorkspace(workspace.id);
response.status(200).json({ history: convertToChatHistory(history) }); response.status(200).json({ history: convertToChatHistory(history) });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -441,7 +441,7 @@ function apiWorkspaceEndpoints(app) { ...@@ -441,7 +441,7 @@ function apiWorkspaceEndpoints(app) {
}); });
response.status(200).json({ workspace: updatedWorkspace }); response.status(200).json({ workspace: updatedWorkspace });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -603,7 +603,7 @@ function apiWorkspaceEndpoints(app) { ...@@ -603,7 +603,7 @@ function apiWorkspaceEndpoints(app) {
}); });
response.status(200).json({ ...result }); response.status(200).json({ ...result });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.status(500).json({ response.status(500).json({
id: uuidv4(), id: uuidv4(),
type: "abort", type: "abort",
...@@ -726,7 +726,7 @@ function apiWorkspaceEndpoints(app) { ...@@ -726,7 +726,7 @@ function apiWorkspaceEndpoints(app) {
}); });
response.end(); response.end();
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
writeResponseChunk(response, { writeResponseChunk(response, {
id: uuidv4(), id: uuidv4(),
type: "abort", type: "abort",
......
...@@ -96,7 +96,7 @@ function apiWorkspaceThreadEndpoints(app) { ...@@ -96,7 +96,7 @@ function apiWorkspaceThreadEndpoints(app) {
}); });
response.status(200).json({ thread, message }); response.status(200).json({ thread, message });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -179,7 +179,7 @@ function apiWorkspaceThreadEndpoints(app) { ...@@ -179,7 +179,7 @@ function apiWorkspaceThreadEndpoints(app) {
); );
response.status(200).json({ thread: updatedThread, message }); response.status(200).json({ thread: updatedThread, message });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -228,7 +228,7 @@ function apiWorkspaceThreadEndpoints(app) { ...@@ -228,7 +228,7 @@ function apiWorkspaceThreadEndpoints(app) {
}); });
response.sendStatus(200).end(); response.sendStatus(200).end();
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -307,7 +307,7 @@ function apiWorkspaceThreadEndpoints(app) { ...@@ -307,7 +307,7 @@ function apiWorkspaceThreadEndpoints(app) {
response.status(200).json({ history: convertToChatHistory(history) }); response.status(200).json({ history: convertToChatHistory(history) });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -425,7 +425,7 @@ function apiWorkspaceThreadEndpoints(app) { ...@@ -425,7 +425,7 @@ function apiWorkspaceThreadEndpoints(app) {
}); });
response.status(200).json({ ...result }); response.status(200).json({ ...result });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.status(500).json({ response.status(500).json({
id: uuidv4(), id: uuidv4(),
type: "abort", type: "abort",
...@@ -576,7 +576,7 @@ function apiWorkspaceThreadEndpoints(app) { ...@@ -576,7 +576,7 @@ function apiWorkspaceThreadEndpoints(app) {
}); });
response.end(); response.end();
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
writeResponseChunk(response, { writeResponseChunk(response, {
id: uuidv4(), id: uuidv4(),
type: "abort", type: "abort",
......
...@@ -76,7 +76,7 @@ function embeddedEndpoints(app) { ...@@ -76,7 +76,7 @@ function embeddedEndpoints(app) {
history: convertToChatHistory(history), history: convertToChatHistory(history),
}); });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -93,7 +93,7 @@ function embeddedEndpoints(app) { ...@@ -93,7 +93,7 @@ function embeddedEndpoints(app) {
await EmbedChats.markHistoryInvalid(embed.id, sessionId); await EmbedChats.markHistoryInvalid(embed.id, sessionId);
response.status(200).end(); response.status(200).end();
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
......
...@@ -75,7 +75,7 @@ function systemEndpoints(app) { ...@@ -75,7 +75,7 @@ function systemEndpoints(app) {
const results = await SystemSettings.currentSettings(); const results = await SystemSettings.currentSettings();
response.status(200).json({ results }); response.status(200).json({ results });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
}); });
...@@ -98,7 +98,7 @@ function systemEndpoints(app) { ...@@ -98,7 +98,7 @@ function systemEndpoints(app) {
response.sendStatus(200).end(); response.sendStatus(200).end();
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -241,7 +241,7 @@ function systemEndpoints(app) { ...@@ -241,7 +241,7 @@ function systemEndpoints(app) {
}); });
} }
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
}); });
...@@ -307,7 +307,7 @@ function systemEndpoints(app) { ...@@ -307,7 +307,7 @@ function systemEndpoints(app) {
: await VectorDb.totalVectors(); : await VectorDb.totalVectors();
response.status(200).json({ vectorCount }); response.status(200).json({ vectorCount });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -322,7 +322,7 @@ function systemEndpoints(app) { ...@@ -322,7 +322,7 @@ function systemEndpoints(app) {
await purgeDocument(name); await purgeDocument(name);
response.sendStatus(200).end(); response.sendStatus(200).end();
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -337,7 +337,7 @@ function systemEndpoints(app) { ...@@ -337,7 +337,7 @@ function systemEndpoints(app) {
for await (const name of names) await purgeDocument(name); for await (const name of names) await purgeDocument(name);
response.sendStatus(200).end(); response.sendStatus(200).end();
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -352,7 +352,7 @@ function systemEndpoints(app) { ...@@ -352,7 +352,7 @@ function systemEndpoints(app) {
await purgeFolder(name); await purgeFolder(name);
response.sendStatus(200).end(); response.sendStatus(200).end();
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -366,7 +366,7 @@ function systemEndpoints(app) { ...@@ -366,7 +366,7 @@ function systemEndpoints(app) {
const localFiles = await viewLocalFiles(); const localFiles = await viewLocalFiles();
response.status(200).json({ localFiles }); response.status(200).json({ localFiles });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -380,7 +380,7 @@ function systemEndpoints(app) { ...@@ -380,7 +380,7 @@ function systemEndpoints(app) {
const online = await new CollectorApi().online(); const online = await new CollectorApi().online();
response.sendStatus(online ? 200 : 503); response.sendStatus(online ? 200 : 503);
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -399,7 +399,7 @@ function systemEndpoints(app) { ...@@ -399,7 +399,7 @@ function systemEndpoints(app) {
response.status(200).json({ types }); response.status(200).json({ types });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -418,7 +418,7 @@ function systemEndpoints(app) { ...@@ -418,7 +418,7 @@ function systemEndpoints(app) {
); );
response.status(200).json({ newValues, error }); response.status(200).json({ newValues, error });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -452,7 +452,7 @@ function systemEndpoints(app) { ...@@ -452,7 +452,7 @@ function systemEndpoints(app) {
} }
response.status(200).json({ success: !error, error }); response.status(200).json({ success: !error, error });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -500,7 +500,7 @@ function systemEndpoints(app) { ...@@ -500,7 +500,7 @@ function systemEndpoints(app) {
multi_user_mode: false, multi_user_mode: false,
}); });
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -511,7 +511,7 @@ function systemEndpoints(app) { ...@@ -511,7 +511,7 @@ function systemEndpoints(app) {
const multiUserMode = await SystemSettings.isMultiUserMode(); const multiUserMode = await SystemSettings.isMultiUserMode();
response.status(200).json({ multiUserMode }); response.status(200).json({ multiUserMode });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
}); });
......
...@@ -53,7 +53,7 @@ function workspaceThreadEndpoints(app) { ...@@ -53,7 +53,7 @@ function workspaceThreadEndpoints(app) {
); );
response.status(200).json({ thread, message }); response.status(200).json({ thread, message });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -72,7 +72,7 @@ function workspaceThreadEndpoints(app) { ...@@ -72,7 +72,7 @@ function workspaceThreadEndpoints(app) {
}); });
response.status(200).json({ threads }); response.status(200).json({ threads });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -91,7 +91,7 @@ function workspaceThreadEndpoints(app) { ...@@ -91,7 +91,7 @@ function workspaceThreadEndpoints(app) {
await WorkspaceThread.delete({ id: thread.id }); await WorkspaceThread.delete({ id: thread.id });
response.sendStatus(200).end(); response.sendStatus(200).end();
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -114,7 +114,7 @@ function workspaceThreadEndpoints(app) { ...@@ -114,7 +114,7 @@ function workspaceThreadEndpoints(app) {
}); });
response.sendStatus(200).end(); response.sendStatus(200).end();
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -145,7 +145,7 @@ function workspaceThreadEndpoints(app) { ...@@ -145,7 +145,7 @@ function workspaceThreadEndpoints(app) {
response.status(200).json({ history: convertToChatHistory(history) }); response.status(200).json({ history: convertToChatHistory(history) });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -168,7 +168,7 @@ function workspaceThreadEndpoints(app) { ...@@ -168,7 +168,7 @@ function workspaceThreadEndpoints(app) {
); );
response.status(200).json({ thread, message }); response.status(200).json({ thread, message });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -197,7 +197,7 @@ function workspaceThreadEndpoints(app) { ...@@ -197,7 +197,7 @@ function workspaceThreadEndpoints(app) {
response.sendStatus(200).end(); response.sendStatus(200).end();
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -239,7 +239,7 @@ function workspaceThreadEndpoints(app) { ...@@ -239,7 +239,7 @@ function workspaceThreadEndpoints(app) {
response.sendStatus(200).end(); response.sendStatus(200).end();
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
......
...@@ -70,7 +70,7 @@ function workspaceEndpoints(app) { ...@@ -70,7 +70,7 @@ function workspaceEndpoints(app) {
response.status(200).json({ workspace, message }); response.status(200).json({ workspace, message });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -99,7 +99,7 @@ function workspaceEndpoints(app) { ...@@ -99,7 +99,7 @@ function workspaceEndpoints(app) {
); );
response.status(200).json({ workspace, message }); response.status(200).json({ workspace, message });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -149,7 +149,7 @@ function workspaceEndpoints(app) { ...@@ -149,7 +149,7 @@ function workspaceEndpoints(app) {
); );
response.status(200).json({ success: true, error: null }); response.status(200).json({ success: true, error: null });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -192,7 +192,7 @@ function workspaceEndpoints(app) { ...@@ -192,7 +192,7 @@ function workspaceEndpoints(app) {
); );
response.status(200).json({ success: true, error: null }); response.status(200).json({ success: true, error: null });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -236,7 +236,7 @@ function workspaceEndpoints(app) { ...@@ -236,7 +236,7 @@ function workspaceEndpoints(app) {
: null, : null,
}); });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -279,7 +279,7 @@ function workspaceEndpoints(app) { ...@@ -279,7 +279,7 @@ function workspaceEndpoints(app) {
} }
response.sendStatus(200).end(); response.sendStatus(200).end();
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -320,7 +320,7 @@ function workspaceEndpoints(app) { ...@@ -320,7 +320,7 @@ function workspaceEndpoints(app) {
} }
response.sendStatus(200).end(); response.sendStatus(200).end();
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -338,7 +338,7 @@ function workspaceEndpoints(app) { ...@@ -338,7 +338,7 @@ function workspaceEndpoints(app) {
response.status(200).json({ workspaces }); response.status(200).json({ workspaces });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -357,7 +357,7 @@ function workspaceEndpoints(app) { ...@@ -357,7 +357,7 @@ function workspaceEndpoints(app) {
response.status(200).json({ workspace }); response.status(200).json({ workspace });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -384,7 +384,7 @@ function workspaceEndpoints(app) { ...@@ -384,7 +384,7 @@ function workspaceEndpoints(app) {
: await WorkspaceChats.forWorkspace(workspace.id); : await WorkspaceChats.forWorkspace(workspace.id);
response.status(200).json({ history: convertToChatHistory(history) }); response.status(200).json({ history: convertToChatHistory(history) });
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -415,7 +415,7 @@ function workspaceEndpoints(app) { ...@@ -415,7 +415,7 @@ function workspaceEndpoints(app) {
response.sendStatus(200).end(); response.sendStatus(200).end();
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -439,7 +439,7 @@ function workspaceEndpoints(app) { ...@@ -439,7 +439,7 @@ function workspaceEndpoints(app) {
response.sendStatus(200).end(); response.sendStatus(200).end();
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
...@@ -476,7 +476,7 @@ function workspaceEndpoints(app) { ...@@ -476,7 +476,7 @@ function workspaceEndpoints(app) {
response.sendStatus(200).end(); response.sendStatus(200).end();
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
} }
......
...@@ -2,6 +2,7 @@ process.env.NODE_ENV === "development" ...@@ -2,6 +2,7 @@ process.env.NODE_ENV === "development"
? require("dotenv").config({ path: `.env.${process.env.NODE_ENV}` }) ? require("dotenv").config({ path: `.env.${process.env.NODE_ENV}` })
: require("dotenv").config(); : require("dotenv").config();
require("./utils/logger")();
const express = require("express"); const express = require("express");
const bodyParser = require("body-parser"); const bodyParser = require("body-parser");
const cors = require("cors"); const cors = require("cors");
...@@ -106,7 +107,7 @@ if (process.env.NODE_ENV !== "development") { ...@@ -106,7 +107,7 @@ if (process.env.NODE_ENV !== "development") {
} }
return; return;
} catch (e) { } catch (e) {
console.log(e.message, e); console.error(e.message, e);
response.sendStatus(500).end(); response.sendStatus(500).end();
} }
}); });
......
const path = require("path"); const path = require("path");
const Graceful = require("@ladjs/graceful"); const Graceful = require("@ladjs/graceful");
const Bree = require("@mintplex-labs/bree"); const Bree = require("@mintplex-labs/bree");
const setLogger = require("../logger");
class BackgroundService { class BackgroundService {
name = "BackgroundWorkerService"; name = "BackgroundWorkerService";
...@@ -13,7 +14,7 @@ class BackgroundService { ...@@ -13,7 +14,7 @@ class BackgroundService {
return BackgroundService._instance; return BackgroundService._instance;
} }
this.logger = this.getLogger(); this.logger = setLogger();
BackgroundService._instance = this; BackgroundService._instance = this;
} }
...@@ -63,27 +64,18 @@ class BackgroundService { ...@@ -63,27 +64,18 @@ class BackgroundService {
]; ];
} }
getLogger() {
const { format, createLogger, transports } = require("winston");
return new createLogger({
level: "info",
format: format.combine(
format.colorize(),
format.printf(({ level, message, service }) => {
return `\x1b[36m[${service}]\x1b[0m ${level}: ${message}`;
})
),
defaultMeta: { service: this.name },
transports: [new transports.Console()],
});
}
onError(error, _workerMetadata) { onError(error, _workerMetadata) {
this.logger.error(`[${error.name}]: ${error.message}`); this.logger.error(`${error.message}`, {
service: "bg-worker",
origin: error.name,
});
} }
onWorkerMessageHandler(message, _workerMetadata) { onWorkerMessageHandler(message, _workerMetadata) {
this.logger.info(`[${message.name}]: ${message.message}`); this.logger.info(`${message.message}`, {
service: "bg-worker",
origin: message.name,
});
} }
} }
......
const winston = require("winston");
class Logger {
logger = console;
static _instance;
constructor() {
if (Logger._instance) return Logger._instance;
this.logger = process.env.NODE_ENV === 'production' ? this.getWinstonLogger() : console;
Logger._instance = this;
}
getWinstonLogger() {
const logger = winston.createLogger({
level: "info",
defaultMeta: { service: "backend" },
transports: [
new winston.transports.Console({
format: winston.format.combine(
winston.format.colorize(),
winston.format.printf(
({ level, message, service, origin = "" }) => {
return `\x1b[36m[${service}]\x1b[0m${origin ? `\x1b[33m[${origin}]\x1b[0m` : ""} ${level}: ${message}`;
}
)
),
}),
],
});
console.log = function () {
return logger.info.apply(logger, arguments);
};
console.error = function () {
return logger.error.apply(logger, arguments);
};
console.info = function () {
return logger.warn.apply(logger, arguments);
};
return logger;
}
}
/**
* Sets and overrides Console methods for logging when called.
* This is a singleton method and will not create multiple loggers.
* @returns {winston.Logger | console} - instantiated logger interface.
*/
function setLogger() {
return new Logger().logger;
}
module.exports = setLogger;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment