Mopidy debug logging under systemd

I’m having difficulty understanding logging in Mopidy. I’m working on a backend and would like some debug logging (while running via systemd).

logging.conf (pointed to by mopidy.conf)

[loggers]
keys = root

[handlers]
keys = fileHandler

[formatters]
keys = simpleFormatter

[logger_root]
handlers = fileHandler

[handler_fileHandler]
class = FileHandler
formatter = simpleFormatter
level = INFO
args = ('/var/log/mopidy/mopidy.log',)

[formatter_simpleFormatter]
format = %(asctime)s %(levelname)s [%(process)d:%(threadName)s] %(name)s: %(message)s
datefmt =

And in my playback.py

import logging

from mopidy import backend

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

class CalmRadioPlayback(backend.PlaybackProvider):
	def translate_uri(self, uri):
		logger.info('Translate URI: %s' % uri)
		logger.debug('Translate URI (debug): %s' % uri)

I would expect that, explicitly setting the logger level, I would get both info and debug logging … but I get only info. What am I missing? (new to mopidy and python … be kind :confused:)

Bumping this … hoping someone can point me in the right direction.

Your code to set the level to DEBUG will execute when the module is imported. But then later, when Mopidy actually starts running, it’ll set the logging level to INFO as defined in your config.

I’d personally scrap all that logging.conf and use the loglevels/* section within your mopidy.conf. So if I wanted to have DEBUG logging for just Mopidy-Spotify’s playlists module and TRACE debugging for the web module: I’d do:

[loglevels]
mopidy_spotify.playlists = DEBUG
mopidy_spotify.web = TRACE

But when I am developing I’d always be using a develop environment and regular stdout logging, not systemd. Not that it makes much different here when it comes to logging, it’s just generally easier to work with.

Thank you for your response and advice. I tried using [loglevels] with no real success … but I’ll revisit that. One of the backends I’m working on has an intermittent failure … could be only once or twice a day. Thought the mopidy log file would be the best way to go.

Maybe try running under pdb with breakpoints to catch the failure mode?

Thanks for all your help. For whatever reason, [loglevels] does not work for me.
I was able to achieve what I wanted in a particular file with:

import logging

from mopidy import backend

logger = logging.getLogger(__name__)

handler = logging.FileHandler('var/log/mopidy/calmradio.log')
formatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)

class CalmRadioPlayback(backend.PlaybackProvider):
        def translate_uri(self, uri):
               logger.debug('Translate URI: %s' % uri)

If you want to share the config you tried and the name of your module we can try and work out why that is. Otherwise, I wish you luck with your debugging.