Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional delimiter for messages #60

Closed
eloo opened this issue Mar 25, 2020 · 6 comments · Fixed by #75
Closed

Additional delimiter for messages #60

eloo opened this issue Mar 25, 2020 · 6 comments · Fixed by #75
Assignees

Comments

@eloo
Copy link

eloo commented Mar 25, 2020

Hello,

i'm testing your library right now to use it together with a fluentD stack and it looks like we could need an additional delimiter to the fired messages.

So would it be possible to configure an additional delimiter for the hook? For example a nullcharacter?
This could be easily done like this

func (f LogstashFormatter) Format(e *logrus.Entry) ([]byte, error) {
    ne := copyEntry(e, f.Fields)
    dataBytes, err := f.Formatter.Format(ne)
    releaseEntry(ne)
    dataBytes = append(dataBytes, []byte("\000")...)
    return dataBytes, err
}

What do you think about it?

Thanks
eloo

@boaz0
Copy link
Member

boaz0 commented Mar 25, 2020

Hi @eloo 👋,

Thanks for your ticket but just a small question:
Is that delimiter necessary for fluentd or logstash?

What I mean is why do you need to append \000 to the end of each entry?

Thanks.

@boaz0 boaz0 self-assigned this Mar 25, 2020
@eloo
Copy link
Author

eloo commented Mar 26, 2020

Hi @boaz0,
i'm not sure if this is related to the fluentd or logstash more to the tcp server implementation we are using.
Its a cool.io ruby server where we need to set a specific delimiter which is in our case a null byte.
So without this specific delimiter the tcp server doesn't recognise the start and end of the message properly.

Thanks

@boaz0
Copy link
Member

boaz0 commented Mar 27, 2020

Hi @eloo

In order to append characters to the formatted message you can do the following thing:

  1. Create a customized writer
type SuffixAppender struct {
  nextWriter io.Writer
}

func (sa SuffixAppender) Write(dataBytes []byte) (int, error) {
  newData := append(dataBytes, []byte("\n")...)
  n, err := sa.nextWriter.Write(newData)
  return n, err
}
  1. Then when setting a new logrustash instance create SuffixAppender and pass it to New as writer.
    For example, in order to print to stdout do the following:
  log := logrus.New()
  sout := SuffixAppender{nextWriter: os.Stdout}
  hook := logrustash.New(sout, logrustash.DefaultFormatter(...))

Does that solve your problem?

@eloo
Copy link
Author

eloo commented Apr 6, 2020

@boaz0
Thanks for this snippet.
Its working perfectly 👍
Just need to exchange the \n with my \000.

Thanks!

@boaz0
Copy link
Member

boaz0 commented Apr 6, 2020

Thanks @eloo

I will add this to the docs and close it once it's merged.

Best regards.

@eloo
Copy link
Author

eloo commented Apr 6, 2020

sounds good.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants