1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

improve logger

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen 2021-08-05 16:18:20 +03:00
parent e102ed0a6f
commit 0aff83947b
3 changed files with 50 additions and 10 deletions

View File

@ -15,7 +15,7 @@
"dev": "concurrently -i -k \"yarn run dev-run -C\" yarn:dev:*", "dev": "concurrently -i -k \"yarn run dev-run -C\" yarn:dev:*",
"dev-build": "concurrently yarn:compile:*", "dev-build": "concurrently yarn:compile:*",
"debug-build": "concurrently yarn:compile:main yarn:compile:extension-types", "debug-build": "concurrently yarn:compile:main yarn:compile:extension-types",
"dev-run": "nodemon --watch static/build/main.js --exec \"electron --remote-debugging-port=9223 --inspect=9229 .\"", "dev-run": "nodemon --watch static/build/main.js --exec \"electron --remote-debugging-port=9223 --inspect .\"",
"dev:main": "yarn run compile:main --watch", "dev:main": "yarn run compile:main --watch",
"dev:renderer": "yarn run webpack-dev-server --config webpack.renderer.ts", "dev:renderer": "yarn run webpack-dev-server --config webpack.renderer.ts",
"dev:extension-types": "yarn run compile:extension-types --watch", "dev:extension-types": "yarn run compile:extension-types --watch",
@ -246,6 +246,7 @@
"uuid": "^8.3.2", "uuid": "^8.3.2",
"win-ca": "^3.2.0", "win-ca": "^3.2.0",
"winston": "^3.3.3", "winston": "^3.3.3",
"winston-console-format": "^1.0.8",
"winston-transport-browserconsole": "^1.0.5", "winston-transport-browserconsole": "^1.0.5",
"ws": "^7.4.6" "ws": "^7.4.6"
}, },

View File

@ -19,15 +19,46 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
import { app, remote } from "electron"; import { app, ipcMain, remote } from "electron";
import winston from "winston"; import winston from "winston";
import { consoleFormat } from "winston-console-format";
import { isDebugging, isTestEnv } from "./vars"; import { isDebugging, isTestEnv } from "./vars";
import BrowserConsole from "winston-transport-browserconsole";
const logLevel = process.env.LOG_LEVEL ? process.env.LOG_LEVEL : isDebugging ? "debug" : "info"; const logLevel = process.env.LOG_LEVEL ? process.env.LOG_LEVEL : isDebugging ? "debug" : "info";
const consoleOptions: winston.transports.ConsoleTransportOptions = { let consoleOptions: winston.transports.ConsoleTransportOptions;
handleExceptions: false,
level: logLevel, if (ipcMain) {
}; consoleOptions = {
handleExceptions: false,
level: logLevel,
format: winston.format.combine(
winston.format.colorize({ level: true, message: false}),
winston.format.padLevels(),
winston.format.ms(),
consoleFormat({
showMeta: true,
inspectOptions: {
depth: 4,
colors: true,
maxArrayLength: 10,
breakLength: 120,
compact: Infinity,
},
})
)
};
} else {
consoleOptions = {
handleExceptions: false,
level: logLevel,
format: winston.format.combine(
winston.format.colorize({ level: true, message: false}),
)
};
}
const fileOptions: winston.transports.FileTransportOptions = { const fileOptions: winston.transports.FileTransportOptions = {
handleExceptions: false, handleExceptions: false,
level: logLevel, level: logLevel,
@ -39,11 +70,10 @@ const fileOptions: winston.transports.FileTransportOptions = {
}; };
const logger = winston.createLogger({ const logger = winston.createLogger({
format: winston.format.combine( format: winston.format.combine(
winston.format.colorize(), winston.format.simple()
winston.format.simple(),
), ),
transports: [ transports: [
new winston.transports.Console(consoleOptions), ipcMain ? new winston.transports.Console(consoleOptions) : new BrowserConsole(),
...(isTestEnv ? [] : [new winston.transports.File(fileOptions)]), ...(isTestEnv ? [] : [new winston.transports.File(fileOptions)]),
], ],
}); });

View File

@ -4089,7 +4089,7 @@ colors@1.0.3:
resolved "https://registry.yarnpkg.com/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b" resolved "https://registry.yarnpkg.com/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b"
integrity sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs= integrity sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs=
colors@^1.1.2, colors@^1.2.1: colors@^1.1.2, colors@^1.2.1, colors@^1.4.0:
version "1.4.0" version "1.4.0"
resolved "https://registry.yarnpkg.com/colors/-/colors-1.4.0.tgz#c50491479d4c1bdaed2c9ced32cf7c7dc2360f78" resolved "https://registry.yarnpkg.com/colors/-/colors-1.4.0.tgz#c50491479d4c1bdaed2c9ced32cf7c7dc2360f78"
integrity sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA== integrity sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==
@ -15288,6 +15288,15 @@ win-ca@^3.2.0:
node-forge "^0.8.2" node-forge "^0.8.2"
split "^1.0.1" split "^1.0.1"
winston-console-format@^1.0.8:
version "1.0.8"
resolved "https://registry.yarnpkg.com/winston-console-format/-/winston-console-format-1.0.8.tgz#591adc8e9567c3397a3fa2e29e596d56e48db840"
integrity sha512-dq7t/E0D0QRi4XIOwu6HM1+5e//WPqylH88GVjKEhQVrzGFg34MCz+G7pMJcXFBen9C0kBsu5GYgbYsE2LDwKw==
dependencies:
colors "^1.4.0"
logform "^2.2.0"
triple-beam "^1.3.0"
winston-transport-browserconsole@^1.0.5: winston-transport-browserconsole@^1.0.5:
version "1.0.5" version "1.0.5"
resolved "https://registry.yarnpkg.com/winston-transport-browserconsole/-/winston-transport-browserconsole-1.0.5.tgz#8ef1bc32da5fb0a66604f2b8b6f127ed725108c9" resolved "https://registry.yarnpkg.com/winston-transport-browserconsole/-/winston-transport-browserconsole-1.0.5.tgz#8ef1bc32da5fb0a66604f2b8b6f127ed725108c9"