-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add file logging to renderer, writing separate log files for renderer main frame and each cluster frame. Related to lensapp/support-lens-extension#118 Signed-off-by: Sami Tiilikainen <97873007+samitiilikainen@users.noreply.github.com>
- Loading branch information
1 parent
56197d8
commit a7496aa
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Copyright (c) OpenLens Authors. All rights reserved. | ||
* Licensed under MIT License. See LICENSE in root directory for more information. | ||
*/ | ||
import { getInjectable } from "@ogre-tools/injectable"; | ||
import { transports } from "winston"; | ||
import directoryForLogsInjectable from "../../common/app-paths/directory-for-logs.injectable"; | ||
import { loggerTransportInjectionToken } from "../../common/logger/transports"; | ||
import windowLocationInjectable from "../../common/k8s-api/window-location.injectable"; | ||
import currentlyInClusterFrameInjectable from "../routes/currently-in-cluster-frame.injectable"; | ||
import { getClusterIdFromHost } from "../utils"; | ||
|
||
const rendererFileLoggerTransportInjectable = getInjectable({ | ||
id: "renderer-file-logger-transport", | ||
instantiate: (di) => { | ||
let frameId: string; | ||
|
||
const currentlyInClusterFrame = di.inject( | ||
currentlyInClusterFrameInjectable, | ||
); | ||
|
||
if (currentlyInClusterFrame) { | ||
const { host } = di.inject(windowLocationInjectable); | ||
const clusterId = getClusterIdFromHost(host); | ||
|
||
frameId = clusterId ? `cluster-${clusterId}` : "cluster"; | ||
} else { | ||
frameId = "main"; | ||
} | ||
|
||
return new transports.File({ | ||
handleExceptions: false, | ||
level: "debug", | ||
filename: `lens-renderer-${frameId}.log`, | ||
dirname: di.inject(directoryForLogsInjectable), | ||
maxsize: 1024 * 1024, | ||
maxFiles: 0, | ||
tailable: true, | ||
}); | ||
}, | ||
injectionToken: loggerTransportInjectionToken, | ||
}); | ||
|
||
export default rendererFileLoggerTransportInjectable; |