# Filebeat prevents python rotating log from rotating files in windows os

**URL:** <https://discuss.elastic.co/t/filebeat-prevents-python-rotating-log-from-rotating-files-in-windows-os/96450>\
**Category:** Beats\
**Created:** [August 9, 2017, 2:09pm UTC](https://discuss.elastic.co/t/filebeat-prevents-python-rotating-log-from-rotating-files-in-windows-os/96450 "2017-08-09T14:09:34Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dima\_Shechtman](https://avatars.discourse-cdn.com/v4/letter/d/c67d28/32.png) [@Dima\_Shechtman](https://discuss.elastic.co/u/Dima_Shechtman)\
**Post date:** [August 9, 2017, 2:09pm UTC](https://discuss.elastic.co/t/filebeat-prevents-python-rotating-log-from-rotating-files-in-windows-os/96450/1 "2017-08-09T14:09:34Z")

</div>

Environment:  
win 10  
python 2.7  
filebeat 5.1.1

My application writes logs with Rotating log handler. When I start Filebeat I start getting the following exceptions from logging lib.

Traceback (most recent call last):  
File "C:\Anaconda2\Lib\logging\[handlers.py](http://handlers.py)", line 77, in emit  
self.doRollover()  
File "C:\Anaconda2\Lib\logging\[handlers.py](http://handlers.py)", line 142, in doRollover  
os.rename(self.baseFilename, dfn)

How can I resolve it?

---

<div class="post-metadata">

**Author:** ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)\
**Post date:** [August 9, 2017, 10:26pm UTC](https://discuss.elastic.co/t/filebeat-prevents-python-rotating-log-from-rotating-files-in-windows-os/96450/2 "2017-08-09T22:26:39Z")

</div>

What's the exception? Is there an error message?

---

<div class="post-metadata">

**Author:** ![Dima\_Shechtman](https://avatars.discourse-cdn.com/v4/letter/d/c67d28/32.png) [@Dima\_Shechtman](https://discuss.elastic.co/u/Dima_Shechtman)\
**Post date:** [August 10, 2017, 5:52am UTC](https://discuss.elastic.co/t/filebeat-prevents-python-rotating-log-from-rotating-files-in-windows-os/96450/3 "2017-08-10T05:52:20Z")

</div>

sorry bad copy paste,

the error is:

WindowsError: [Error 183] Cannot create a file when that file already exists

---

<div class="post-metadata">

**Author:** ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)\
**Post date:** [August 10, 2017, 1:06pm UTC](https://discuss.elastic.co/t/filebeat-prevents-python-rotating-log-from-rotating-files-in-windows-os/96450/4 "2017-08-10T13:06:36Z")

</div>

Try [close\_removed](https://www.elastic.co/guide/en/beats/filebeat/current/configuration-filebeat-options.html#close-removed).

---

<div class="post-metadata">

**Author:** ![Dima\_Shechtman](https://avatars.discourse-cdn.com/v4/letter/d/c67d28/32.png) [@Dima\_Shechtman](https://discuss.elastic.co/u/Dima_Shechtman)\
**Post date:** [August 10, 2017, 2:07pm UTC](https://discuss.elastic.co/t/filebeat-prevents-python-rotating-log-from-rotating-files-in-windows-os/96450/5 "2017-08-10T14:07:56Z")

</div>

close\_removed and close\_renamed are enabled

my understanding from debugging the logger is:

the problem is when Python logger tries to rotate the file, he removes the old one and on that command I get exception, because Flebeat still holds the file open.

---

<div class="post-metadata">

**Author:** ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)\
**Post date:** [August 10, 2017, 8:52pm UTC](https://discuss.elastic.co/t/filebeat-prevents-python-rotating-log-from-rotating-files-in-windows-os/96450/6 "2017-08-10T20:52:50Z")

</div>

Oh, so the time between removing the old file and renaming is very short? So I guess it's not enough time for Filebeat to close the file. Maybe if you try using `close_inactive` the old file will closed by Filebeat before it's time for rotation.

---

<div class="post-metadata">

**Author:** ![Dima\_Shechtman](https://avatars.discourse-cdn.com/v4/letter/d/c67d28/32.png) [@Dima\_Shechtman](https://discuss.elastic.co/u/Dima_Shechtman)\
**Post date:** [August 10, 2017, 9:52pm UTC](https://discuss.elastic.co/t/filebeat-prevents-python-rotating-log-from-rotating-files-in-windows-os/96450/7 "2017-08-10T21:52:49Z")

</div>

posting my config:  
it didn't work.  
as you can see i aslo tried to add workers and pipelines

filebeat.prospectors:

- input\_type: log

close\_renamed: true  
close\_removed: true  
close\_inactive: 30s

name:  
steve\_01  
#----------------------------- Logstash output --------------------------------  
output.logstash:

# The Logstash hosts

hosts: ["host:port"]  
worker: 2  
pipelining: 2

---

<div class="post-metadata">

**Author:** ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)\
**Post date:** [August 10, 2017, 10:33pm UTC](https://discuss.elastic.co/t/filebeat-prevents-python-rotating-log-from-rotating-files-in-windows-os/96450/8 "2017-08-10T22:33:16Z")

</div>

The indentation is wrong. None of the `close_x` settings will be applied as written. These options are members of the prospector config and need to be indented at the same level as `paths` and `input_type`. Each prospector can use different settings therefore these are not global settings.

```auto
filebeat.prospectors:
- input_type: log
  paths:
  - my path
  close_inactive: 30s

```

---

<div class="post-metadata">

**Author:** ![Dima\_Shechtman](https://avatars.discourse-cdn.com/v4/letter/d/c67d28/32.png) [@Dima\_Shechtman](https://discuss.elastic.co/u/Dima_Shechtman)\
**Post date:** [August 13, 2017, 6:44am UTC](https://discuss.elastic.co/t/filebeat-prevents-python-rotating-log-from-rotating-files-in-windows-os/96450/9 "2017-08-13T06:44:06Z")

</div>

thanks for the help didn't see that.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 30, 2017, 2:09pm UTC](https://discuss.elastic.co/t/filebeat-prevents-python-rotating-log-from-rotating-files-in-windows-os/96450/10 "2017-08-30T14:09:37Z")

</div>

This topic was automatically closed after 21 days. New replies are no longer allowed.
