How can I log(watchdog)? In D7 is used to log using Watchdog function. In D8, I see its gone and I should use something called the logging API.

What I a trying to do:


I have created a menu/route, mysite.com/logmessage
When user opens that url in browser, I want to log "hello" to the dblog.


Where should I register the service that D8 documentation says to do? Is it in the services.yml file in sites/default folder?

Can I just load the said class in my controller/module file and call the function for logging? Or should I explicitly extend the class first in my module before using the function?
There are many different types of logging, all called the same way as per the documentation:

\Drupal::logger('my_module')-&gt;alert($message);

\Drupal::logger('my_module')-&gt;info($message);

\Drupal::logger('my_module')-&gt;debug($message);


Just call this code anywhere in your module, if you want to register logmessage as a path you'll need to create my_module.routing.yml, etc.