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

docs: added documentation for logging #5469

Merged
merged 2 commits into from
Oct 25, 2023
Merged

docs: added documentation for logging #5469

merged 2 commits into from
Oct 25, 2023

Conversation

shahednasser
Copy link
Member

Added documentation for logging.

@shahednasser shahednasser requested a review from a team as a code owner October 25, 2023 09:04
@changeset-bot
Copy link

changeset-bot bot commented Oct 25, 2023

⚠️ No Changeset found

Latest commit: 2fe9386

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Oct 25, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
api-reference ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 25, 2023 9:18am
docs-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 25, 2023 9:18am
medusa-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 25, 2023 9:18am

@vercel vercel bot temporarily deployed to Preview – docs-ui October 25, 2023 09:05 Inactive
@vercel vercel bot temporarily deployed to Preview – docs-ui October 25, 2023 09:08 Inactive
@vercel vercel bot temporarily deployed to Preview – api-reference October 25, 2023 09:09 Inactive
@vercel vercel bot temporarily deployed to Preview – medusa-docs October 25, 2023 09:18 Inactive
@shahednasser shahednasser merged commit 8bb8eb5 into develop Oct 25, 2023
@shahednasser shahednasser deleted the docs/logging branch October 25, 2023 09:53
@uro
Copy link

uro commented Oct 25, 2023

Hey @shahednasser

As we have logging docs, I would add a section on extending the logger.
Medusa is using Winston logger, and it's a Singleton within our container, so we can create a simple loader and override transports within it. By doing that, we can create a new strategy of how we want to store logs/how to rotate them, etc.

As you can see, I am accessing private property below as there's no setter/getter. There is also another option to override the logger service.

1st:

loaders/logger.ts

transports = ... // winston transports

export default (container: AwilixContainer, config): void => {
  const logger = container.resolve<Logger>('logger');
  const loggerInstance = (logger as any).loggerInstance_ as winston.Logger;

  loggerInstance.configure({
    transports
  });
}

2nd:

// transports and logger instance configuration 
export class OurReporter extends Reporter {
  constructor() {
    // @ts-ignore
    const ora = MedusaLogger.ora_;

    super({
      logger: loggerInstance,
      activityLogger: ora,
    });
  }
...
export default (container: AwilixContainer, config): void => {
  container.dispose().then(() => {}); 

  container.register({
    [ContainerRegistrationKeys.LOGGER]: asClass(OurReporter)
  });
};

Definitely helpful as I struggled with it for a while.

So, what I achieved by doing that: I use Datadog for log aggregation. Medusa logger is not letting me use context parameters on log entries like info, warn,err etc. I had to override the logger instance to update the contracts. Thanks to that I can attach context to the logged entries and aggregate them across the request, order, product etc - it's simpler to investigate issues on later stage

@shahednasser
Copy link
Member Author

Thank you for the feedback @uro ! We actually intend to improve our logging in general, so I imagine our future implementation should provide the logging capabilities that wouldn't require you to extend the logger. That's a better approach than documenting how to extend the logger, especially since it's more of a per-use-case rather than something we currently encourage.

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.

2 participants