-
Notifications
You must be signed in to change notification settings - Fork 10
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
Chore/replace logs with logger #15
Chore/replace logs with logger #15
Conversation
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.
The logger takes a string and then an object which is preferred over trying to include it in the string itself. This way we can pass any sort of metadata and we never see [Object object]
I would refactor back to the original way of passing objects as a second param. If it makes sense to include a single variable in the string do that but it's also good to just wrap that var in an object too
Indeed the problem you mention can be seen here. However does the second argument of the logger actually get logged somewhere? I don't remember if that is the current behavior. |
Yeah it does see this run. In my opinion it looks like it's treated as a second call to actually log it (that may be wrong and it's just how the formatting works) but it's effective and easily read. code reference |
I applied some changes and I will check later the arguments to add later. I might need to use the function from start-stop project: On another hand, logger.ok returns LogReturn, the previous logger returns Promise. I will recode the comment creation later. |
No no you shouldn't need that function. That's to create a HTML comment which is posted onto the issue. We just want to log any additional info that we can by passing an object to any
The previous logger was just a placeholder. It's logic or whatever it returned should be replaced with what the real Look here for one way that we handle using the |
@@ -169,7 +169,7 @@ export class Wallet extends Super { | |||
if (walletData.location_id === null) { | |||
throw new Error("Location ID is null"); | |||
} | |||
logger.debug("Enriching wallet location metadata", locationMetaData); | |||
logger.debug(`Enriching wallet location metadata ${locationMetaData}`); |
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.
Doesn't look right. The latter parameter is for JSON metadata. This is important for filtering/sorting the error class (the string) and then investigating the details (the metadata) in the SQL database
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.
Oh I see. Then, if I keep locationMetaData as a parameter, I need it to be a Partial, it does not match the locationMetaData type.
If I understand it well, I would need the logger method "debug" to handle locationMetaData ?
Sorry in advance for my questions, I am not well away of all the types used in the project:
The two types don't really match in this current state.
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.
wrap anything you pass as a second param in an object so that locationMetaData
is a key of {}
@@ -82,14 +34,14 @@ export async function plugin(inputs: PluginInputs, env: Env) { | |||
} catch (e) { | |||
if (e instanceof CommanderError) { | |||
if (e.code !== "commander.unknownCommand") { | |||
await context.logger.error(e.message); | |||
context.logger.error(e.message); |
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.
Perhaps I'm missing some large detail here but this used to write to our Supabase. I would expect this to be async.
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.
Yeah we removed all GitHub and Supabase integrations from the logger because it was dangerous to standardize it into plugins and have it be able to post directly to our db.
Also isn't it the case that we should only store to Supabase on .fatal()
and only from inside either the kernel or core plugins? This is a core plugin but in general I mean to confirm
I have suggested that the current logger implementation could be for non-core plugins and we have a core-logger which has the ability to post to our Supabase? Alternatively refactor the current logger but any way we refactor it opens us up to the issues we sought to resolve
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 can also post fatal to a dedicated telegram chat for us to triage. It might be simpler and more effective than a database specifically to triage errors.
Definitely for kernel. Not sure for plugins.
src/plugin.ts
Outdated
} | ||
} else { | ||
await context.logger.error(e); | ||
context.logger.error(`${e}`); |
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.
Seems unusual to coerce to a string with this syntax.
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 see, would it be better in this form ?
context.logger.error("", { error: e as Error });
Would it be necessary in that case to add a string as well?
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.
Typically we add a string yeah, avoid empty strings as much as possible.
context.logger.error("Error string", { e });
no need to cast as Error if you just pass the e
object
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.
Probably can just pass e object straight in instead of nesting inside another object.
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 the type expects to get the error within an object and not the error straight in, at least with our current version of the logger. Could be changed later.
If I must summarise what I must implement to get this PR done:
Do I miss something in the whole logic? |
Resolves #4
As intended I replaced Warn with Error for now.
I can replace it with anything else later if required.