Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to log arbitrary output #8

Open
pfmoore opened this issue Aug 13, 2019 · 0 comments
Open

How to log arbitrary output #8

pfmoore opened this issue Aug 13, 2019 · 0 comments

Comments

@pfmoore
Copy link

pfmoore commented Aug 13, 2019

Hi, I just found this project, and I love the approach it takes to logging - in particular the idea of building instrumentation in from the design stage. But there's one thing I can't see how to handle, which is to integrate "unstructured" output into the logs.

To give an example, in pip[1] we build a project by calling the build system in a subprocess. So in a lithoxyl style of code, we'd do something like (highly simplified, obviously):

def build_project(proj):
    with log.critical("Extracting sources"):
        build_dir = get_temp_location()
        proj.extract_source_to(build_dir)
    with log.critical("Building project"):
        proc = subprocess.run([sys.executable, 'setup.py', 'bdist_wheel'], capture_output=True)
        # subprocess output is in proc.output

However, we capture the output of the subprocess, and we want to display it only when there's an error. Ideally, output would be something like:

... Extracting sources succeeded
... Building project failed
subprocess output goes here
with whatever formatting the build process used
    preserved
    intact
for the user to diagnose the issue

Note that I don't really want things like timestamps on the subprocess output, as that makes no sense (we didn't log the output in "real time" so the timestamps would be misleading rather than helpful).

Alternatively, there are cases where I'd log the subprocess output in real time. In those cases, I'd be OK with timestamp-style data, but conversely I'd want the display of the data to be tied to the success or failure of the enclosing action, so the output is only displayed if the build action doesn't succeed (which is obviously complicated by the fact that the output has been generated before we know whether we're going to want to display it).

Is there a way to do this?

[1] BTW, there's no plan that I know of to switch to using lithoxyl with pip, but it's a good example of the type of problem I face frequently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant