question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom logger for nestjs-hasura

See original GitHub issue

Hi there,

Is there a way to override the default logger in nestjs-hasura? Would like to extend it to use our custom logger but I don’t really know how.

We are sending json logs to Google Cloud Logging, would love to use the same format, but the custom logger isn’t picked up by the module. Ex.:

{"context":"NestFactory","level":"info","message":"Starting Nest application...","timestamp":"2021-12-23T05:53:40.767Z"}
{"context":"InstanceLoader","level":"info","message":"ConfigHostModule dependencies initialized","timestamp":"2021-12-23T05:53:40.788Z"}
{"context":"InstanceLoader","level":"info","message":"DiscoveryModule dependencies initialized","timestamp":"2021-12-23T05:53:40.788Z"}
{"context":"InstanceLoader","level":"info","message":"AppModule dependencies initialized","timestamp":"2021-12-23T05:53:40.788Z"}
{"context":"InstanceLoader","level":"info","message":"TerminusModule dependencies initialized","timestamp":"2021-12-23T05:53:40.788Z"}
{"context":"InstanceLoader","level":"info","message":"ConfigModule dependencies initialized","timestamp":"2021-12-23T05:53:40.932Z"}
{"context":"InstanceLoader","level":"info","message":"ConfigModule dependencies initialized","timestamp":"2021-12-23T05:53:40.932Z"}
{"context":"InstanceLoader","level":"info","message":"FirebaseModule dependencies initialized","timestamp":"2021-12-23T05:53:40.933Z"}
{"context":"InstanceLoader","level":"info","message":"HasuraModule dependencies initialized","timestamp":"2021-12-23T05:53:40.933Z"}
{"context":"InstanceLoader","level":"info","message":"HealthchecksModule dependencies initialized","timestamp":"2021-12-23T05:53:40.933Z"}
{"context":"RoutesResolver","level":"info","message":"HealthchecksController {/healthcheck}:","timestamp":"2021-12-23T05:53:41.393Z"}
{"context":"RouterExplorer","level":"info","message":"Mapped {/healthcheck, GET} route","timestamp":"2021-12-23T05:53:41.395Z"}
{"context":"RouterExplorer","level":"info","message":"Mapped {/healthcheck/auth, GET} route","timestamp":"2021-12-23T05:53:41.396Z"}
{"context":"RoutesResolver","level":"info","message":"EventHandlerController {/hasura}:","timestamp":"2021-12-23T05:53:41.396Z"}
{"context":"RouterExplorer","level":"info","message":"Mapped {/hasura/events, POST} route","timestamp":"2021-12-23T05:53:41.396Z"}
[Nest] 65647   - 2021-12-22, 9:53:41 p.m.   [HasuraModule] Initializing Hasura Module
[Nest] 65647   - 2021-12-22, 9:53:41 p.m.   [HasuraModule] Discovered 1 hasura event handlers
[Nest] 65647   - 2021-12-22, 9:53:41 p.m.   [HasuraModule] Registering hasura event handlers from HealthchecksService
{"context":"NestApplication","level":"info","message":"Nest application successfully started","timestamp":"2021-12-23T05:53:41.418Z"}
{"context":"NestApplication","level":"info","message":"Application ready on port 4001","timestamp":"2021-12-23T05:53:41.420Z"}

We can see in the example that the logs are shown using Nest.js default logger instead.

Thanks!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
underfiskcommented, Feb 3, 2022

@foxted I have merged a PR that reverts the change from using Logger -> ConsoleLogger and we just need to do a new version so that its reflected in every package @WonderPanda When you can produce a new minor, that would be great

1reaction
underfiskcommented, Jan 10, 2022

I think we can create a factory for the logger so that you can use your own logger like the official Nestjs core package does Would you like to create a PR for that? I can do that if you prefer

Read more comments on GitHub >

github_iconTop Results From Across the Web

Build Fullstack Apps with NestJS, Hasura, and GraphQL APIs
In this post, we'll give a general overview to NestJS, how it works in the context of Hasura and how GraphQL APIs can...
Read more >
Logger | NestJS - A progressive Node.js framework
You can provide a custom logger implementation to be used by Nest for system ... Implementing your own custom logger is straightforward.
Read more >
Event-driven apps with Hasura and NestJS made simple
A demo of how Jesse Carter's NestJS integration with Hasura lets you add custom business logic using cron/event triggers to your app in ......
Read more >
Full Stack GraphQL Apps with NestJS and Hasura - YouTube
A workshop on how to build fullstack GraphQL apps using NestJS, TypeScript, and Hasura, hosted by Hasura's Gavin Ray and Jesse Carter, ...
Read more >
awesome-nestjs/README.md at master - GitHub
NestJS HTTP Boilerplate - A template for NestJS, Fastify, Typegoose, Vitest, custom Logger implementation, Redis and more, fast and simple boilerplate.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found