The Python library is very powerful and can basically find all the lib we need. The logging module is a log record library in Python. It draws on the idea of the LOG4J module in Java and can be conveniently used to record software execution logs. Recently, an automated testing tool is being developed, which requires the logging module. However, an exception is often thrown when the logging module's RotatingFileHandler is used. Print the following exception information: 1 lne 86, in _ init _ 2 rotatingHandler. dorolover () 3 File "/lib/python2.7/lib/logging/handlers. py ", line 131, in dorolover4 OS. rename (self. baseFilename, dfn) 5 OSError: [Errno 13] Permission denied after viewing log file permissions, it is found that all file attributes are question marks, and after executing the copy or move command on it, the file attributes are restored to normal. It is said on the Internet that the problem is caused by calling Getlogger in multiple places. No other redundant modules have obtained the same Logger. (Later, I found that multiple threads directly record logs to log files through logging, and multiple threads simultaneously operate on a log file may cause this error.) Then I found a solution after google wrote an early discussion post: 1. Find handlers in the logging library. in The py file, locate the dorolover method of the base class of RotatingFileHandler, and modify the following code: 1 try: 2 OS. rename (self. baseFilename, dfn) 3 # import shutil first and replace it with 4 try: 5 shutil. move (self. baseFilename, dfn) 2. log record operation exceptions may occur. If the following exception occurs (the exception information comes from the network): 1 Traceback (most recent call last): 2 File "C: \ Python24 \ lib \ logging \ handlers. py ", line 72, in emit3 self. dorolover () 4 File "C: \ Python24 \ lib \ logging \ handlers. py ", line 141, in dorolover5 self. handleError (record) 6 NameError: global name 'record 'is not defined. Please try the following modifications: 1 if self. shouldrolover (record): 2 self. dorolover () 3 # modify to: 4 if self. shouldrolover (record): 5 self. dorolover (record) 3. When you press Ctrl + C to exit the program, the following exception may be printed: Copy code 1 Error in atexit. _ run_exitfuncs: 2 Traceback (most recent call last): 3 File "C: \ Python24 \ lib \ atexit. py ", line 24, in _ run_exitfuncs 4 func (* targs, ** kargs) 5 File" C: \ Python24 \ lib \ logging \__ init __. py ", line 1333, in shutdown 6 h. close () 7 File "C: \ Python24 \ lib \ logging \__ init __. py ", line 772, in close 8 StreamHandler. close (self) 9 File "C: \ Python24 \ lib \ logging \__ init __. py ", line 674, in close10 del _ handlers [self] 11 KeyError: <logging. handlers. rotatingFileHandler instance at 0x01E098A0> 12 Error in sys. exitfunc: 13 Traceback (most recent call last): 14 File "C: \ Python24 \ lib \ atexit. py ", line 24, in _ run_exitfuncs15 func (* targs, ** kargs) 16 File" C: \ Python24 \ lib \ logging \__ init __. py ", line 1333, in shutdown17 h. close () 18 File "C: \ Python24 \ lib \ logging \__ init __. py ", line 772, in close19 StreamHandler. close (self) 20 File "C: \ Python24 \ lib \ logging \__ init __. py ", line 674, in close21 del _ handlers [self] 22 KeyError: <logging. handlers. rotatingFileHandler instance at 0x01E098A0> to copy the code, try the following: copy the Code 1 _ acquireLock () 2 try: # unlikely to raise an exception, but you never know... 3 del _ handlers [self] 4 _ handlerList. remove (self) 5 finally: 6 _ releaseLock () 7 8 # change to: 9 _ acquireLock () 10 try: # unlikely to raise an exception, but you never know... 11 # del _ handlers [self] 12 if (_ handlers. has_key (self): del _ handlers [self] 13 # if (self in _ handlerList): _ handlerList. remove (self) 14 _ handlerList. remove (self) 15 finally: 16 _ releaseLock ()