Preferred style for logging facility calls

Currently, the Skill Development documentation does not seem to cover logging (https://mycroft-ai.gitbook.io/docs/skill-development/introduction). In examining a few skills, I see two or three “styles”, examples below. Maybe the “getLogger” function is just a helper method or something, I’m not really sure. What is the current recommended/preferred style of setting up and calling logging functions?
To be clear, I’m not trying to get logging to work, that is already achieved. I’m trying to be consistent and future-proof in the code.

in daily_meditation:

   from mycroft.util.log import getLogger
    ...
    LOGGER = getLogger(__name__)
    ...
                LOGGER.error("Error: {0}".format(e))

in fallback-AIML and mycroft-mark-1.mycroftai::

from mycroft.util.log import LOG
...
        LOG.info('Loading Brain')

in mycroft-timer.mycroftai and mycroft-spotify.forslund:

  from mycroft.util.log import LOG
   ...
                   self.log.error('Couldn\'t allocate mixer, {}'.format(repr(e)))
   ...
           self.log.info(dump)
1 Like

Hey there,

This is a great post showing the evolution of logging over time!

The last one is the current recommended format. The log method is also now available directly from the MycroftSkill class so no need to import anything.

I updated the HelloWorld Skill a few weeks ago to show how this should be used but it definitely deserves its own section in the docs.

The Skill Dev docs are what I’m working on at the moment, so you might see some new/moving pages over the next few weeks. If there are any other topics that you find aren’t covered, please let us know about those too :slight_smile:

2 Likes

Thanks for the clarification. The addition to the standard docs will be really helpful.

I had not taken a look in the HelloWorld skill, but I did create a brand new skill with msk, which did not contain an example logging line. Perhaps that is intended to keep it minimal, but I think it would be worth it. Especially if two or three things seem to be in agreement, that can give an answer seeker confidence.