Skip to content

Commit

Permalink
Allow for users to enabled release mode debugging (lensapp#481)
Browse files Browse the repository at this point in the history
* Allow for users to enabled release mode debugging by setting the env var `DEBUG` to "true"

* Adds file logging so that in production logs can still be
  obtained. Those log files are limited the size and number and are rotated automatically

Signed-off-by: Sebastian Malton <smalton@mirantis.com>

Co-authored-by: Sebastian Malton <smalton@mirantis.com>
  • Loading branch information
Nokel81 and Sebastian Malton authored Sep 1, 2020
1 parent 533646c commit cb3e19f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ static/build/**
binaries/client/
binaries/server/
locales/**/**.js
lens.log
7 changes: 4 additions & 3 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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();
}

Expand All @@ -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();
}

Expand Down
18 changes: 14 additions & 4 deletions src/main/logger.ts
Original file line number Diff line number Diff line change
@@ -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),
],
});

Expand Down

0 comments on commit cb3e19f

Please sign in to comment.