-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Hey @shahednasser As we have logging docs, I would add a section on extending the logger. 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 |
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. |
Added documentation for logging.