RotatingFileHandler

2004-12-02 Thread Kamus of Kadizhar
I'm having a problem with logging.  I have an older app that used the
RotatingFileHandler before it became part of the main distribution (I
guess in 2.3).

It worked fine then.  Now I get:

[EMAIL PROTECTED] bin]# ./mplayer.py file://test.avi
//test.avi
Traceback (most recent call last):
  File "./mplayer.py", line 40, in ?
logFile.emit(movieName)
  File 
"/usr/src/build/394694-i386/install/usr/lib/python2.3/logging/handlers.py", 
line 102, in emit
  File 
"/usr/src/build/394694-i386/install/usr/lib/python2.3/logging/__init__.py", 
line 567, in format
  File 
"/usr/src/build/394694-i386/install/usr/lib/python2.3/logging/__init__.py", 
line 362, in format
AttributeError: 'str' object has no attribute 'getMessage'

The offending snippet of code is:

   logFile = 
logging.handlers.RotatingFileHandler('/var/log/user/movies2.log','a',2000,4)
   logFile.emit(movieName)

I don't see anything wrong with this, but I'm a relative python bonehead.

movieName contains the string 'test.avi' at the time of the crash.

What's going on?  Anything I need to look at?

--Kamus

-- 
   o   |
 o__  >[]  | A roadie who doesn't ride a mountain bike has no soul.
 ,>/'_/\   | But then a mountain biker who doesn't ride a road bike has no 
legs...
(_)\(_)   \ \  | -Doug Taylor, alt.mountain-bike

-- 
http://mail.python.org/mailman/listinfo/python-list


File locking and logging

2004-12-02 Thread Kamus of Kadizhar
Thanks to Robert Brewer, I got enough insight into logging to make it work

Now I have another issue:  file locking.  Sorry if this is a very basic
question, but I can't find a handy reference anywhere that mentions this.

When a logger opens a log file for append, is it automatically locked so
other processes cannot write to it?  And what happens if two or more
processes attempt to log an event at the same time?

Here's my situation.  I have two or three workstations that will log an
event (the playing of a movie).  The log file is NFS mounted and all
workstations will use the same log file.  How is file locking implemented?
Or is it?

I've read through the various logger doc pages and this is never mentioned.

The logging code that works (for me at least) is this:

   logging.basicConfig()
   logFile = 
logging.handlers.RotatingFileHandler("/var/log/user/movies.log",'a',2000,4)
   logFile.setLevel(logging.INFO)
   formatter = logging.Formatter(hostname + ' %(asctime)s 
%(message)s',datefmt='%Y-%m-%d.%H:%M')
   logFile.setFormatter(formatter)
   logging.getLogger('').addHandler(logFile)
   logging.warning(movieName)
   logFile.flush()
   logFile.close()

Any thoughts are appreciated

Thanks,

--Kamus

-- 
   o   |
 o__  >[]  | A roadie who doesn't ride a mountain bike has no soul.
 ,>/'_/\   | But then a mountain biker who doesn't ride a road bike has no 
legs...
(_)\(_)   \ \  | -Doug Taylor, alt.mountain-bike

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RotatingFileHandler

2004-12-03 Thread Kamus of Kadizhar
On Fri, 03 Dec 2004 09:40:07 +, Vinay Sajip wrote:

> Of course, you should not normally be calling emit() from user code. The 
>   correct approach is to log events to loggers, and not emit them to 
> handlers directly.

Thanks, I finally got that figured out.  Lots changed between the time I
originally wrote the code a couple of years ago and today

--Kamus

-- 
   o   |
 o__  >[]  | A roadie who doesn't ride a mountain bike has no soul.
 ,>/'_/\   | But then a mountain biker who doesn't ride a road bike has no 
legs...
(_)\(_)   \ \  | -Doug Taylor, alt.mountain-bike

-- 
http://mail.python.org/mailman/listinfo/python-list