Sheharyar
Sheharyar

Reputation: 75820

Log a Stream of text

I have an Elixir app where I spawn an external process using Porcelain. The spawned process' STDOUT is available to me as stream of text as proc.out (in the form of #Function<59.89908360/2 in Stream.unfold/2>).

I'm able to print the stream's content line by line using IO.stream/2 but I would explicitly like to do it using Logger.info. This is what it currently looks like:

proc = Porcelain.spawn("node", ["/path/to/node/server.js"], [out: :stream])
stream = proc.out
Enum.into(stream, IO.stream(:stdio, :line))

I've currently tried:

Upvotes: 1

Views: 264

Answers (1)

Sheharyar
Sheharyar

Reputation: 75820

Enum.map/2 and Enum.each/2 both solve my problem by iterating over the stream lines and applying Logger.info. But as @dogbert pointed out, each might be faster and better suited in this case:

Enum.each(stream, &Logger.info/1)

Upvotes: 1

Related Questions