Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #816 (closed defect: fixed)

Opened 13 years ago

Last modified 12 years ago

[PATCH] File logging is broken

Reported by: Matthew Good <tg@…> Owned by: anonymous
Priority: normal Milestone: 0.9a6
Component: TurboGears Version: 0.9a5
Severity: normal Keywords:


Changeset r1263 broke the file logging since it tries to open a StreamHandler with the filename instead of a file-like object. The following patch should fix it:

  • turbogears/startup.py

    197197            handler.setFormatter(fmt) 
    198198            setuplog.addHandler(handler) 
    200         logfile = turbogears.config.get("server.log_file", sys.stdout) 
    201         setuplog = logging.getLogger("turbogears.access") 
    202         setuplog.propagate = 0 
    203         fmt = logging.Formatter("%(message)s") 
    204         handler = logging.StreamHandler(logfile) 
    205         handler.setLevel(logging.INFO) 
    206         handler.setFormatter(fmt) 
    207         setuplog.addHandler(handler) 
     200        logfile = turbogears.config.get("server.log_file") 
     201        if logfile: 
     202            setuplog = logging.getLogger("turbogears.access") 
     203            setuplog.propagate = 0 
     204            fmt = logging.Formatter("%(message)s") 
     205            handler = logging.FileHandler(logfile) 
     206            handler.setLevel(logging.INFO) 
     207            handler.setFormatter(fmt) 
     208            setuplog.addHandler(handler) 
    209210    bonjoursetting = turbogears.config.get("tg.bonjour", None) 
    210211    if bonjoursetting or isdev: 

Change History

comment:1 Changed 13 years ago by michele

  • Summary changed from File logging is broken to [PATCH] File logging is broken

comment:2 Changed 13 years ago by godoy

Instead of modifying everything and loosing the output to sys.stdout, shouldn't something like

        logfile = turbogears.config.get(open("server.log_file"), sys.stdout)

be used? Of course, I'm not checking exceptions on this suggestion, but I believe it would be better to keep the possibility to have both...

(I haven't tried that, this is just "pseudocode")

comment:3 Changed 13 years ago by Matt Good <tg@…>

Logging to stdout is handled separately via the [branches/1.0/turbogears/startup.py?rev=1263#L187 server.log_to_screen] setting, so it was already redundant.

Of course you may want to double-check your pseudocode ... you may notice some ... unusual behavior ;)

comment:4 Changed 13 years ago by Matt Good <tg@…>

Doh, messed up that link above to the server.log_to_screen setting (I still need my caffeine).

comment:5 Changed 13 years ago by godoy

Hey, I'm the one who haven't slept and you're needing caffeine? :-)

As I said, I hadn't checked it, it was just to "give an idea" on a different approach.

If it is done in a separate place, then I don't see why duplicating it here.

comment:6 Changed 13 years ago by kevin

  • Milestone set to 0.9a6

comment:7 Changed 13 years ago by kevin

  • Status changed from new to closed
  • Resolution set to fixed

committed in [1381]

Note: See TracTickets for help on using tickets.