framer.go 810 B

12345678910111213141516171819202122232425
  1. package srslog
  2. import (
  3. "fmt"
  4. )
  5. // Framer is a type of function that takes an input string (typically an
  6. // already-formatted syslog message) and applies "message framing" to it. We
  7. // have different framers because different versions of the syslog protocol
  8. // and its transport requirements define different framing behavior.
  9. type Framer func(in string) string
  10. // DefaultFramer does nothing, since there is no framing to apply. This is
  11. // the original behavior of the Go syslog package, and is also typically used
  12. // for UDP syslog.
  13. func DefaultFramer(in string) string {
  14. return in
  15. }
  16. // RFC5425MessageLengthFramer prepends the message length to the front of the
  17. // provided message, as defined in RFC 5425.
  18. func RFC5425MessageLengthFramer(in string) string {
  19. return fmt.Sprintf("%d %s", len(in), in)
  20. }