How to use hanami logger?

483 Views Asked by At

can you give examples of using hanami logger? I found some controversial Examples, some says it is already inside hanami(and you can use just logger.info('test'), unfortunately at least for me it is not working, I only see config for logger inside environment.rb), some says you need to install gem hanami-utils, then

require 'hanami/logger'
logger = Hanami::Logger.new('Test', level: 'info')
logger.info('test')

It works, but how to require it to all modules? Or only way to use global variables and say rubocop don't worry on every logger line? Sorry for may be stupid question ruby and hanami is new world for me.

1

There are 1 best solutions below

0
On

The Hanami.logger is part of a Hanami App. It is loaded automatically, so can use it without requiring.

Hanami.logger.debug("Hello")

You can do some logging configuration at config/environment.rb

If you need special behavior you could use a custom logger