use pythonic way to read log
See original GitHub issueI was trying to run this with WSL to see if that would work. It seems like there is an issue where you can’t follow a file in WSL without the ---disable-inotify flag on tail. I tested this and added that option in the log consumer and it does work after that. I noticed there have been issues with Windows as well during log rotations. I’m not sure if switching over to a pythonic way of reading the debug file will solve this, but it seems like it would be better since you don’t need differentiate between OSes either.
Not sure if remote would work with this either, so it would require a bit of testing.
Maybe something like: https://stackoverflow.com/questions/12523044/how-can-i-tail-a-log-file-in-python/53121178#53121178
Edit:
Initially something like this appears to work with little resources:
def _consume_loop(self):
expanded_user_log_path = self._log_path.expanduser()
logging.info(f"Consuming log file from {expanded_user_log_path}")
try:
fp = open(expanded_user_log_path, "r")
st_results = os.stat(expanded_user_log_path)
st_size = st_results[6]
fp.seek(st_size)
while self._is_running:
where = fp.tell()
line = fp.readline()
if not line:
time.sleep(1)
fp.seek(where)
elif fp.tell() > os.path.getsize(expanded_user_log_path):
logging.info("Log rotated, opening latest log file")
fp.close()
fp = open(expanded_user_log_path, "r")
fp.seek(0,2)
else:
self._notify_subscribers(line)
except Exception as e:
fp.close()
logging.critical(f"Error consuming log file: {e}")
I can run it for a bit and see what happens during rotations as well. This seems to work the same for windows.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (3 by maintainers)

Top Related StackOverflow Question
Chia uses this:
https://github.com/Chia-Network/chia-blockchain/blob/1c808b6c2910ed32fdbfdfc576ba1bc5a5adeac9/setup.py#L15
You can see how they use it here:
https://github.com/Chia-Network/chia-blockchain/blob/59de4ffe9f98de62d281695d1f519d65ef2e2ece/chia/util/chia_logging.py#L6
Definitely worth a try and would be nice if it worked cross-platform. My work on the log rotation issue is available here: https://github.com/martomi/chiadog/tree/windows-rotation
It’s tested on Linux local, Linux remote and Windows local, but I can’t test Windows remote without setting up a dummy node