Shell Script Error Logging

I am trying to set up a simple logging structure in my shell scripts. For this, I would like to define a function "log", which can be called

log "LEVEL" $message

If the message is a variable, to which I previously redirected the outputs of the executed commands. My problem is that I get errors with the following

{message=command 2>&3 1>&3 3>&-} >&3
log "INFO" $message

Is there something wrong there?

TIA

+3
source share
4 answers

Perhaps you want to:

message=$( command 2>&1 )
log INFO "$message"
+1
source

I developed a simple multi-level magazine for my shell scripts, you can take a look at usage, inspiration or something else you want.

+3
source

, (, , , ), logger, Unix — . . .

+1

$() ( ):

{ command; }
0

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


All Articles