Seite 1 von 1

logging with-yaml config

Verfasst: Sonntag 18. Mai 2014, 15:49
von Tariiq
what i get...

Code: Alles auswählen

Traceback (most recent call last):
  File "/Users/Genius/Desktop/newpy/in.py", line 3, in <module>
    logging.config.dictConfig('login.yaml')
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/config.py", line 803, in dictConfig
    dictConfigClass(config).configure()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/config.py", line 380, in __init__
    self.config = ConvertingDict(config)
ValueError: dictionary update sequence element #0 has length 1; 2 is required
this is my code...

Code: Alles auswählen

import logging
import logging.config
logging.config.dictConfig('login.yaml')
logger=logging.getLogger('henry')
print("an insect maults by shedding off its wings")
logger.debug("debug message")
logger.info("info message")
logger.warn("warn message")
logger.error("error message")
logger.critical("critical message")

Code: Alles auswählen

version: 1
formatters:
  simple:
    format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
handlers:
  console:
    class: logging.StreamHandler
    level: DEBUG
    formatter: simple
    stream: ext://sys.stdout
loggers:
 henry:
    level: DEBUG
    handlers: [console]
    propagate: no
root:
  level: DEBUG
  handlers: [console]

Re: logging with-yaml config

Verfasst: Sonntag 18. Mai 2014, 17:37
von BlackJack
@Tariiq: `logging.config.dictConfig()` expects a dictionary as argument, not a string.