code: func (b *Buffer) Add(m *rfc5424.Message) error {
  	b.mu.Lock()
  	defer b.mu.Unlock()
  
  	if b.length == -1 {
  		return errors.New("buffer closed")
  	}
  	if b.head == nil {
  		b.head = &message{Message: *m}
  		b.tail = b.head
  	} else {
  		// iterate from newest to oldest through messages to find position
  		// to insert new message
  		for other := b.tail; other != nil; other = other.prev {
  			if m.Timestamp.Equal(other.Timestamp) && bytes.Equal(m.StructuredData, other.StructuredData) {
  				// duplicate log line
  				return nil
  			}
  			if m.Timestamp.Before(other.Timestamp) {
  				if other.prev == nil {
  					// insert before other at head
  					other.prev = &message{Message: *m, next: other}
  					b.head = other.prev
  					break
  				} else {
  					continue
  				}
  			}
  			msg := &message{Message: *m, prev: other}
  			if other.next != nil {
  				// insert between other and other.next
  				other.next.prev = msg
  				msg.next = other.next
  			} else {
  				// insert at tail
  				b.tail = msg
  			}
  			other.next = msg
  			break
  		}
  	}
  	if b.length < b.capacity {
  		// buffer not yet full
  		b.length++
  	} else {
  		// at capacity, remove head
  		b.head = b.head.next
  		b.head.prev = nil
  	}
  
  	for msgc := range b.subs {
  		select {
  		case msgc <- m:
  		default: // chan is full, drop this message to it
  		}
  	}
  
  	return nil
  }
docs: // Add adds an element to the Buffer. If the Buffer is already full, it removes
  // an existing message.