Reputation: 421
I am trying to configure logger to my script
#! /bin/bash
alias log="logger -s -t conf_nginx"
exec >> /var/log/myscript/file.log
exec 2>&1
log "this a log message"
when I am executing this script, I only see this line in the log file
$ cat /var/log/myscript/file.log
logger: socket /dev/log: No such file or directory
Please help
$cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 9 (stretch)" NAME="Debian GNU/Linux" VERSION_ID="9" VERSION="9 (stretch)" ID=debian HOME_URL="debian.org/" SUPPORT_URL="debian.org/support" BUG_REPORT_URL="bugs.debian.org/"
Upvotes: 2
Views: 7563
Reputation: 295736
Because a Docker container has its own filesystem namespace, the /dev/log
socket from the host won't be available within -- and because best-practice in the Docker world is to have each container only running a single service, there generally won't exist a separate log daemon inside the local container.
Best practice is to just log to the container's stdout and stderr. Thus, instead of running logger -s -t conf_nginx "this is a log message"
, just echo "this is a log message" >&2
.
Aliases are a facility intended for interactive use, not scripting, and are in some shells turned off by default in interactive mode. Use a function instead:
log() { logger -s -t conf_nginx "$@"; }
Upvotes: 2