func testRoundTripAndTextMarshaller(t *testing.T, f func(protolion.Logger), expected string) { for _, marshalPair := range []struct { marshaller lion.Marshaller unmarshaller lion.Unmarshaller }{ { protolion.DelimitedMarshaller, protolion.DelimitedUnmarshaller, }, { protolion.Base64DelimitedMarshaller, protolion.Base64DelimitedUnmarshaller, }, } { buffer := bytes.NewBuffer(nil) fakeTimer := newFakeTimer(0) logger := protolion.NewLogger( lion.NewLogger( lion.NewWritePusher( buffer, marshalPair.marshaller, ), lion.LoggerWithIDAllocator(newFakeIDAllocator()), lion.LoggerWithTimer(fakeTimer), ), ) f(logger) puller := lion.NewReadPuller( buffer, marshalPair.unmarshaller, ) writeBuffer := bytes.NewBuffer(nil) writePusher := lion.NewTextWritePusher( writeBuffer, lion.TextMarshallerDisableTime(), ) for encodedEntry, pullErr := puller.Pull(); pullErr != io.EOF; encodedEntry, pullErr = puller.Pull() { require.NoError(t, pullErr) entry, err := encodedEntry.Decode() require.NoError(t, err) require.NoError(t, writePusher.Push(entry)) } require.Equal(t, expected, writeBuffer.String()) } }
func testRoundTripAndTextMarshallerTail(t *testing.T, f func(protolion.Logger), expected string) { file, err := ioutil.TempFile("", "lion") require.NoError(t, err) filePath := file.Name() // will not actually get called if a require statement is hit defer func() { _ = file.Close() _ = os.Remove(filePath) }() fakeTimer := newFakeTimer(0) logger := protolion.NewLogger( lion.NewLogger( lion.NewWritePusher( file, protolion.Base64DelimitedNewlineMarshaller, ), lion.LoggerWithIDAllocator(newFakeIDAllocator()), lion.LoggerWithTimer(fakeTimer), ), ) f(logger) writeBuffer := bytes.NewBuffer(nil) writePusher := lion.NewTextWritePusher( writeBuffer, lion.TextMarshallerDisableTime(), ) require.NoError( t, taillion.Tail( filePath, protolion.Base64DelimitedUnmarshaller, writePusher.Push, nil, taillion.TailOptions{}, ), ) require.Equal(t, expected, writeBuffer.String()) }
/* Package sysloglion defines functionality for integration with syslog. */ package sysloglion // import "go.pedge.io/lion/syslog" import ( "log/syslog" "go.pedge.io/lion" ) var ( // DefaultTextMarshaller is the default text Marshaller for syslog. DefaultTextMarshaller = lion.NewTextMarshaller( lion.TextMarshallerDisableTime(), lion.TextMarshallerDisableLevel(), ) ) // PusherOption is an option for constructing a new Pusher. type PusherOption func(*pusher) // PusherWithMarshaller uses the Marshaller for the Pusher. // // By default, DefaultTextMarshaller is used. func PusherWithMarshaller(marshaller lion.Marshaller) PusherOption { return func(pusher *pusher) { pusher.marshaller = marshaller } }