Merge pull request #7 from darko-poljak/improve-logging
Improve logging: stdout, file, syslog options.
This commit is contained in:
commit
12b6b2cf28
4 changed files with 166 additions and 36 deletions
135
ccollect
135
ccollect
|
@ -127,6 +127,11 @@ fi
|
||||||
PARALLEL=""
|
PARALLEL=""
|
||||||
MAX_JOBS=""
|
MAX_JOBS=""
|
||||||
USE_ALL=""
|
USE_ALL=""
|
||||||
|
LOGFILE=""
|
||||||
|
SYSLOG=""
|
||||||
|
# e - only errors, a - all output
|
||||||
|
LOGLEVEL="a"
|
||||||
|
LOGONLYERRORS=""
|
||||||
|
|
||||||
#
|
#
|
||||||
# catch signals
|
# catch signals
|
||||||
|
@ -138,18 +143,11 @@ trap "${TRAPFUNC}" 1 2 15
|
||||||
# Functions
|
# Functions
|
||||||
#
|
#
|
||||||
|
|
||||||
# time displaying echo
|
# check if we are running interactive or non-interactive
|
||||||
_techo()
|
# see: http://www.tldp.org/LDP/abs/html/intandnonint.html
|
||||||
|
_is_interactive()
|
||||||
{
|
{
|
||||||
echo "$(${DDATE}): $@"
|
[ -t 0 -o -p /dev/stdin ]
|
||||||
}
|
|
||||||
|
|
||||||
# exit on error
|
|
||||||
_exit_err()
|
|
||||||
{
|
|
||||||
_techo "Error: $@"
|
|
||||||
rm -f "${TMP}"
|
|
||||||
exit 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
add_name()
|
add_name()
|
||||||
|
@ -192,13 +190,16 @@ ${__myname}: [args] <interval name> <sources to backup>
|
||||||
|
|
||||||
ccollect creates (pseudo) incremental backups
|
ccollect creates (pseudo) incremental backups
|
||||||
|
|
||||||
-h, --help: Show this help screen
|
-h, --help: Show this help screen
|
||||||
-a, --all: Backup all sources specified in ${CSOURCES}
|
-a, --all: Backup all sources specified in ${CSOURCES}
|
||||||
-j [max], --jobs [max] Specifies the number of jobs to run simultaneously.
|
-e, --errors: Log only errors
|
||||||
If max is not specified then parallelise all jobs.
|
-j [max], --jobs [max] Specifies the number of jobs to run simultaneously.
|
||||||
-p, --parallel: Parallelise backup processes (deprecated from 2.0)
|
If max is not specified then parallelise all jobs.
|
||||||
-v, --verbose: Be very verbose (uses set -x)
|
-l FILE, --logfile FILE Log to specified file
|
||||||
-V, --version: Print version information
|
-p, --parallel: Parallelise backup processes (deprecated from 2.0)
|
||||||
|
-s, --syslog: Log to syslog with tag ccollect
|
||||||
|
-v, --verbose: Be very verbose (uses set -x)
|
||||||
|
-V, --version: Print version information
|
||||||
|
|
||||||
This is version ${VERSION} released on ${RELEASE}.
|
This is version ${VERSION} released on ${RELEASE}.
|
||||||
|
|
||||||
|
@ -219,6 +220,54 @@ unlock()
|
||||||
"${unlockf}" "$@"
|
"${unlockf}" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# time displaying echo
|
||||||
|
# stdout version
|
||||||
|
_techo_stdout()
|
||||||
|
{
|
||||||
|
echo "$(${DDATE}): $@"
|
||||||
|
}
|
||||||
|
|
||||||
|
# syslog version
|
||||||
|
_techo_syslog()
|
||||||
|
{
|
||||||
|
logger -t ccollect "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
# specified file version
|
||||||
|
_techo_file()
|
||||||
|
{
|
||||||
|
_techo_stdout "$@" >> "${LOGFILE}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# determine _techo version before parsing options
|
||||||
|
if _is_interactive
|
||||||
|
then
|
||||||
|
_techof="_techo_stdout"
|
||||||
|
else
|
||||||
|
_techof="_techo_syslog"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# _techo with determined _techo version
|
||||||
|
_techo()
|
||||||
|
{
|
||||||
|
if [ "${LOGLEVEL}" = "a" ]
|
||||||
|
then
|
||||||
|
"${_techof}" "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_techo_err()
|
||||||
|
{
|
||||||
|
_techo "Error: $@"
|
||||||
|
}
|
||||||
|
|
||||||
|
_exit_err()
|
||||||
|
{
|
||||||
|
_techo_err "$@"
|
||||||
|
rm -f "${TMP}"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# Parse options
|
# Parse options
|
||||||
#
|
#
|
||||||
|
@ -247,6 +296,28 @@ while [ "$#" -ge 1 ]; do
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
-e|--errors)
|
||||||
|
LOGONLYERRORS="1"
|
||||||
|
;;
|
||||||
|
-l|--logfile)
|
||||||
|
if [ "$#" -ge 2 ]
|
||||||
|
then
|
||||||
|
case "$2" in
|
||||||
|
-*)
|
||||||
|
_exit_err "Missing log file"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
LOGFILE="$2"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
else
|
||||||
|
_exit_err "Missing log file"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
-s|--syslog)
|
||||||
|
SYSLOG="1"
|
||||||
|
;;
|
||||||
-v|--verbose)
|
-v|--verbose)
|
||||||
set -x
|
set -x
|
||||||
;;
|
;;
|
||||||
|
@ -268,6 +339,34 @@ while [ "$#" -ge 1 ]; do
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# determine _techo version and logging level after parsing options
|
||||||
|
if [ "${LOGFILE}" ]
|
||||||
|
then
|
||||||
|
_techof="_techo_file"
|
||||||
|
LOGLEVEL="a"
|
||||||
|
elif _is_interactive
|
||||||
|
then
|
||||||
|
if [ "${SYSLOG}" ]
|
||||||
|
then
|
||||||
|
_techof="_techo_syslog"
|
||||||
|
LOGLEVEL="a"
|
||||||
|
else
|
||||||
|
_techof="_techo_stdout"
|
||||||
|
LOGLEVEL="e"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
_techof="_techo_syslog"
|
||||||
|
LOGLEVEL="a"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${LOGFILE}" -o "${SYSLOG}" ]
|
||||||
|
then
|
||||||
|
if [ "${LOGONLYERRORS}" ]
|
||||||
|
then
|
||||||
|
LOGLEVEL="e"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# check that MAX_JOBS is natural number > 0
|
# check that MAX_JOBS is natural number > 0
|
||||||
# empty string means run all in parallel
|
# empty string means run all in parallel
|
||||||
echo "${MAX_JOBS}" | grep -q -E '^[1-9][0-9]*$|^$'
|
echo "${MAX_JOBS}" | grep -q -E '^[1-9][0-9]*$|^$'
|
||||||
|
|
16
doc/changes/2.0
Normal file
16
doc/changes/2.0
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
* Introduce -j option for max parallel jobs, deprecate -p (Darko Poljak)
|
||||||
|
* Add locking (Darko Poljak)
|
||||||
|
* Fix source-is-up check (Nikita Koshikov)
|
||||||
|
* Fix some minor command line parsing issues (Nico Schottelius)
|
||||||
|
* Correct output, if configuration is not in cconfig format (Nico Schottelius)
|
||||||
|
* Minor code cleanups and optimisations (Nico Schottelius)
|
||||||
|
* ccollect_analyse_logs.sh traps more errors and warnings (Patrick Drolet)
|
||||||
|
* Remove -v for mkdir and rm, as they are not POSIX (Patrick Drolet)
|
||||||
|
* Export destination_* to source specific post_exec (Nico Schottelius)
|
||||||
|
* Update documentation regarding exported variables (Nico Schottelius)
|
||||||
|
* Simplify time calculation (Nico Schottelius)
|
||||||
|
* Documentate pre_exec error handling (Nico Schottelius)
|
||||||
|
* Added start script (Thorsten Elle)
|
||||||
|
* Documentate autofs hint (Nico Schottelius)
|
||||||
|
* Speedup source-is-up check and remove --archive (Nico Schottelius)
|
||||||
|
* Removed support for remote backup (see doc) (Nico Schottelius)
|
|
@ -1,16 +1 @@
|
||||||
* Introduce -j option for max parallel jobs, deprecate -p (Darko Poljak)
|
* Add options for stdout, file and syslog logging (Darko Poljak)
|
||||||
* Add locking (Darko Poljak)
|
|
||||||
* Fix source-is-up check (Nikita Koshikov)
|
|
||||||
* Fix some minor command line parsing issues (Nico Schottelius)
|
|
||||||
* Correct output, if configuration is not in cconfig format (Nico Schottelius)
|
|
||||||
* Minor code cleanups and optimisations (Nico Schottelius)
|
|
||||||
* ccollect_analyse_logs.sh traps more errors and warnings (Patrick Drolet)
|
|
||||||
* Remove -v for mkdir and rm, as they are not POSIX (Patrick Drolet)
|
|
||||||
* Export destination_* to source specific post_exec (Nico Schottelius)
|
|
||||||
* Update documentation regarding exported variables (Nico Schottelius)
|
|
||||||
* Simplify time calculation (Nico Schottelius)
|
|
||||||
* Documentate pre_exec error handling (Nico Schottelius)
|
|
||||||
* Added start script (Thorsten Elle)
|
|
||||||
* Documentate autofs hint (Nico Schottelius)
|
|
||||||
* Speedup source-is-up check and remove --archive (Nico Schottelius)
|
|
||||||
* Removed support for remote backup (see doc) (Nico Schottelius)
|
|
||||||
|
|
|
@ -29,6 +29,9 @@ OPTIONS
|
||||||
-a, --all::
|
-a, --all::
|
||||||
Backup all sources specified in /etc/ccollect/sources
|
Backup all sources specified in /etc/ccollect/sources
|
||||||
|
|
||||||
|
-e, --errors::
|
||||||
|
Log only errors
|
||||||
|
|
||||||
-h, --help::
|
-h, --help::
|
||||||
Show the help screen
|
Show the help screen
|
||||||
|
|
||||||
|
@ -36,14 +39,41 @@ OPTIONS
|
||||||
Specifies the number of jobs to run simultaneously.
|
Specifies the number of jobs to run simultaneously.
|
||||||
If max is not specified then parallelise all jobs.
|
If max is not specified then parallelise all jobs.
|
||||||
|
|
||||||
|
-l FILE, --logfile FILE::
|
||||||
|
Log to specified file
|
||||||
|
|
||||||
-p, --parallel::
|
-p, --parallel::
|
||||||
Parallelise backup processes (deprecated from 2.0)
|
Parallelise backup processes (deprecated from 2.0)
|
||||||
|
|
||||||
|
-s, --syslog::
|
||||||
|
Log to syslog with tag ccollect
|
||||||
|
|
||||||
|
-V, --version::
|
||||||
|
Show version and exit
|
||||||
|
|
||||||
-v, --verbose::
|
-v, --verbose::
|
||||||
Be very verbose (uses set -x)
|
Be very verbose (uses set -x)
|
||||||
|
|
||||||
-V, --version::
|
|
||||||
Show version and exit
|
LOGGING MECHANISM
|
||||||
|
-----------------
|
||||||
|
ccollect logging depends on running in non-interactive/interactive mode
|
||||||
|
and on specified optins. The mechanism behaves as the following:
|
||||||
|
|
||||||
|
non-interactive mode::
|
||||||
|
|
||||||
|
* standard output goes to syslog
|
||||||
|
* optional: specify logging into file
|
||||||
|
* log all output by default
|
||||||
|
* optional: log only errors
|
||||||
|
|
||||||
|
interactive mode::
|
||||||
|
|
||||||
|
* standard output goes to stdout
|
||||||
|
* log only errors
|
||||||
|
* optional: log into syslog or file
|
||||||
|
- log all output by default
|
||||||
|
- optional: log only errors
|
||||||
|
|
||||||
|
|
||||||
SEE ALSO
|
SEE ALSO
|
||||||
|
|
Loading…
Reference in a new issue