Skip to content

采集socket源消息,怎么消除换行符 #22141

Answered by jszwedko
papapy asked this question in Q&A
Discussion options

You must be logged in to vote

Got it, thanks! Yes, sending a message that ends with a newline with nc will result in Vector receiving the message with a newline. You can use a remap transform to trim it like:

sources:
  dummy_logs:
    type: socket
    address: 0.0.0.0:55555
    mode: udp

transforms:
    trim:
        type: remap
        inputs: ["dummy_logs"]
        source: |
            .message = strip_whitespace!(.message)

sinks:
  file:
    type: file
    inputs: ["trim"]
    path: demo-%Y-%m-%d.log
    encoding: 
      codec: raw_message
  print:
    type: "console"
    inputs: ["trim"]
    encoding:
      codec: "json"
      json:
        pretty: true

See https://vector.dev/docs/reference/configuration/tran…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@papapy
Comment options

@papapy
Comment options

@jszwedko
Comment options

Answer selected by pront
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants