diff --git a/packages/api/package.json b/packages/api/package.json index 072635a4..1de46fe9 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -50,6 +50,7 @@ "node-cron": "^2.0.3", "on-finished": "^2.4.1", "pino": "^8.8.0", + "pino-multi-stream": "^6.0.0", "portfinder": "^1.0.28", "simple-encryptor": "^4.0.0", "ssh2": "^1.11.0", diff --git a/packages/api/src/index.js b/packages/api/src/index.js index 7271ea03..14c1c699 100644 --- a/packages/api/src/index.js +++ b/packages/api/src/index.js @@ -1,10 +1,12 @@ const { setLogger, getLogger, setLoggerName } = require('dbgate-tools'); const processArgs = require('./utility/processArgs'); const pino = require('pino'); +const pinoms = require('pino-multi-stream'); const fs = require('fs'); const moment = require('moment'); const path = require('path'); const { logsdir, setLogsFilePath, getLogsFilePath } = require('./utility/directories'); +const platformInfo = require('./utility/platformInfo'); if (processArgs.startProcess) { setLoggerName(processArgs.startProcess.replace(/Process$/, '')); @@ -30,38 +32,42 @@ function configureLogger() { setLogsFilePath(logsFilePath); setLoggerName('main'); - // let logger = pinoms({ - // redact: { paths: ['hostname'], remove: true }, - // streams: [ - // { - // stream: process.stdout, - // level: process.env.CONSOLE_LOG_LEVEL || process.env.LOG_LEVEL || 'info', - // }, - // { - // stream: fs.createWriteStream(logsFilePath), - // level: process.env.FILE_LOG_LEVEL || process.env.LOG_LEVEL || 'info', - // }, - // ], - // }); + const streams = []; + if (!platformInfo.isElectron) { + streams.push({ + stream: process.stdout, + level: process.env.CONSOLE_LOG_LEVEL || process.env.LOG_LEVEL || 'info', + }); + } - // @ts-ignore - let logger = pino({ - redact: { paths: ['hostname'], remove: true }, - transport: { - targets: [ - { - level: process.env.CONSOLE_LOG_LEVEL || process.env.LOG_LEVEL || 'info', - target: 'pino/file', - }, - { - level: process.env.FILE_LOG_LEVEL || process.env.LOG_LEVEL || 'info', - target: 'pino/file', - options: { destination: logsFilePath }, - }, - ], - }, + streams.push({ + stream: fs.createWriteStream(logsFilePath), + level: process.env.FILE_LOG_LEVEL || process.env.LOG_LEVEL || 'info', }); + let logger = pinoms({ + redact: { paths: ['hostname'], remove: true }, + streams, + }); + + // // @ts-ignore + // let logger = pino({ + // redact: { paths: ['hostname'], remove: true }, + // transport: { + // targets: [ + // { + // level: process.env.CONSOLE_LOG_LEVEL || process.env.LOG_LEVEL || 'info', + // target: 'pino/file', + // }, + // { + // level: process.env.FILE_LOG_LEVEL || process.env.LOG_LEVEL || 'info', + // target: 'pino/file', + // options: { destination: logsFilePath }, + // }, + // ], + // }, + // }); + setLogger(logger); } diff --git a/yarn.lock b/yarn.lock index 40af051e..6f4aca33 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3664,6 +3664,16 @@ duplexify@^3.4.2, duplexify@^3.6.0: readable-stream "^2.0.0" stream-shift "^1.0.0" +duplexify@^4.1.2: + version "4.1.2" + resolved "https://registry.yarnpkg.com/duplexify/-/duplexify-4.1.2.tgz#18b4f8d28289132fa0b9573c898d9f903f81c7b0" + integrity sha512-fz3OjcNCHmRP12MJoZMPglx8m4rrFP8rovnk4vT8Fs+aonZoCwGg10dSsQsfP/E62eZcPTMSMP6686fu9Qlqtw== + dependencies: + end-of-stream "^1.4.1" + inherits "^2.0.3" + readable-stream "^3.1.1" + stream-shift "^1.0.0" + ecc-jsbn@~0.1.1: version "0.1.2" resolved "https://registry.yarnpkg.com/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz#3a83a904e54353287874c564b7549386849a98c9" @@ -4292,7 +4302,7 @@ fast-levenshtein@~2.0.6: resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917" integrity sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw== -fast-redact@^3.1.1: +fast-redact@^3.0.0, fast-redact@^3.1.1: version "3.1.2" resolved "https://registry.yarnpkg.com/fast-redact/-/fast-redact-3.1.2.tgz#d58e69e9084ce9fa4c1a6fa98a3e1ecf5d7839aa" integrity sha512-+0em+Iya9fKGfEQGcd62Yv6onjBmmhV1uh86XVfOU8VwAe6kaFdQCWI9s0/Nnugx5Vd9tdbZ7e6gE2tR9dzXdw== @@ -8294,6 +8304,11 @@ object.pick@^1.3.0: dependencies: isobject "^3.0.1" +on-exit-leak-free@^0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/on-exit-leak-free/-/on-exit-leak-free-0.2.0.tgz#b39c9e3bf7690d890f4861558b0d7b90a442d209" + integrity sha512-dqaz3u44QbRXQooZLTUKU41ZrzYrcvLISVgbrzbyCMxpmSLJvZ3ZamIJIZ29P6OhZIkNIQKosdeM6t1LYbA9hg== + on-exit-leak-free@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/on-exit-leak-free/-/on-exit-leak-free-2.1.0.tgz#5c703c968f7e7f851885f6459bf8a8a57edc9cc4" @@ -8722,6 +8737,21 @@ pino-abstract-transport@^1.0.0, pino-abstract-transport@v1.0.0: readable-stream "^4.0.0" split2 "^4.0.0" +pino-abstract-transport@v0.5.0: + version "0.5.0" + resolved "https://registry.yarnpkg.com/pino-abstract-transport/-/pino-abstract-transport-0.5.0.tgz#4b54348d8f73713bfd14e3dc44228739aa13d9c0" + integrity sha512-+KAgmVeqXYbTtU2FScx1XS3kNyfZ5TrXY07V96QnUSFqo2gAqlvmaxH67Lj7SWazqsMabf+58ctdTcBgnOLUOQ== + dependencies: + duplexify "^4.1.2" + split2 "^4.0.0" + +pino-multi-stream@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/pino-multi-stream/-/pino-multi-stream-6.0.0.tgz#2116bca740cb5eb606f430b20fd480f4944b2b99" + integrity sha512-oCuTtaDSUB5xK1S45r9oWE0Dj8RWdHVvaGTft5pO/rmzgIqQRkilf5Ooilz3uRm0IYj8sPRho3lVx48LCmXjvQ== + dependencies: + pino "^7.0.0" + pino-pretty@^9.1.1: version "9.1.1" resolved "https://registry.yarnpkg.com/pino-pretty/-/pino-pretty-9.1.1.tgz#e7d64c1db98266ca428ab56567b844ba780cd0e1" @@ -8742,11 +8772,33 @@ pino-pretty@^9.1.1: sonic-boom "^3.0.0" strip-json-comments "^3.1.1" +pino-std-serializers@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/pino-std-serializers/-/pino-std-serializers-4.0.0.tgz#1791ccd2539c091ae49ce9993205e2cd5dbba1e2" + integrity sha512-cK0pekc1Kjy5w9V2/n+8MkZwusa6EyyxfeQCB799CQRhRt/CqYKiWs5adeu8Shve2ZNffvfC/7J64A2PJo1W/Q== + pino-std-serializers@^6.0.0: version "6.1.0" resolved "https://registry.yarnpkg.com/pino-std-serializers/-/pino-std-serializers-6.1.0.tgz#307490fd426eefc95e06067e85d8558603e8e844" integrity sha512-KO0m2f1HkrPe9S0ldjx7za9BJjeHqBku5Ch8JyxETxT8dEFGz1PwgrHaOQupVYitpzbFSYm7nnljxD8dik2c+g== +pino@^7.0.0: + version "7.11.0" + resolved "https://registry.yarnpkg.com/pino/-/pino-7.11.0.tgz#0f0ea5c4683dc91388081d44bff10c83125066f6" + integrity sha512-dMACeu63HtRLmCG8VKdy4cShCPKaYDR4youZqoSWLxl5Gu99HUw8bw75thbPv9Nip+H+QYX8o3ZJbTdVZZ2TVg== + dependencies: + atomic-sleep "^1.0.0" + fast-redact "^3.0.0" + on-exit-leak-free "^0.2.0" + pino-abstract-transport v0.5.0 + pino-std-serializers "^4.0.0" + process-warning "^1.0.0" + quick-format-unescaped "^4.0.3" + real-require "^0.1.0" + safe-stable-stringify "^2.1.0" + sonic-boom "^2.2.1" + thread-stream "^0.15.1" + pino@^8.8.0: version "8.8.0" resolved "https://registry.yarnpkg.com/pino/-/pino-8.8.0.tgz#1f0d6695a224aa06afc7ad60f2ccc4772d3b9233" @@ -8911,6 +8963,11 @@ process-nextick-args@~2.0.0: resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2" integrity sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag== +process-warning@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/process-warning/-/process-warning-1.0.0.tgz#980a0b25dc38cd6034181be4b7726d89066b4616" + integrity sha512-du4wfLyj4yCZq1VupnVSZmRsPJsNuxoDQFdCFHLaYiEbFBD7QE0a+I4D7hOxrVnh78QE/YipFAj9lXHiXocV+Q== + process-warning@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/process-warning/-/process-warning-2.1.0.tgz#1e60e3bfe8183033bbc1e702c2da74f099422d1a" @@ -9257,6 +9314,11 @@ readdirp@~3.6.0: dependencies: picomatch "^2.2.1" +real-require@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/real-require/-/real-require-0.1.0.tgz#736ac214caa20632847b7ca8c1056a0767df9381" + integrity sha512-r/H9MzAWtrv8aSVjPCMFpDMl5q66GqtmmRkRjpHTsp4zBAa+snZyiQNlMONiUmEJcsnaw0wCauJ2GWODr/aFkg== + real-require@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/real-require/-/real-require-0.2.0.tgz#209632dea1810be2ae063a6ac084fee7e33fba78" @@ -9618,7 +9680,7 @@ safe-regex@^1.1.0: dependencies: ret "~0.1.10" -safe-stable-stringify@^2.3.1: +safe-stable-stringify@^2.1.0, safe-stable-stringify@^2.3.1: version "2.4.2" resolved "https://registry.yarnpkg.com/safe-stable-stringify/-/safe-stable-stringify-2.4.2.tgz#ec7b037768098bf65310d1d64370de0dc02353aa" integrity sha512-gMxvPJYhP0O9n2pvcfYfIuYgbledAOJFcqRThtPRmjscaipiwcwPPKLytpVzMkG2HAN87Qmo2d4PtGiri1dSLA== @@ -9971,6 +10033,13 @@ socks@^2.6.1, socks@^2.6.2: ip "^2.0.0" smart-buffer "^4.2.0" +sonic-boom@^2.2.1: + version "2.8.0" + resolved "https://registry.yarnpkg.com/sonic-boom/-/sonic-boom-2.8.0.tgz#c1def62a77425090e6ad7516aad8eb402e047611" + integrity sha512-kuonw1YOYYNOve5iHdSahXPOK49GqwA+LZhI6Wz/l0rP57iKyXXIHaRagOBHAPmGwJC6od2Z9zgvZ5loSgMlVg== + dependencies: + atomic-sleep "^1.0.0" + sonic-boom@^3.0.0, sonic-boom@^3.1.0: version "3.2.1" resolved "https://registry.yarnpkg.com/sonic-boom/-/sonic-boom-3.2.1.tgz#972ceab831b5840a08a002fa95a672008bda1c38" @@ -10633,6 +10702,13 @@ text-table@^0.2.0: resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4" integrity sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw== +thread-stream@^0.15.1: + version "0.15.2" + resolved "https://registry.yarnpkg.com/thread-stream/-/thread-stream-0.15.2.tgz#fb95ad87d2f1e28f07116eb23d85aba3bc0425f4" + integrity sha512-UkEhKIg2pD+fjkHQKyJO3yoIvAP3N6RlNFt2dUhcS1FGvCD1cQa1M/PGknCLFIyZdtJOWQjejp7bdNqmN7zwdA== + dependencies: + real-require "^0.1.0" + thread-stream@^2.0.0: version "2.3.0" resolved "https://registry.yarnpkg.com/thread-stream/-/thread-stream-2.3.0.tgz#4fc07fb39eff32ae7bad803cb7dd9598349fed33"