Modify

Ticket #283 (new defect)

Opened 21 months ago

PyYaml does not create logging handler classes correctly in Python 2.7

Reported by: jordi.puigsegur@… Owned by: xi
Priority: normal Component: pyyaml
Severity: normal Keywords: python 2.7 logging handlers
Cc:

Description

logging.FileHandler? and logging.RotatingFileHandler? (haven't tried other handlers) do not get correctly initialized in python 2.7 when loaded using PyYaml?.

This example reproduces the problem:

import logging
import logging.handlers
import yaml

logger = logging.getLogger() # root logger

# Option 1 - OK
##handler = logging.handlers.RotatingFileHandler(filename = "test.log", maxBytes = 262144, backupCount = 3)

# Option 2 - RotatingFileHandler fails when created through yaml
handler = yaml.load("""
!!python/object/new:logging.handlers.RotatingFileHandler
    kwds:
        filename: test.log
        maxBytes: 262144
        backupCount: 3
""")

# Option 3 - FileHandler also fails when created through yaml
##handler = yaml.load("""
##!!python/object/new:logging.FileHandler
##    kwds:
##        filename: test.log
##""")

logger.addHandler(handler)

logger.warning("test handler")

The example above works in python 2.6 and 2.5, but fails in python 2.7. In both cases I am using the latest version of PyYaml?: 3.10

I've opened a ticket in python ( http://bugs.python.org/issue15616) and it seems that Logging changed from old-style classes in 2.6 to new-style classes in 2.7 and that may be the reason.

Attachments

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as new
as The resolution will be set. Next status will be 'closed'
to The owner will be changed from xi. Next status will be 'new'
The owner will be changed from xi to anonymous. Next status will be 'assigned'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.