rtorrent icon indicating copy to clipboard operation
rtorrent copied to clipboard

Log to stdout

Open peloyeje opened this issue 3 years ago • 1 comments

Hello,

I'm currently trying to output logs to stdout in order to take advantage of s6 log handling system, here what I did so far:

...
log.open_file = "main", (cat, "/dev/stdout")

# Based on levels defined here: https://github.com/jesec/libtorrent/blob/master/include/torrent/utils/log.h
log.add_output = "dht_info", "main"
log.add_output = "peer_info", "main"
...

After granting the user running rtorrent the rights to write to /dev/pts/0, logging correctly appears in stdout:

rTorrent: started, 0 torrents loaded
1653143350 N rtorrent scgi: Starting thread.
1653143350 N rtorrent main: Starting thread.

But an error msg pops before any output: Error in option file: /config/rtorrent/rtorrent.d/05-log.rc:2: Could not open log file '/dev/stdout'.

I was wondering if that's a good way to go - my c++ fu is pretty basic and I don't really know the semantics/primitives to write to stdout in this language haha - or whether stdout support requires some adjustments and should be a feature request.

For additional context, with this setup, s6-overlay logging capture feature is not working as expected: only the aforementioned log line is captured endlessly. AFAIU this feature works by creating in/out fd for each program and passing them around (hope I got it right), could this be related to the fact that I specified /dev/stdout explicitely?

Thanks for the help! Happy to provide any info

peloyeje avatar May 21 '22 14:05 peloyeje

Here's a workaround, make a fifo:

#!/usr/bin/env bash
set -eo pipefail

main() {
  rm -f /var/log/rtorrent.log
  mkfifo /var/log/rtorrent.log
  exec 3<>/var/log/rtorrent.log
  cat <&3 >&2 &
  local tail_rtorrent_pid=$!

  rtorrent "$@" &
  local rtorrent_pid=$!

  local signal
  for signal in TERM HUP INT USR1 USR2 QUIT; do
    # shellcheck disable=2064
    trap "kill -$signal $rtorrent_pid;" $signal
  done
  wait $rtorrent_pid
  # shellcheck disable=2064
  trap "kill $tail_rtorrent_pid" EXIT
}

main "$@"

andsens avatar Oct 29 '25 16:10 andsens