#!/bin/bash
#Name: lib-logging-ds
#Version: 1.0
#Depends: 
#Author: BitJam, Dave (david@daveserver.info)
#Purpose: Logging library for desktop-session
#License: gplv3

ME=${0##*/}

fatal() {
    echo "$ME: Fatal Error: $*"
    exit 2
}

warn()  { echo "$ME: Warning: $*"           ; }
say()   { echo "$ME: $*"                    ; }
log()   { echo "$ME: $*" >> $log_file       ; }
shout() { echo "$ME: $*" | tee -a $log_file ; }
psay()  { say "$(plural "$@")"              ; }

echo_variable() {
    echo "$ME: Setting environment variable: $*"
    export "$@"
}

echo_cmd() {
    echo "$ME: run: $*"
    "$@"
}

echo_eval_cmd() {
    echo "$ME: run: eval $*"
    eval "$@" &
}

echo_bg_cmd() {
    echo "$ME: run: $* &"
    "$@" &
}

rotate() {
    date=$(date +%Y-%m-%d_%H-%M);
    log_amount=5;
    
    [ -e $log_file ] && mv $log_file $log_file-$date.log

    log_file_count=$(find -maxdepth '1' -path "$user_dts_dir/*.log" |wc -l)
    if [ "$log_file_count" > "$log_amount" ]; then
        filter_number=$(expr "$log_amount" + "1" )
        for item in $( stat -c "%X|%n" "$user_dts_dir/*.log" |sort -r |tail -n "+$filter_number" )
        do
            file=$(echo $item | cut -d "|" -f2)
            rm $file;
        done
    fi
}
