Save output of chia plots check from console to file

Viewed 1173

I would like to write the logging output from CLI command chia plots check to a file.

The usual way via chia plots check > file.log und chia plots check | tee file.log was unfortunately unsuccessful.

Editing the python file does not work either, because chia is installed via .deb.

Thanks for your help.

2 Answers

Solved I had the same problem and I found the answer.

try this worked for me

chia plots check &> /home/chia/plot-check.log 

Note: you will have have to tail the file if you want to see real time output.

I solved this problem using a python script.

from contextlib import redirect_stdout
import subprocess, re, os
with open('text.txt', 'w') as f:
    with redirect_stdout(f):      
        res = subprocess.check_output('chia plots check', shell=True, stderr=subprocess.STDOUT)
        ansi_escape = re.compile(b'(?:\x1B[@-Z\\-_]|[\x80-\x9A\x9C-\x9F]|(?:\x1B\[|\x9B)[0-?]*[ -/]*[@-~])')
        res = ansi_escape.sub(b'', res)
        print(res.decode('utf-8'))

I have redirected the output stream to a file with redirect_stdout (all prints are directed to a file). Used subprocess library to run chia. Since the output contains colors (ANSI) I used regular expressions to replace the output bytes.

Related