Need help in configuration for TimedRotatingFileHandler

L

Lokesh

Hi,

Need help in configure the TimedRotatingFileHandler from configuration
file

I have tried with the below code and ended up with the error, code is
pasted below
Error - IOError: [Errno 2] No such file or directory: 'G:\\lok_sib\
\logs\rotate_test'
[loggers]
keys=root,simpleExample

[handlers]
keys=consoleHandler,timedRotatingFileHandler

[formatters]
keys=simpleFormatter

[logger_root]
level=DEBUG
handlers=consoleHandler

[logger_simpleExample]
level=DEBUG
handlers=timedRotatingFileHandler
qualname=simpleExample
propagate=0

[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=simpleFormatter
args=(sys.stdout,)

[handler_timedRotatingFileHandler]
class=handlers.TimedRotatingFileHandler
level=DEBUG
formatter=simpleFormatter
args=("G:\lok_sib\logs\rotate_test", 'midnight', 1)

[formatter_simpleFormatter]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
datefmt='%Y-%m-%d %H:%M:%S'


Thanks or your time
Regards,
Lokesh
 
K

Kushal Kumaran

Hi,

Need help in configure the TimedRotatingFileHandler from configuration
file

I have tried with the below code and ended up with the error, code is
pasted below
Error - IOError: [Errno 2] No such file or directory: 'G:\\lok_sib\
\logs\rotate_test'

Does the directory G:\\lok_sib\\logs exist?
 
J

Jan Kaliszewski

09-08-2009 Lokesh said:
I have tried with the below code and ended up with the error, code is
pasted below
Error - IOError: [Errno 2] No such file or directory: 'G:\\lok_sib\
\logs\rotate_test'

Note that: '\r' is listed (interpreted by Python as 'carriage return'
special character) and not '\\r' (which would mean '\' char + 'r' char).

Regards,
*j
 
D

Dave Angel

Lokesh said:
Hi,

Need help in configure the TimedRotatingFileHandler from configuration
file

I have tried with the below code and ended up with the error, code is
pasted below
Error - IOError: [Errno 2] No such file or directory: 'G:\\lok_sib\
\logs\rotate_test'
[loggers]
keys=root,simpleExample

[handlers]
keys=consoleHandler,timedRotatingFileHandler

[formatters]
keys=simpleFormatter

[logger_root]
level=DEBUG
handlers=consoleHandler

[logger_simpleExample]
level=DEBUG
handlers=timedRotatingFileHandler
qualname=simpleExample
propagate=0

[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=simpleFormatter
args=(sys.stdout,)

[handler_timedRotatingFileHandler]
class=handlers.TimedRotatingFileHandler
level=DEBUG
formatter=simpleFormatter
args=("G:\lok_sib\logs\rotate_test", 'midnight', 1)

[formatter_simpleFormatter]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
datefmt='%Y-%m-%d %H:%M:%S'


Thanks or your time
Regards,
Lokesh
I don't see code there, I see lots of config data, presumably in an .ini
file. So I don't know how you're reading it in, and converting it to
Python variables, but I know where I'd look, based on your error message.

The following line:

args=("G:\lok_sib\logs\rotate_test", 'midnight', 1)

seems to contain a Python string. But there are unescaped backslashes
within it. You can get away with it in two cases, because \l isn't a
valid escape sequence. But in the case of \r, it looks like a newline
character.

Anyway, all three of those backslashes probably need to be doubled.

args=("G:\\lok_sib\\logs\\rotate_test", 'midnight', 1)

Two other cures that may work, depending on context: change the backslashes to forward slashes, or use a raw string.

But as I said earlier, you don't show in any way what code is interpreting this line, so it's all just guesswork.

DaveA
 
D

Dave Angel

Lokesh said:
<snip>
Code:
mlogger = logging.getLogger("simpleExample")
def a_view(request):
mlogger.debug("a_view called")
if request.method== "POST" :
mlogger.debug("post function")
else:
mlogger.debug("serve function")

Execution:
step1: Executed the code and got the log file with the information
step2: Modified the system time from current day to next day
step3: End up with the error and the error is pasted below

Traceback (most recent call last):
File "c:\Python25\lib\logging\handlers.py", line 74, in emit
self.doRollover()
File "c:\Python25\lib\logging\handlers.py", line 274, in doRollover
os.rename(self.baseFilename, dfn)
WindowsError: [Error 32] The process cannot access the file because it is
being used by another process

Python version - 2.5.4

I guess my output should be like this for the next day
-a new log file rotate_test.<date format> should generate in the respective
location

Please correct me if I am wrong.


Thanks for your time.

Regards,
Lokesh
Generally speaking, this error on os.rename() will occur if you haven't
properly closed the file first, and if I recall correctly, Unix would
have permitted a rename on an open file. You're on Windows. However, I
don't know how that works with the logging package. If the program has
terminated, and you run it a second time on the following day (or after
changing the system time), then I'd expect no trouble. But I'm guessing
your program is still running, and you just want to change from logging
to yesterday's file to logging to today's file.

If I had to guess, I'd say that you have two instances of the logger
running, and the second one is still holding the handle open. But
that's just a wild guess.

Could someone else who is familiar with logging, and with
TimedRotatingFileHandler in particular, jump in here? Preferably a
Windows person?

DaveA
 
V

Vinay Sajip

Lokesh said:
Traceback (most recent call last):
  File "c:\Python25\lib\logging\handlers.py", line 74, in emit
    self.doRollover()
  File "c:\Python25\lib\logging\handlers.py", line 274, in doRollover
    os.rename(self.baseFilename, dfn)
WindowsError: [Error 32] The process cannot access the file because it is
being used by another process

Generally speaking, this error on os.rename() will occur if you haven't
properly closed the file first, and if I recall correctly, Unix would
have permitted a rename on an open file.  You're on Windows.  However, I
don't know how that works with theloggingpackage.  If the program has
terminated, and you run it a second time on the following day (or after
changing the system time), then I'd expect no trouble.  But I'm guessing
your program is still running, and you just want to change fromlogging
to yesterday's file tologgingto today's file.

If I had to guess, I'd say that you have two instances of the logger
running, and the second one is still holding the handle open.  But
that's just a wild guess.

It's certainly possible that there are two instances of the handler,
which would cause this problem. Other things which might cause this
problem are the file handle inherited by a child process, an anti-
virus scanner having the file open for scanning (anti-virus scanners
often scan files which have just been written, like log files) and
indexing software such as Google Desktop or Windows' own indexing
service.

I would advise using sysinternals tools such as FileMon and Handle to
see what's holding the file open.

Regards,


Vinay Sajip
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top