forked from kwindrem/SetupHelper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LogHandler
executable file
·64 lines (55 loc) · 1.77 KB
/
LogHandler
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# LogHandler for SetupHelper
# contains a functions and variables necessare=y to write to and output logs
#
# Refer to the SetupHelper ReadMe file for details on how to use these resources
#
# it is sourced by CommonResources and reinstall Mods
#
# there may be two logs associated with a setup script:
# the script helper log and optionally the package log
# logs are written to both places and additionally the command line if not running from reinstallMods
setupLogFile="/var/log/SetupHelper"
# enable logging to console
# scripts can disable logging by setting
# logToConsole to false AFTER sourcing LogHandler
logToConsole=true
# output the last 100 lines of the log file to the console
# the full path to the log file should be passed in $1
# converts the tai64 time stamp to human readable form
#
# $1 specifies the path to the log file
# $setupLogFile
# $packageLogFile is defined to point to the log file of the package if it exists
displayLog ()
{
if [ ! -z "$1" ]; then
if [ -f "$1" ]; then
tail -100 "$1" | tai64nlocal
else
echo "no log File $1 found"
fi
else
echo "no log File specified"
fi
}
# write a message to one or more log files
logMessage ()
{
# to console
if $logToConsole ; then
echo "$*"
fi
# to setup helper log
if [ ! -z $setupLogFile ]; then
echo "$shortScriptName: $*" | tai64n >> $setupLogFile
fi
# to setup helper log
if [ ! -z $packageLogFile ]; then
# no log file yet - make enclosing directory
# if directory already exists mkdir will do nothing (silently)
if [ ! -f "$packageLogFile" ]; then
mkdir -p $(dirname "$packageLogFile")
fi
echo "$shortScriptName: $*" | tai64n >> $packageLogFile
fi
}