-
Notifications
You must be signed in to change notification settings - Fork 310
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
feat: Adds extension name as prefix when extension is using logger #872
Conversation
@benoitf I apologize as I am still relatively new to everything. This is where I am at right now, I thought it would be more productive to open a PR review and ask for some guidance on how to get it right rather than continue shooting in the dark as it were. Am I on the right track? |
Helo @sfrunza13 It's inside the 'patched' console.log method that we should be 'smarter' and see if it's an extension that is calling us or not. so probably, look at the stack trace, if stack is coming from an extension, grab the name we probably need to retrieve some values from extensionLoader class (like the name of the root extension folder or all extension folders used |
@benoitf how is this? What would you advise to improve it? |
@sfrunza13 I would not hard code the list of possible extensions I would ask extensionLoader to grab the current root directory for extensions or the set of directories that are currently loaded |
but it looks very promising 🎉 thanks for looking at it |
And FYI, to get a stack, no need to throw and catch const stack = new Error().stack |
packages/main/src/plugin/index.ts
Outdated
} | ||
|
||
if(stack!=''){ | ||
var extensionGroupings = stack.match(/(podman\-desktop\\extensions)\\(lima|crc|docker|kube\-context|podman)\\(dist\\extension\.js)+:/) |
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.
note that it could be other JavaScript object than the entrypoint and it's not forced to be named extension.js
So here probably we should just check if parent folder is part of an extension
Currently, I can think of 2 ways of going about it, both of which involve creating a private variable in index.ts to have the extension ids in a scope I can work with. Either have my knowledge of the extension ids tied to extensionLoader.start() by retrieving them with .listExtensions(), in which case I can not append the prefix to logs that occur before this, or import path to index.ts and duplicate the read logic found within .start() right after the creation of the extensionLoader. Are either of these acceptable? I am certain I am missing a better solution. |
Hello @sfrunza13 We want to prefix the logging for extensions so it's ok to wait that extensionLoader is created to add a reference packages/main/src/plugin/index.ts const extensionLoader = new ExtensionLoader( then in redirectConsole() method you'll access to extensionLoader from there (if extensionLoader is not defined, we don't try to add a prefix So redirectConsole should have all elements before an extension is started. |
@benoitf I tried using listExtensions() but the analyzedExtensions member that it is trying to return do not seem to be populated until after the extensionLoader.start() method and not the extensionLoader creation. So what I have done is I factored out the extension file reading from the start() method and I used that to build my list of extensionNames to check against. Is this ok? |
Hi @sfrunza13 I'm not sure to get all of it. But I would assume that it's ok to only try to call listExtensions only when extensionLoader is defined. it's ok if it's not populated until the start of extension loader as we populate the list before activating the extensions (and this is where the extension is starting) |
@benoitf I think this time I might have got the idea |
packages/main/src/plugin/index.ts
Outdated
//Take the id information from extensionLoader | ||
let validExtObj = await this.extensionLoader.listExtensions(); | ||
|
||
validExtObj.forEach((extInfo: any) => { |
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.
AFAIK the type is not any, we have a known type returned by listExtensions()
packages/main/src/plugin/index.ts
Outdated
let validExtObj = await this.extensionLoader.listExtensions(); | ||
|
||
validExtObj.forEach((extInfo: any) => { | ||
validExt.push(extInfo.id); |
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.
I think we should grab the path of the extension (add that information in the info object)
so we don't hardcode some path in the regexp
packages/main/src/plugin/index.ts
Outdated
const re = new RegExp(`(podman\-desktop\\\\extensions)\\\\(${insert})`) | ||
var extensionGroupings = stack.match(re) | ||
if (extensionGroupings != null) | ||
return '[' + extensionGroupings[2] + ']'; |
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.
we need to display the extension name, not the id, so we should keep the mapping extension path<--> extension name
How's this? |
FYI I tested it and it does not work on my computer
|
packages/main/src/plugin/index.ts
Outdated
//Check if index.ts private member extensionLoader initialized | ||
//If it is grab listExtensions() | ||
if(this.extensionLoader != undefined){ | ||
let validExtObj = await this.extensionLoader.listExtensions(); | ||
//start setting path => name | ||
validExtObj.forEach((extInfo: ExtensionInfo) => { | ||
extensions.set(extInfo.path, extInfo.name) | ||
}) | ||
} |
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.
as an improvement, I think we should build objects only if extension list is changing.
It'll cost too many iteration to do that on each log call.
packages/main/src/plugin/index.ts
Outdated
let searchString = path.replace("/","\\") | ||
searchString = searchString.replaceAll("\\", "\\\\") | ||
let re = new RegExp(`${searchString}`) |
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.
FYI on my computer, it's not working
packages/main/src/plugin/index.ts
Outdated
}) | ||
|
||
if (toAppend != '') | ||
return '[' + toAppend + ']'; |
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.
return '[' + toAppend + ']'; | |
return `[${toAppend}]`; |
@sfrunza13 you'll need to sign off the commits And apply linter/formatter |
thanks for linter and formatter. The DCO check is still need. You may have to squash all your commits into a single one |
71a5c81
to
35136ee
Compare
Check stack for extensions retrieved from extensionloader, then append them to log (podman-desktop#822) Signed-off-by: stefanaz2 <sfrunza@seneca.ca>
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.
thanks @sfrunza13 for the contribution 👍
Activating extension (crc)
[crc] Can not find CRC binary!
Activation extension (crc) ended
Activating extension (lima)
[lima] Could not find podman socket at /Users/benoitf/.lima/podman-lima/sock/podman.sock nor /Users/benoitf/.lima/podman-lima/sock/podman.sock
in a next improvement (not this PR), we may reformat the logging of Activating/Deactivating extensions using the same pattern
so instead of
Activating extension (lima)
[lima] Could not find podman socket at /Users/benoitf/.lima/podman-lima/sock/podman.sock nor /Users/benoitf/.lima/podman-lima/sock/podman.sock
Activation extension (lima) ended
[lima] Activating extension...
[lima] Could not find podman socket at /Users/benoitf/.lima/podman-lima/sock/podman.sock nor /Users/benoitf/.lima/podman-lima/sock/podman.sock
[lima] Activation extension succeed
@benoitf Thank you for your patience and guidance |
What does this PR do?
I am aiming to create a wrapper for some of the logging so that we can have a prefix for each separate extension.
Screenshot/screencast of this PR
Something similar to this
What issues does this PR fix or reference?
#822
How to test this PR?
Check logs originating from extensions folder for the appropriate names
Signed-off-by: Stefan Frunza stefanfrunza@gmail.com