DEV Community

Discussion on: Say Goodbye to console.log from Production environment

Collapse
 
dikamilo profile image
dikamilo

I prefer to create a custom logger wrapper/class and use it in app. In react apps as custom context/provider with hook to get logger instance in components.

Why? Several advantages:

  • log to multiple services, not just console if necessary
  • different logger implementation for tests, you can mock logger methods and assert them in tests (if you have business flow logs, then this is useful)
  • different logger implementation for storybook: you can see logs as actions in storybook
  • production? Just use dummy logger that do nothing or log only to production services

"Checking every file, and deleting the statement is very time-consuming"
ESLint's rule to deny console logs + ignore them just in console logger implementation

Collapse
 
gulshanaggarwal profile image
Gulshan Aggarwal

Actually, while searching for the solution I had no idea about logger services so I solved it using the package. Yeah! thanks for the detailed solution ♥