You are not logged in.

#1 2011-10-29 01:00:07

stqn
Member
Registered: 2010-03-19
Posts: 1,191
Website

[SOLVED] How to merge stderr and a log file in real time?

I'm using a program that produces a log file and also writes debug information to stderr.

I'd like to merge the two outputs in real time so that I can see everything in the same place. Is there a way to do that?

Thanks.

Edit: I actually want to save the output, not see it in real time...

Last edited by stqn (2011-10-29 03:18:09)

Offline

#2 2011-10-29 01:19:33

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] How to merge stderr and a log file in real time?

What happens if you redirect stderr to the log and view the log with 'tail -f'?

Edit:

multitail -I file1 -I file2

seems to work.

# pacman -S multitail

Last edited by karol (2011-10-29 01:50:31)

Offline

#3 2011-10-29 02:25:37

stqn
Member
Registered: 2010-03-19
Posts: 1,191
Website

Re: [SOLVED] How to merge stderr and a log file in real time?

I've tried your first idea and it almost works. If I run the program like this:

program 2>>program.log

Then I can get the mix with:

tail -f program.log >new.log

But unfortunately every time something is output to stderr, it swallows a bit of the original log (some text is missing.)

On the other hand, multitail looks quite awesome smile. Unfortunately, I can't make it save the output to a file... Options "-a" and "-A" are supposed to do it, but it only creates an empty file.

Offline

#4 2011-10-29 02:29:27

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] How to merge stderr and a log file in real time?

You create an empty file

touch foo

and redirect the output of the command to it

somecommand > foo

(just one '>')

multitail -I foo -I /var/log/pacman.log

seems to work.

Edit: Ah, I get what you want now. I'll check the -a / -A part.

Last edited by karol (2011-10-29 02:32:15)

Offline

#5 2011-10-29 02:42:47

stqn
Member
Registered: 2010-03-19
Posts: 1,191
Website

Re: [SOLVED] How to merge stderr and a log file in real time?

Yeah maybe it wasn't clear that I want to save the merged logs in order to be able to examine all of it later. I didn't mention that at all, in fact wink.

Offline

#6 2011-10-29 02:53:58

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] How to merge stderr and a log file in real time?

Try

multitail -a outputfile -I file1 -a outputfile -I file2

file1 and file2 are the log and stderr and the outputfile is what you can view later - both sources interleaved with each other., just like when you view them with multitail.

Last edited by karol (2011-10-29 02:54:49)

Offline

#7 2011-10-29 03:16:54

stqn
Member
Registered: 2010-03-19
Posts: 1,191
Website

Re: [SOLVED] How to merge stderr and a log file in real time?

Yes, it's working! I was simply adding "-a file" at the end of the command line but that only produces an empty file. The man page doesn't mention that "-a" has to be used before each input file...

Thanks a lot for your help smile. This will be very helpful to see what's going on and improve the program.

Offline

Board footer

Powered by FluxBB