Python logging & custom message levels…

Having played with this for a little too long…  I found a simple fix…

My problem was when defining a new custom logging level –

    logger = logging.getLogger(myProj)
    logger.setLevel(logging.INFO)   # default

and then checking that user edited config options are valid, with –

            x = (sys.argv[1]).upper()
            n = getattr(logging,x,None)
            if not isinstance(n, int):
                logger.error('Invalid log level argument: %s'%x)
                dbugLvl = x
      "Logging level : %s"%dbugLvl)

This did not recognise my new “ALERT” level.

The simple fix is to add to the initial code –


I hope this helps someone else avoid hours of fun…


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s