Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Ticket #256 (defect)

Opened 3 years ago

Last modified 2 years ago

Log file needs a file lock

Status: closed (fixed)

Reported by: fumanchu Assigned to: rdelon
Priority: normal Milestone: 3.0
Component: CherryPy code Keywords: log threading
Cc:

Usually, writing to the log file is fast enough, but an explicit file lock (or *at least* a thread lock) would be wise.

Change History

08/28/05 15:03:48: Modified by lawouach

I wonder what would be the safest and quickest: locking the file or locking the calling thread

09/14/05 23:18:58: Modified by mikerobi

Locking the log file would probably prevent two threads from spewing garbage into the log, but it would not provide true safety. If a single thread writes multiple entires to the log, the entries could still be seperated by entries written from other threads.

I can see two solutions to this problem. Each log entry could be prefixed with a unique identifier for the thread that created it. The second solution would be to buffer all of the cache data an flush it to disk when each thread is terminated.

The first solution would be much simpler but the log would be less readable. The second solution is much more complicated and has the added risk of log data getting lost if there is some kind of server failure. (Of course you could combine both of these solutions.)

I think both of these solutions too extreme for a theoreticall problem. We should leave things alone until someone experiences a real problem.

11/03/05 17:40:56: Modified by james_007_bond@users.sourceforge.net

Why not using the logging module? This will solve the issue of logging to files, rotating files, syslog and more. logging uses locking already. I've changed the log methods in my cherrypy app to use this battery included module, and it works just fine. It seems that reuse in this case would be a good idea.

04/01/06 04:57:45: Modified by lawouach

  • milestone set to 3.0.

It would be nice to decide whether or not we move to the logging module of the stdlib.

06/22/06 18:43:43: Modified by fumanchu

  • status changed from new to closed.
  • resolution set to fixed.

Fixed in [1155]. CherryPy now uses the logging module from the Python standard library, which does thread locking. The only significant change to the CherryPy API is that the severity levels now match those of the logging module; the access log defaults to logging.INFO and the error log defaults to logging.DEBUG. The other significant change is that different applications or paths cannot now set different logs simply by changing "log_file" or "log_access_file" in config.

06/25/06 01:03:24: Modified by fumanchu

Better fix in [1156]. Apps now have their own access and error loggers (whose config entries must be at "/"), and the global access logger has been removed (although you can make one manually if you like).

07/09/06 23:58:43: Modified by fumanchu

Note that the above changes have slowed CP between 5 and 6 percent on my dev machine. There are a lot of function calls underlying Logger.log()...

Hosted by WebFaction

Log in as guest/cpguest to create tickets