What is verbosity level exactly in python?(difference between each level)

10,689

Verbosity level is related just to logging. In unit tests you find it for the logging of the information.

Note: It is more pythonic to use levels as constant names(logging.INFO, logging.DEBUG rather than numbers.

These levels decide the amount of information you will get. For example setting the level to ERROR for running unit tests will display only the cases for which the unit tests failed. Setting it to DEBUG will give you more (the most in fact) info such as what were the values of the variables (in assert statements etc).

It is more useful in cases where your program has different levels of logging and you want your users to see different levels of info. For eg. usually you don't want the users to see details of internals, apart from fatal errors. So users will be running the program in FATAL or CRITICAL mode. But when some error occurs you will need such details. In this case you will run the program in debug mode. You can issue custom messages with these levels too. For eg, if you are providing back compatibility with older versions of your program, you can WARN them with logging.warn(), which will be issued only when the logging level is warning or less.


DOCS:

Level related stuff

Default levels and level names, these can be replaced with any positive set of values having corresponding names. There is a pseudo-level, NOTSET, which is only really there as a lower limit for user-defined levels. Handlers and loggers are initialized with NOTSET so that they will log all messages, even at user-defined levels.

CRITICAL = 50 
FATAL = CRITICAL
ERROR = 40 
WARNING = 30 
WARN = WARNING
INFO = 20 
DEBUG = 10 
NOTSET = 0
Share:
10,689
chao787
Author by

chao787

My name is Richard. Interesting about python and Emacs, NLP or AI-related area.

Updated on July 30, 2022

Comments

  • chao787
    chao787 over 1 year

    What is the verbosity level in python. I see it in unittest.

    In documentation it just say simply that higher verbosity level, more info print out. but more means what? That is to say, which message will be printed out in a higher level and which will not?

    Also find verbosity in logging.

    I think they are different due to the reason that logging verbosity level is in [0, 50] and unittest's is just a unit number. I just want to find out the difference between each verbosity level in unittests.

  • chao787
    chao787 almost 12 years
    I don't think verbosity has strong relationship with logging because unittest has its own level in [1,2,3]. but logging.INFO is equal to 20 or more.
  • 0xc0de
    0xc0de almost 12 years
    @RichardWong These are just some constant values for convenience, valued 0, 10, 20, 30, 40 and 50. You are welcome to read the code.. :)