Linux bash how to create stderr, stdout and combined log file

with linux bash I need to redirect the logs of my nodejs application to the stdout and stderr file, but also create a third log file that combines both of them into one.

I used: node app.js 1>log/stdout.log 2>log/stderr.log

And I was looking for some command to add to create a log file that combines stdout.log with stderr.log in the shared.log file.

I tried to use the command teefrom the suggestions of other similar questions, but I could not.

Can you help me?

thank

+4
source share
2 answers

3 : 0, stdin, 1, stdout 2, stderr, , , 2 , 3 tee: tee "" stdout

(((node app.js | tee log_stdout.txt) 3>&1 1>&2 2>&3 | tee log_stderr.txt ) 3>&2 2>&1 1>&3 ) > log_combined.txt 2>&1

+3

-

$ node a.js 1>stdout.log 2>stderr.log ; cat stdout.log stderr.log >> all.log

a.js

console.log('Hello World');

stdout -

root@a2980bfaeb16:/# node a.js 1>stdout.log 2>stderr.log ; cat stdout.log stderr.log >> all.log
root@a2980bfaeb16:/# cat stdout.log 
Hello World
root@a2980bfaeb16:/# cat stderr.log 
root@a2980bfaeb16:/# cat all.log    
Hello World

stderr ( , stderr) -

root@a2980bfaeb16:/# node a.js 1>stdout.log 2>stderr.log ; cat stdout.log stderr.log >> all.log
root@a2980bfaeb16:/# cat stdout.log 
root@a2980bfaeb16:/# cat stderr.log 
/a.js:1
(function (exports, require, module, __filename, __dirname) { console.g('Hello World');
                                                                      ^

TypeError: console.g is not a function
    at Object.<anonymous> (/a.js:1:71)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Function.Module.runMain (module.js:701:10)
    at startup (bootstrap_node.js:194:16)
    at bootstrap_node.js:618:3
root@a2980bfaeb16:/# cat all.log    
Hello World
/a.js:1
(function (exports, require, module, __filename, __dirname) { console.g('Hello World');
                                                                      ^

TypeError: console.g is not a function
    at Object.<anonymous> (/a.js:1:71)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Function.Module.runMain (module.js:701:10)
    at startup (bootstrap_node.js:194:16)
    at bootstrap_node.js:618:3

, !

PS - , .

0

Source: https://habr.com/ru/post/1692695/


All Articles