#๐Ÿ”’ Handling new log files when created, or date cycling

7 messages ยท Page 1 of 1 (latest)

fair hemlock
#

Hi, I'm working on a project that monitors log files for keywords (long story short).

The one problem I'm facing right now is that the program creating and writing to the log files names them by date, creating one daily. Right now I have my Python script grabbing a file to read by the date format:

start_date = datetime.today().strftime('%Y%m%d')
main_run(start_date)```

but once it is the next day, the file is no longer being written to.

Furthermore I am using `sh` module to follow the file, and the script is held by a loop:
```py
# In "main_run" function:
 tail_proc = tail("-f", "-n 0", path_1, _iter=False, _out=tail_callback, _bg=True)
tail_proc.wait()```
(I'm probably going to change the structure of the main starting function.)

How can I either break the loop by the next day, or when there is new file created, and start following the new file?
high bronzeBOT
#

@fair hemlock

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

fair hemlock
#

what practice would be best? Possibly file creation detection

fair hemlock
#

Bump as I'm going away for a bit. My goal is to have this script continue to run - no relaunching every day if not needed

fair hemlock
#

back

high bronzeBOT
#

@fair hemlock

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.