-
Hi all, Quick question, is there a nice way to use I'm veering towards setting up a console, printing to it with Cheers, Phil |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
I guess I could create a console object, run inspect using that and capture the output to a string, and then print that string to the log file (x-ref #2374 (comment) ) A bit roundabout, but should work.. Any nicer ways? 🤔 |
Beta Was this translation helpful? Give feedback.
-
Saya tidak paham tolong bantuannya
Pada tanggal Jum, 19 Agu 2022 15.58, Phil Ewels ***@***.***>
menulis:
… Thanks for this - having another go now I'm back after holidays.
If you don't mind that the inspect data only working with the RichHandler
Ideally I want this for verbose logging which in this tool can get written
to a file, so if possible I'd like it to play nicely with
logging.FileHandler (though refactoring this could be another option)
I had a go with the capture() output approach and it half works, but I
get all of the ANSI codes. Even if I tell the console not to use colour, I
still get them in the inspect() output:
inspect_console = Console(no_color=True)with inspect_console.capture() as capture:
inspect(
subprocess.run(
self.before_command,
cwd=self.working_dir,
shell=True,
env=command_env,
capture_output=True,
),
title="'before_command' results",
docs=False,
console=inspect_console,
)log.debug(capture.get())
DEBUG ╭────────────────────────────────────────────────────────── 'before_command' results ──────────────────────────────────────────────────────────╮
│ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │
│ │ [1mCompletedProcess[0m[1m([0margs='echo "This is a very simple example" > before_after_command_example.txt\n', returncode=[1m0[0m, stdout=b'',
stderr=b''[1m)[0m │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ │
│ │
│ [3margs[0m = 'echo "This is a very simple example" > before_after_command_example.txt\n' │
│ [3mreturncode[0m = [1m0[0m
│
│ [3mstderr[0m = b'' │
│ [3mstdout[0m = b'' │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Am I missing something? Is there no way to disable colour from inspect()?
🤔
—
Reply to this email directly, view it on GitHub
<#2378 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AZMOCWZKXMIPVGVHEUMHQQLVZ45BZANCNFSM52VQRNGA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
I guess I could create a console object, run inspect using that and capture the output to a string, and then print that string to the log file (x-ref #2374 (comment) )
A bit roundabout, but should work.. Any nicer ways? 🤔