Skip to content

add logging

Chad Hanna requested to merge logging into main

This provides a minimal logging harness.

Taking an example from the docs and putting into a script called test.py

from sgn import Pipeline, DequeSink, DequeSource, CallableTransform

# Define a function to use in the pipeline
def add_ten(frame):
    return None if frame.data is None else frame.data + 10

# Create source element
src = DequeSource(
    name="src1",
    source_pad_names=["H1"],
    iters={"src1:src:H1": [1, 2, 3]},
)

# Create a transform element using an arbitrary function
trn1 = CallableTransform.from_callable(
    name="t1",
    sink_pad_names=["H1"],
    callable=add_ten,
    output_name="H1",
)

# Create the sink so we can access the data after running
snk = DequeSink(
    name="snk1",
    sink_pad_names=("H1",),
)

# Create the Pipeline
p = Pipeline()

# Insert elements into pipeline and link them explicitly
p.insert(src, trn1, snk, link_map={
    "t1:sink:H1": "src1:src:H1",
    "snk1:sink:H1": "t1:src:H1",
})

# Run the pipeline
p.run()

Then setting the env variable and running it gives:


$ SGNDEBUG=1 python test.py 
Executing graph loop 1:
	SourcePad(name='src1:src:H1', _id='2522afebccb844b098680a2a7fae1743'):Frame(EOS=False, is_gap=False, metadata={'__graph__': '-> src1:src:H1 '}, data=3)
	SinkPad(name='t1:sink:H1', _id='817a956cb11c4fe286968fe1862d051b'):Frame(EOS=False, is_gap=False, metadata={'__graph__': '-> src1:src:H1 -> t1:sink:H1 '}, data=3)
	SourcePad(name='t1:src:H1', _id='da878d3bb6d1460db26bb246aa8d7a92'):Frame(EOS=False, is_gap=False, metadata={'__graph__': '-> t1:src:H1 '}, data=13)
	SinkPad(name='snk1:sink:H1', _id='4f5ebe2e1abd408283f70196c4e3001e'):Frame(EOS=False, is_gap=False, metadata={'__graph__': '-> t1:src:H1 -> snk1:sink:H1 '}, data=13)
Executing graph loop 2:
	SourcePad(name='src1:src:H1', _id='2522afebccb844b098680a2a7fae1743'):Frame(EOS=False, is_gap=False, metadata={'__graph__': '-> src1:src:H1 '}, data=2)
	SinkPad(name='t1:sink:H1', _id='817a956cb11c4fe286968fe1862d051b'):Frame(EOS=False, is_gap=False, metadata={'__graph__': '-> src1:src:H1 -> t1:sink:H1 '}, data=2)
	SourcePad(name='t1:src:H1', _id='da878d3bb6d1460db26bb246aa8d7a92'):Frame(EOS=False, is_gap=False, metadata={'__graph__': '-> t1:src:H1 '}, data=12)
	SinkPad(name='snk1:sink:H1', _id='4f5ebe2e1abd408283f70196c4e3001e'):Frame(EOS=False, is_gap=False, metadata={'__graph__': '-> t1:src:H1 -> snk1:sink:H1 '}, data=12)
Executing graph loop 3:
	SourcePad(name='src1:src:H1', _id='2522afebccb844b098680a2a7fae1743'):Frame(EOS=False, is_gap=False, metadata={'__graph__': '-> src1:src:H1 '}, data=1)
	SinkPad(name='t1:sink:H1', _id='817a956cb11c4fe286968fe1862d051b'):Frame(EOS=False, is_gap=False, metadata={'__graph__': '-> src1:src:H1 -> t1:sink:H1 '}, data=1)
	SourcePad(name='t1:src:H1', _id='da878d3bb6d1460db26bb246aa8d7a92'):Frame(EOS=False, is_gap=False, metadata={'__graph__': '-> t1:src:H1 '}, data=11)
	SinkPad(name='snk1:sink:H1', _id='4f5ebe2e1abd408283f70196c4e3001e'):Frame(EOS=False, is_gap=False, metadata={'__graph__': '-> t1:src:H1 -> snk1:sink:H1 '}, data=11)
Executing graph loop 4:
	SourcePad(name='src1:src:H1', _id='2522afebccb844b098680a2a7fae1743'):Frame(EOS=True, is_gap=False, metadata={'__graph__': '-> src1:src:H1 '}, data=None)
	SinkPad(name='t1:sink:H1', _id='817a956cb11c4fe286968fe1862d051b'):Frame(EOS=True, is_gap=False, metadata={'__graph__': '-> src1:src:H1 -> t1:sink:H1 '}, data=None)
	SourcePad(name='t1:src:H1', _id='da878d3bb6d1460db26bb246aa8d7a92'):Frame(EOS=True, is_gap=False, metadata={'__graph__': '-> t1:src:H1 '}, data=None)
	SinkPad(name='snk1:sink:H1', _id='4f5ebe2e1abd408283f70196c4e3001e'):Frame(EOS=True, is_gap=False, metadata={'__graph__': '-> t1:src:H1 -> snk1:sink:H1 '}, data=None)
Edited by Chad Hanna

Merge request reports

Loading