Ask Your Question
1

cinder python module logger collides with my logger

asked 2016-05-25 04:49:19 -0500

jlausuch gravatar image

updated 2016-05-25 04:56:54 -0500

I want to have log handling in a script I'm writing, but when I import cinderclient python module I get duplicated log outputs. This is the script:

import logging

#from cinderclient.v2 import client as cinderclient

logger = logging.getLogger("test")
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - '
                              '%(levelname)s - %(message)s')
ch = logging.StreamHandler()
ch.setFormatter(formatter)
ch.setLevel(logging.DEBUG)
logger.addHandler(ch)
logger.debug("this is a test...")

This is the output when I execute this script without importing cinder module:

$python test.py 
2016-05-25 09:43:26,753 - test - DEBUG - this is a test...

But when I uncomment the cinder import line:

$python test.py 
2016-05-25 09:44:47,375 - test - DEBUG - this is a test...
DEBUG:test:this is a test...

I get a second output without my predefined formatting.

My cinder client is python-cinderclient (1.7.0). And this doesn't happen with nova/neutron (from neutronclient.v2_0 import client as neutronclient or from novaclient import client as novaclient).

Does anyone know why?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-06-02 03:14:36 -0500

jlausuch gravatar image

updated 2016-06-02 03:14:52 -0500

The solution is :

logger = logging.getLogger("test")
self.logger.propagate = 0
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

Asked: 2016-05-25 04:49:19 -0500

Seen: 74 times

Last updated: Jun 02 '16