#!/bin/bash
# logging - __package__ logging library
set -e
lib_load 'core/file'
######
# Settings
# logging - Enables logging
logging=${logging:-false}
# logdir - Location for log files
logdir=${logdir:-/home/zwelch/src/mcf/mcsh/install/log/mcsh}
######
# Configuration
log_config_init() {
lib_setting_vars logging
lib_setting_vars -ro logdir
}
######
# Output support
# log_pipe - Passes stdin to stdout, saving a copy to file ($1).
log_pipe() {
has_args 1 "$@"
logging=false pretend=false file_mkdir "$1"
tee -a "$1"
}
######
# Log file support
# log_filename - Returns log filename given its base name ($1).
log_filename() {
echo "$logdir/${1:-main}.log}"
}
# log_rotate - Rotates log file ($1), saving $2 (int) old files.
log_rotate() {
has_args 2 "$@"
local log=$1
local dst=$2
if [ $dst -eq 0 ]; then
if [ -f "$log" ]; then
run mv "$log" "$log.$dst"
run gzip "$log.$dst"
fi
return
fi
local src
src=$(($dst - 1))
if [ -f "$log.$src.gz" ]; then
run mv "$log.$src.gz" "$log.$dst.gz"
fi
log_rotate "$log" "$src"
}
Generated on Tue Apr 25 21:20:11 PDT 2017 by mcsh i7 v0.18.0.