diff --git a/.gitignore b/.gitignore index 53701a44d2..d6efc880e7 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ static/build/** binaries/client/ binaries/server/ locales/**/**.js +lens.log diff --git a/src/main/index.ts b/src/main/index.ts index 3014b78c41..e4fd246467 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -21,7 +21,7 @@ import logger from "./logger" const workingDir = path.join(app.getPath("appData"), appName); app.setName(appName); -if(!process.env.CICD) { +if (!process.env.CICD) { app.setPath("userData", workingDir); } @@ -49,7 +49,8 @@ async function main() { try { proxyPort = await getFreePort() } catch (error) { - await dialog.showErrorBox("Lens Error", "Could not find a free port for the cluster proxy") + logger.error(error) + dialog.showErrorBox("Lens Error", "Could not find a free port for the cluster proxy") app.quit(); } @@ -68,7 +69,7 @@ async function main() { proxyServer = LensProxy.create(proxyPort, clusterManager); } catch (error) { logger.error(`Could not start proxy (127.0.0:${proxyPort}): ${error.message}`) - await dialog.showErrorBox("Lens Error", `Could not start proxy (127.0.0:${proxyPort}): ${error.message || "unknown error"}`) + dialog.showErrorBox("Lens Error", `Could not start proxy (127.0.0:${proxyPort}): ${error.message || "unknown error"}`) app.quit(); } diff --git a/src/main/logger.ts b/src/main/logger.ts index eab9478bf0..0d720b65ac 100644 --- a/src/main/logger.ts +++ b/src/main/logger.ts @@ -1,20 +1,30 @@ +import { app, remote } from "electron"; import winston from "winston" import { isDebugging } from "../common/vars"; -const options = { - colorize: true, +const consoleOptions: winston.transports.ConsoleTransportOptions = { handleExceptions: false, - json: false, level: isDebugging ? "debug" : "info", } +const fileOptions: winston.transports.FileTransportOptions = { + handleExceptions: false, + level: isDebugging ? "debug" : "info", + filename: "lens.log", + dirname: (app || remote.app).getPath("logs"), + maxsize: 16 * 1024, + maxFiles: 16, + tailable: true, +} + const logger = winston.createLogger({ format: winston.format.combine( winston.format.colorize(), winston.format.simple(), ), transports: [ - new winston.transports.Console(options), + new winston.transports.Console(consoleOptions), + new winston.transports.File(fileOptions), ], });