Skip to content

feat: oxidize open_stream#416

Draft
bepri wants to merge 18 commits intofeature/oxidationfrom
work/rust-stream-handlers/CRAFT-4964
Draft

feat: oxidize open_stream#416
bepri wants to merge 18 commits intofeature/oxidationfrom
work/rust-stream-handlers/CRAFT-4964

Conversation

@bepri
Copy link
Member

@bepri bepri commented Feb 3, 2026

  • Have you followed the guidelines for contributing?
  • Have you signed the CLA?
  • Have you successfully run make lint && make test?

This is based on (and thus requires) #411. The diff will be pretty noisy until it is merged.

I recommend not reviewing the code directly until I've had an opportunity to clean up the commit history once #411 lands, but this can be tested using the scripts below in the meantime.

This PR adds the open_stream method back to the emitter. This required refactoring the Printer class to not solely exist as a field on an Emitter instance, as the stream handler object needed access too. Now, the Printer is a global, static variable that gets initialized upon the first print. For similar reasons, the logging mechanism has been moved into the printer and must be explicitly initialized via the new Emitter.init_logger().

Here is some example code to test the changes:

# testing.py
import subprocess

from craft_cli import EmitterMode
from craft_cli._rs.emitter import Emitter

e = Emitter("blah.log", EmitterMode.TRACE, "example.com", "hello from rust!")
e.init_logger()

with e.open_stream() as stream:
    subprocess.run(["bash", "testing.sh"], stdout=stream, stderr=stream)
# testing.sh
for i in {1..6}; do
  echo $i
  sleep 1
done

Known bugs: It seems that trace-level events (and perhaps others?) duplicate the timestamp in logs (tracked in CRAFT 4999)

CRAFT-4964.

@bepri bepri self-assigned this Feb 3, 2026
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

Successfully merging this pull request may close these issues.

1 participant