Hi, this may be a basic question, sorry if I missed the answer in the documentation… How do you add logging capabilities to a module’s code?
See Dubugging in the Omeka S developer docs, under “Logging elsewhere”.
Yes, thanks Jim, I had read that before posting, I could not get it working. Do you have a functional sample?
For example, in Module.php, in a event handler or wherever you can get the service locator, add the following:
$logger = $this->getServiceLocator()->get('Omeka\Logger');
$logger->notice('Test logger');
Make sure your log file is writable by the web server, and that you’ve enabled logging in config/local.config.php.
Thanks Jim, that’s roughly what I had tried… Using the info() method did not work even after having reduced the priority to INFO. Fortunately, notice() works as expected!
Btw, I think there are typos in the Debugging page: $logger()->info('...') should certainly be $logger->info('...'), right?
When it’s using the controller plugin, it would be properly $this->logger()->info() and so on. The part about running within jobs, getting the Logger object and calling to it directly, that should be $logger->info(), yes.
As for “info” not working, that should be just down to your logger configuration’s priority setting, which does default to notice (so debug and info will not be printed). I think you’re saying that didn’t work, but it should, unless there’s some problem with your local.config.php, or maybe if you have a module that affects logging it might be substituting its own settings.
Ok thanks John, I’ll check that the module config does override the local one.