Add a method to list the current named logging levels

Barry barry at barrys-emacs.org
Fri Sep 3 13:49:44 EDT 2021



> On 2 Sep 2021, at 23:38, Dieter Maurer <dieter at handshake.de> wrote:
> 
> Edward Spencer wrote at 2021-9-2 10:02 -0700:
>> Sometimes I like to pass the logging level up to the command line params so my user can specific what level of logging they want. However there is no easy method for pulling the named logging level names.
>> 
>> Looking into the code, it would actually be incredibly easy to implement;
>> 
>> in `logging.__init__.py`;
>> 
>> def listLevelNames():
>>   return _nameToLevel.keys()
>> 
>> You could obviously add some other features, like listing only the defaults, sorted by numerical level or alphabetically, etc. But really this basic implementation would be enough to expose the internal variables which shouldn't be accessed because they change (and in fact, between python 2 and 3, they did).
>> 
>> Any thoughts?
> 
> Usually, you use 5 well known log levels: "DEBUG", "INFO", "WARNING",
> "ERROR" and "CRITICAL".
> No need to provide a special function listing those levels.

I add my own levels, but then I know I did it.

Barry

> 
> 
> 
> --
> Dieter
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 



More information about the Python-list mailing list