Logging api

Reviewers:  @bernerdschaefer, @peterbourgon 

First pass at the internals of the logging API.  This is two layers thick.  There is a RingBuffer for log messages, and on top of this is a data structure that implements storage for and operations for each container.  (The RingBuffer probably should have been a separate submit.)

The next piece to be worked on will be the HTTP logging interface.
Done


On Wed, Jul 30, 2014 at 5:52 PM, Bernerd Schaefer <notifications@github.com>
wrote:

> In harpoon-agent/logs.go:
>
> > +// Last retrieves the n last log lines from containerID, returning them in
> > +// the order from oldest to newest, i.e. []string{oldest, newer, ..., newest}.
> > +// The call is is idempotent.
> > +func (cl *containerLog) Last(n int) []string {
> > +	msg := logLast{count: n, last: make(chan []string)}
> > +	cl.lastc <- msg
> > +	return <- msg.last
> > +}
> > +
> > +// Listen subscribes a listener to a container.  New log lines to the subscribed container
> > +// are set to all of its listeners via their supplied logSink channels.  A logSink does
> > +// receive messages while it is blocked.  All of those messages are lost like tears in the
> > +// rain.
> > +//
> > +// The caller can subsequently use the ListenerID to remove the subscription.
> > +func (cl *containerLog) Listen(logSink chan string) ListenerID {
>
> channels are comparable, and thus can be used as keys to a map:
>
> type containerLog struct {
>   listeners map[chan string]struct{}}
> func (*containerLog) Listen(logSink chan string) {
>   // ...}
> func (*containerLog) Unlisten(c chan string) {
>   // ...}
> func (cl *containerLog) addListener(c chan string) {
>   cl.listeners[c] = struct{}{}}
> func (cl *containerLog) removeListener(c chan string) {
>   delete(cl.listeners, c)}
>
> This lets you get rid of the id generation stuff. For an example, see
> container.go, lines 125-131 and 153-156. I think Subscribe/Unsubscribe
> would also be good verbs for the loggers.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/soundcloud/harpoon/pull/13/files#r15592705>.
>