What I want to achieve is redirect both normal message and error message to a file. But also print the error message to the console (only error message).
One (out of many) solutions is the following:
command 2>&1 1>logfile | tee -a logfile
`2>&1` redirect the output of STDERR to STDOUT `1>logfile` redirect STDOUT (note: leaves STDERR unchanged) `| tee -a logfile` append the redirected STDERR to the logfile
For more information, see the Bash Hackers Wiki