Linux non-blocking fifo (on demand logging)

前端 未结 10 2325
你的背包
你的背包 2020-11-29 19:20

I like to log a programs output \'on demand\'. Eg. the output is logged to the terminal, but another process can hook on the current output at any time.

The classic

10条回答
  •  难免孤独
    2020-11-29 19:54

    The logging could be directed to a UDP socket. Since UDP is connection-less, it won't block the sending program. Of course logs will be lost if the receiver or network can't keep up.

    myprogram 2>&1 | socat - udp-datagram:localhost:3333
    

    Then when you want to observe the logging:

    socat udp-recv:3333 -
    

    There are some other cool benefits like being able to attach multiple listeners at the same time or broadcast to multiple devices.

提交回复
热议问题