Skip to content
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

Conversation

wolfmic
Copy link

@wolfmic wolfmic commented Aug 18, 2024

Resolves #4

As intended I replaced Warn with Error for now.
I can replace it with anything else later if required.

src/plugin.ts Outdated Show resolved Hide resolved
src/plugin.ts Outdated Show resolved Hide resolved
src/plugin.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@Keyrxng Keyrxng left a 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

@gentlementlegen
Copy link
Member

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.

@Keyrxng
Copy link
Contributor

Keyrxng commented Aug 18, 2024

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

@wolfmic
Copy link
Author

wolfmic commented Aug 18, 2024

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: createStructuredMetadata, it might be a good step to achieve it.

On another hand, logger.ok returns LogReturn, the previous logger returns Promise.
I kinda wonder how to handle that part.

I will recode the comment creation later.

@Keyrxng
Copy link
Contributor

Keyrxng commented Aug 18, 2024

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: createStructuredMetadata, it might be a good step to achieve it.

On another hand, logger.ok returns LogReturn, the previous logger returns Promise. I kinda wonder how to handle that part.

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 Logs function after the initial string.

LogReturn contains two versions of the message being passed in which is used for posting the comments to GitHub amongst other things and each Logs function returns this.

The previous logger was just a placeholder. It's logic or whatever it returned should be replaced with what the real Logs returns.

Look here for one way that we handle using the LogReturn object for reference. We are adopting a 'bubble all errors up to the entry' approach slowly but surely

@@ -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}`);
Copy link
Member

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

Copy link
Author

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.

Copy link
Contributor

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);
Copy link
Member

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.

Copy link
Contributor

@Keyrxng Keyrxng Aug 18, 2024

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

Copy link
Member

@0x4007 0x4007 Aug 18, 2024

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}`);
Copy link
Member

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.

Copy link
Author

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?

Copy link
Contributor

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

Copy link
Member

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.

Copy link
Member

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.

@wolfmic
Copy link
Author

wolfmic commented Aug 19, 2024

If I must summarise what I must implement to get this PR done:

Do I miss something in the whole logic?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change logs to use ubiquity-dao/ubiquibot-logger
4 participants