Reputation: 4492
So I'm using the python logging module for the first time, and I'm receiving an error I cannot find any information on.
At the start of my file, I have the following:
logging.basicConfig(level=logging.INFO, filename='logs', filemode='a+', format='[%(asctime)-15s] %(levelname)-8s %(message)s')
The line that's throwing the error:
logging.info(f'Downloading: {file_name}\t{local_file_path}\t{os.path.abspath(local_file_path)}')
--- Logging error ---
Traceback (most recent call last):
File "C:\Python36\lib\logging\__init__.py", line 996, in emit
self.flush()
File "C:\Python36\lib\logging\__init__.py", line 976, in flush
self.stream.flush()
OSError: [Errno 22] Invalid argument
Call stack:
File "Main.py", line 81, in <module>
main()
File "C:\Python36\lib\site-packages\click\core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "C:\Python36\lib\site-packages\click\core.py", line 697, in main
rv = self.invoke(ctx)
File "C:\Python36\lib\site-packages\click\core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:\Python36\lib\site-packages\click\core.py", line 535, in invoke
return callback(*args, **kwargs)
File "Main.py", line 32, in main
work_tv(ftp, ext)
File "Main.py", line 76, in work_tv
logging.info(f'Downloading: {file_name}\t{local_file_path}\t{os.path.abspath(local_file_path)}')
Message: 'Downloading: Preacher S02E13\t./Preacher/Season 2/Preacher S02E13.mkv\tZ:\\TV\\Preacher\\Season 2\\Preacher S02E13.mkv'
Arguments: ()
I don't understand this error. The first 8 times it ran successfully without a problem. However the last two, it has thrown this identical error. Can someone please explain it to me.
Upvotes: 12
Views: 14447
Reputation: 99355
The fact that it failed on a self.stream.flush()
implies that the file being written to (presumably logs
) has already been closed or is not writable for some other reason.
Update: If you need to deal with this, subclass the handler and override the emit()
method to do what you need to recover from the error.
Upvotes: 3