linux - Separately redirecting and recombining stderr/stdout without losing ordering -


i want execute command , want redirect stderr , stdout below:

stderr , stdout -> should written logs.log file while keeping order

stderr -> should printed screen , written errors.log

so far can redirect them both screen , file log.txt this:

command 2>&1 | tee logs.log 

but above not need.

to make more clear again results needs be.

after command executed need see on screen result of stderr, need have 1 file named errors.log stderr, , need have file named logs.log result of both stdout , stderr in original order in created.

preserving perfect order while performing separate redirections not theoretically possible without ugly hackery. ordering preserved in writes (in o_append mode) directly same file; put tee in 1 process not other, ordering guarantees go out window , can't retrieved without keeping information syscalls invoked in order.

so, hackery like? might this:

# eat our initialization time *before* start background process sudo sysdig-probe-loader  # now, start monitoring syscalls made children of shell write fd 1 or 2 # ...funnel content our logs.log file sudo sysdig -s 32768 -b -p '%evt.buffer' \   "proc.apid=$$ , event.type=write , (fd.num=1 or fd.num=2)" \   > >(base64 -i -d >logs.log) \   & sysdig_pid=$!  # run your-program, stderr going both console , errors.log ./your-program >/dev/null 2> >(tee errors.log) 

that said, remains ugly hackery: catches writes direct fds 1 , 2, , doesn't track further redirections may take place. (this improved performing writes fifos, , using sysdig track writes fifos; way fdup() , similar operations work as-expected; above suffices prove concept).


obviously, shouldn't of this. update program support whatever logging infrastructure available in native language (log4j in java, python logging module, etc) allow logging configured explicitly.


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -