django command logging levels

205 views
Skip to first unread message

co1632...@gmail.com

unread,
Feb 15, 2019, 4:38:45 PM2/15/19
to Django users

Django command interface has the following CLI arg

  -v {0,1,2,3}, --verbosity {0,1,2,3}
                        Verbosity level; 0=minimal output, 1=normal output,
                        2=verbose output, 3=very verbose output

It doesn't connect with the logging levels used by the commands, so the commands don't show extra information.

So is this an incompatibility or I have to add some arguments to my custom management commands ?

Dan Davis

unread,
Feb 15, 2019, 5:42:07 PM2/15/19
to Django users
The common verbosity will be passed to the handler:

class Command(BaseCommand):
    ...
    def handler(**kwargs):
         verbosity = kwargs['verbosity']


I tried to get clever once and not have **kwargs, but Django sends that common stuff, like '--settings", and it is good for me to pay attention.

OTOH, if you want to know whether this has anything to do with Python's logging module, it doesn't - that all depends on your settings file contents.

co1632...@gmail.com

unread,
Feb 16, 2019, 4:41:23 AM2/16/19
to Django users
But I have added a logger setting in my django settings file, then also do I have to add verbosity setting arg in my custom management command ?

Jason

unread,
Feb 16, 2019, 7:47:10 AM2/16/19
to Django users
verbosity is varying levels of output.  management commands output to stdout directly, which is different from logging.

I would suggest you look at the implementation of the included django management commands and see how they handle verbosity settings.  For example, makemigrations has different levels of output when you search for verbosity

Jason

unread,
Feb 16, 2019, 7:50:15 AM2/16/19
to Django users
however, if you want to incorporate logging levels, like DEBUG, INFO, WARN in your management commands and have them correspond to a verbosity level check out https://www.crccheck.com/blog/django-management-commands-and-verbosity/

co1632...@gmail.com

unread,
Feb 16, 2019, 9:38:42 AM2/16/19
to Django users
Thank U for help. I will check the links to get more info :-)
Reply all
Reply to author
Forward
0 new messages