-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Renderer file logging transport #6795
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
03d51a7
Renderer file logging transport
samitiilikainen e1da883
Switch renderer file log level to info
samitiilikainen 528e18e
Unmount on pagehide instead of beforeunload
samitiilikainen 0c83cfb
Close log files on unmount
samitiilikainen da946cf
Improve file handle closing in different situations
samitiilikainen 7a4e3a7
Fix renderer log rotation
samitiilikainen e35e470
Switch back to beforeunload in root frame
samitiilikainen fbb17b7
Remove capturing phase event usage
samitiilikainen File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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,20 @@ | ||
/** | ||
* 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 { createLogger, format } from "winston"; | ||
import { loggerTransportInjectionToken } from "./logger/transports"; | ||
|
||
const winstonLoggerInjectable = getInjectable({ | ||
id: "winston-logger", | ||
instantiate: (di) => createLogger({ | ||
format: format.combine( | ||
format.splat(), | ||
format.simple(), | ||
), | ||
transports: di.injectMany(loggerTransportInjectionToken), | ||
}), | ||
}); | ||
|
||
export default winstonLoggerInjectable; |
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
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
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
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
22 changes: 22 additions & 0 deletions
22
packages/core/src/renderer/logger/close-renderer-log-file.injectable.ts
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,22 @@ | ||
/** | ||
* 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 winstonLoggerInjectable from "../../common/winston-logger.injectable"; | ||
import rendererFileLoggerTransportInjectable from "./file-transport.injectable"; | ||
|
||
const closeRendererLogFileInjectable = getInjectable({ | ||
id: "close-renderer-log-file", | ||
instantiate: (di) => { | ||
const winstonLogger = di.inject(winstonLoggerInjectable); | ||
const fileLoggingTransport = di.inject(rendererFileLoggerTransportInjectable); | ||
|
||
return () => { | ||
fileLoggingTransport.close?.(); | ||
winstonLogger.remove(fileLoggingTransport); | ||
}; | ||
}, | ||
}); | ||
|
||
export default closeRendererLogFileInjectable; |
44 changes: 44 additions & 0 deletions
44
packages/core/src/renderer/logger/file-transport.injectable.ts
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: "info", | ||
filename: `lens-renderer-${frameId}.log`, | ||
dirname: di.inject(directoryForLogsInjectable), | ||
maxsize: 1024 * 1024, | ||
maxFiles: 2, | ||
tailable: true, | ||
}); | ||
}, | ||
injectionToken: loggerTransportInjectionToken, | ||
}); | ||
|
||
export default rendererFileLoggerTransportInjectable; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usually the filename matches the injectable name/id ?