typesafehub / akka-contrib-extra

ConductR Akka contributions
Other
9 stars 16 forks source link

A logging Subscriber #42

Closed jeantil closed 9 years ago

jeantil commented 9 years ago

It parses lines out of a Stream[ByteString] then logs them to the enclosing ActorSystem logging bus.

Lines are defined by a separator ("\n" by default), bytes are accumulated until a separator is found or the maximumLineLength is exceeded (1MByte by default)

I wrote this to be able to centralize logs from processes spawned with akka.contrib.process.BlockingProcess to the application log file (in my case a webdriver based app)

huntc commented 9 years ago

Just wondering if you actually observed the lines to become fragmented. I've never observed this to be the case... The InputStreamPublisher will just publish whatever it receives via InputStream.read. I guess that it can become fragmented, but I'd like to understand why that would be a problem.

jeantil commented 9 years ago

hello,

I have not actually observed fragmentation but considering that the BlockingProcess uses an InputStreamPublisher which itself has an internal buffer of 8k bytes, if the process were to log messages longer than 8k, fragmentation would occur.

The use case I have in mind is logging, and I have seen logfiles reprocessed through the use of unix tools (cat/grep/...), or other linefeed sensitive tools, often enough that I would prefer avoiding introducing linefeeds as much as possible

Actually in my project I would probably configure the maximumLineLength at something even larger than 1MB

jeantil commented 9 years ago

In the end, this pull request is not needed, a better way will be available once https://github.com/akka/akka/pull/17446 is merged.

with Framing, the conversion from bytestring to line becomes

source(stdout).via(Framing.lines("\n", maximumLineBytes = 1024*1024)).foreach

which can then be logged in a foreach, making this class completely unnecessary.

Regards

huntc commented 9 years ago

nice one - thanks