Skip to content

TCP/UDP Sources

Receive logs over the network via TCP or UDP connections. Applications can stream logs directly to Logger for real-time viewing.

TCP vs UDP#

  • TCP: Reliable delivery, connection-based. Best for most applications.
  • UDP: Fast, connectionless. Good for high-volume, loss-tolerant logs.

Sending Logs#

Send newline-delimited logs to the configured port:

# TCP
echo '{"level":"info","msg":"hello"}' | nc localhost 9000

# UDP
echo '{"level":"info","msg":"hello"}' | nc -u localhost 9001

Windows (PowerShell)#

# TCP
$c=[Net.Sockets.TcpClient]::new("localhost",9000);$w=[IO.StreamWriter]::new($c.GetStream());$w.WriteLine('{"level":"info","msg":"hello"}');$w.Flush();$w.Close();$c.Close()

# UDP
$c=[Net.Sockets.UdpClient]::new();$b=[Text.Encoding]::UTF8.GetBytes('{"level":"info","msg":"hello"}');$c.Send($b,$b.Length,"localhost",9001)

Buffering Issues#

Many programs use block buffering when their output is piped instead of sent to a terminal. This causes logs to be delayed or batched together instead of streaming line-by-line.

Use stdbuf -oL to force line buffering, sending each line immediately:

# Without stdbuf - logs may be delayed or batched
my-app | nc localhost 9000

# With stdbuf - logs sent immediately per line
stdbuf -oL my-app | nc localhost 9000

The -oL flag sets stdout to line-buffered mode. This is essential for real-time log streaming.

Advanced Sending with socat#

socat is a more powerful alternative to nc with better connection handling and more options:

# Basic TCP with socat
stdbuf -oL my-app | socat - TCP:localhost:9000

# UDP with socat (datagram mode, no shutdown signal)
stdbuf -oL my-app | socat - UDP4-DATAGRAM:localhost:9001,shut-none

# TCP with keep-alive (maintains connection)
stdbuf -oL my-app | socat - TCP:localhost:9000,keepalive

How to use

  1. Configure a TCP source on port 9000 in tab settings
  2. Pipe application output to netcat

Related