Add --syslog to allow logging of errors, info or debug to system log.

This commit is contained in:
David Kerr 2017-02-04 12:06:31 -05:00
parent f2a6dc4dfd
commit 3a02158ebf

45
acme.sh
View File

@ -58,6 +58,12 @@ LOG_LEVEL_1=1
LOG_LEVEL_2=2 LOG_LEVEL_2=2
LOG_LEVEL_3=3 LOG_LEVEL_3=3
DEFAULT_LOG_LEVEL="$LOG_LEVEL_1" DEFAULT_LOG_LEVEL="$LOG_LEVEL_1"
SYSLOG_LEVEL=0
SYSLOG_ERROR=3
SYSLOG_INFO=6
SYSLOG_DEBUG=7
SYSLOG_DEBUG2=8
SYSLOG_DEBUG3=9
_DEBUG_WIKI="https://github.com/Neilpang/acme.sh/wiki/How-to-debug-acme.sh" _DEBUG_WIKI="https://github.com/Neilpang/acme.sh/wiki/How-to-debug-acme.sh"
@ -129,11 +135,17 @@ _log() {
_info() { _info() {
_log "$@" _log "$@"
if [ "$SYSLOG_LEVEL" -ge "$SYSLOG_INFO" ]; then
logger -i -t "acme.sh" -p "user.info" "$@" >/dev/null 2>&1
fi
_printargs "$@" _printargs "$@"
} }
_err() { _err() {
_log "$@" _log "$@"
if [ "$SYSLOG_LEVEL" -ge "$SYSLOG_ERROR" ]; then
logger -i -t "acme.sh" -p "user.error" "$@" >/dev/null 2>&1
fi
if [ -z "$NO_TIMESTAMP" ] || [ "$NO_TIMESTAMP" = "0" ]; then if [ -z "$NO_TIMESTAMP" ] || [ "$NO_TIMESTAMP" = "0" ]; then
printf -- "%s" "[$(date)] " >&2 printf -- "%s" "[$(date)] " >&2
fi fi
@ -155,6 +167,9 @@ _debug() {
if [ -z "$LOG_LEVEL" ] || [ "$LOG_LEVEL" -ge "$LOG_LEVEL_1" ]; then if [ -z "$LOG_LEVEL" ] || [ "$LOG_LEVEL" -ge "$LOG_LEVEL_1" ]; then
_log "$@" _log "$@"
fi fi
if [ "$SYSLOG_LEVEL" -ge "$SYSLOG_DEBUG" ]; then
logger -i -t "acme.sh" -p "user.debug" "$@" >/dev/null 2>&1
fi
if [ -z "$DEBUG" ]; then if [ -z "$DEBUG" ]; then
return return
fi fi
@ -165,6 +180,9 @@ _debug2() {
if [ "$LOG_LEVEL" ] && [ "$LOG_LEVEL" -ge "$LOG_LEVEL_2" ]; then if [ "$LOG_LEVEL" ] && [ "$LOG_LEVEL" -ge "$LOG_LEVEL_2" ]; then
_log "$@" _log "$@"
fi fi
if [ "$SYSLOG_LEVEL" -ge "$SYSLOG_DEBUG2" ]; then
logger -i -t "acme.sh" -p "user.debug" "$@" >/dev/null 2>&1
fi
if [ "$DEBUG" ] && [ "$DEBUG" -ge "2" ]; then if [ "$DEBUG" ] && [ "$DEBUG" -ge "2" ]; then
_debug "$@" _debug "$@"
fi fi
@ -174,6 +192,9 @@ _debug3() {
if [ "$LOG_LEVEL" ] && [ "$LOG_LEVEL" -ge "$LOG_LEVEL_3" ]; then if [ "$LOG_LEVEL" ] && [ "$LOG_LEVEL" -ge "$LOG_LEVEL_3" ]; then
_log "$@" _log "$@"
fi fi
if [ "$SYSLOG_LEVEL" -ge "$SYSLOG_DEBUG3" ]; then
logger -i -t "acme.sh" -p "user.debug" "$@" >/dev/null 2>&1
fi
if [ "$DEBUG" ] && [ "$DEBUG" -ge "3" ]; then if [ "$DEBUG" ] && [ "$DEBUG" -ge "3" ]; then
_debug "$@" _debug "$@"
fi fi
@ -4241,6 +4262,7 @@ Parameters:
--accountkeylength, -ak [2048] Specifies the account key length. --accountkeylength, -ak [2048] Specifies the account key length.
--log [/path/to/logfile] Specifies the log file. The default is: \"$DEFAULT_LOG_FILE\" if you don't give a file path here. --log [/path/to/logfile] Specifies the log file. The default is: \"$DEFAULT_LOG_FILE\" if you don't give a file path here.
--log-level 1|2 Specifies the log level, default is 1. --log-level 1|2 Specifies the log level, default is 1.
--syslog [error|info|debug|debug2|debug3] Specifies that messages will be logged to system syslog. Default level is error.
These parameters are to install the cert to nginx/apache or anyother server after issue/renew a cert: These parameters are to install the cert to nginx/apache or anyother server after issue/renew a cert:
@ -4393,6 +4415,7 @@ _process() {
_deploy_hook="" _deploy_hook=""
_logfile="" _logfile=""
_log="" _log=""
_syslog=""
_local_address="" _local_address=""
_log_level="" _log_level=""
_auto_upgrade="" _auto_upgrade=""
@ -4721,6 +4744,28 @@ _process() {
LOG_LEVEL="$_log_level" LOG_LEVEL="$_log_level"
shift shift
;; ;;
--syslog)
_syslog="$2"
if [ -z "$_syslog" ] || _startswith "$_syslog" '-'; then
_syslog="error"
else
shift
fi
if _startswith "$_syslog" "error"; then
SYSLOG_LEVEL=$SYSLOG_ERROR
elif _startswith "$_syslog" "info"; then
SYSLOG_LEVEL=$SYSLOG_INFO
elif _startswith "$_syslog" "debug3"; then
SYSLOG_LEVEL=$SYSLOG_DEBUG3
elif _startswith "$_syslog" "debug2"; then
SYSLOG_LEVEL=$SYSLOG_DEBUG2
elif _startswith "$_syslog" "debug"; then
SYSLOG_LEVEL=$SYSLOG_DEBUG
else
_err "Invalid parameter to --syslog, must be one of error, info or debug"
return 1
fi
;;
--auto-upgrade) --auto-upgrade)
_auto_upgrade="$2" _auto_upgrade="$2"
if [ -z "$_auto_upgrade" ] || _startswith "$_auto_upgrade" '-'; then if [ -z "$_auto_upgrade" ] || _startswith "$_auto_upgrade" '-'; then