You are not logged in.

#1 2024-10-30 20:15:41

pixie
Member
Registered: 2024-02-28
Posts: 8

Is it possible to log all stdout and stderr to a file? [RESOLVED]

I want to create a large log file for everything printed to stdout and stderr (separately, preferably) that is owned (might be the wrong terminology) by my user or the root. The idea is that I could run a program from the terminal like normal, and everything it printed would also be written to this log file. Is there a way to do this? It seems like something that a lot of people would have a use for.

Last edited by pixie (2024-11-01 01:17:11)

Offline

#2 2024-10-30 20:57:18

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: Is it possible to log all stdout and stderr to a file? [RESOLVED]

The simplest / manual way would be to use tee:

some-command-here 2>&1 | tee -a /path/to/logfile

If there were specific commands you wanted to log, this could work well.  But for every command typed directly in an interactive shell, you'd be better off using the `script' tool perhaps launched from your shellrc.

As for anything outside of an interactive shell, this would be highly impractical and likely be a very bad idea.  Most of that is logged somewhere already (mostly the journal nowadays).


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2024-10-30 21:45:26

bulletmark
Member
From: Brisbane, Australia
Registered: 2013-10-22
Posts: 673

Re: Is it possible to log all stdout and stderr to a file? [RESOLVED]

You want all output written to the terminal but stderr and stdout also logged to separate files so are you asking for something like?

some-command-here 2> >(tee stderr.log) > >(tee stdout.log)

Offline

#4 2024-10-30 22:01:47

seth
Member
Registered: 2012-09-03
Posts: 58,413

Re: Is it possible to log all stdout and stderr to a file? [RESOLVED]

Offline

#5 2024-10-31 00:11:11

pixie
Member
Registered: 2024-02-28
Posts: 8

Re: Is it possible to log all stdout and stderr to a file? [RESOLVED]

This is exactly what I had in mind, thank you!

Offline

#6 2024-10-31 06:59:33

seth
Member
Registered: 2012-09-03
Posts: 58,413

Re: Is it possible to log all stdout and stderr to a file? [RESOLVED]

\o/
Please always remember to mark resolved threads by editing your initial posts subject - so others will know that there's no task left, but maybe a solution to find.
Thanks.

Offline

Board footer

Powered by FluxBB