alpha_omega 1.1.1 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/alpha_omega +2 -10
- data/lib/alpha_omega/deploy.rb +2 -16
- data/libexec/ao +15 -0
- data/libexec/ao-activate +22 -0
- data/libexec/ao-build +22 -0
- data/libexec/ao-check +22 -0
- data/libexec/ao-compare +22 -0
- data/libexec/ao-cook +22 -0
- data/libexec/ao-deploy +22 -0
- data/libexec/ao-dist +22 -0
- data/libexec/ao-lock +31 -0
- data/libexec/ao-migrate +22 -0
- data/libexec/ao-plan +22 -0
- data/libexec/ao-release +22 -0
- data/libexec/ao-restart +22 -0
- data/libexec/ao-rollback +22 -0
- data/libexec/ao-shell +22 -0
- data/libexec/ao-stage +22 -0
- data/libexec/ao-task +23 -0
- data/libexec/ao-unlock +31 -0
- data/sbin/_bump +126 -0
- data/sbin/_jason +172 -0
- data/sbin/_log4sh +3840 -0
- data/sbin/_meat +172 -0
- data/sbin/_prime +8 -0
- data/sbin/_shflags +1012 -0
- data/sbin/_shunit +1048 -0
- data/sbin/_sub +37 -0
- data/sbin/_treadstone +8 -0
- data/sbin/_versions +174 -0
- data/sbin/ao +15 -0
- data/sbin/stub +15 -0
- metadata +31 -57
- data/libexec/activate +0 -199
- data/libexec/build +0 -30
- data/libexec/build.orig +0 -199
- data/libexec/bump.orig +0 -32
- data/libexec/check +0 -199
- data/libexec/compare +0 -199
- data/libexec/config +0 -199
- data/libexec/debug +0 -199
- data/libexec/deploy +0 -199
- data/libexec/dist +0 -199
- data/libexec/dna +0 -199
- data/libexec/hosts +0 -199
- data/libexec/invoke +0 -199
- data/libexec/lock +0 -199
- data/libexec/migrate +0 -199
- data/libexec/plan +0 -199
- data/libexec/release +0 -199
- data/libexec/repl +0 -199
- data/libexec/restart +0 -199
- data/libexec/rollback +0 -199
- data/libexec/shell +0 -199
- data/libexec/stage +0 -199
- data/libexec/task +0 -199
- data/libexec/unlock +0 -199
data/libexec/ao-unlock
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
#/ NAME
|
4
|
+
#/ ao-unlock -- unlock a deploy
|
5
|
+
#/
|
6
|
+
#/ SYNOPSIS
|
7
|
+
#/ ao unlock [deploy_set...]
|
8
|
+
#/ ao unlock migrate|compare [deploy_set...]
|
9
|
+
|
10
|
+
# figure out the project root under which bin, lib live
|
11
|
+
shome="$(cd -P -- "$(dirname -- "$BASH_SOURCE")/.." && pwd -P)"
|
12
|
+
|
13
|
+
# load a jason bourne library
|
14
|
+
source "$shome/sbin/_treadstone"
|
15
|
+
|
16
|
+
# parse the command-line
|
17
|
+
|
18
|
+
# entry point
|
19
|
+
function main {
|
20
|
+
case "${1}" in
|
21
|
+
compare|migrate)
|
22
|
+
nm_lock="${1}"; shift
|
23
|
+
bundle exec cap "$@" "deploy:unlock_${nm_lock}"
|
24
|
+
;;
|
25
|
+
*)
|
26
|
+
bundle exec cap "$@" deploy:unlock
|
27
|
+
;;
|
28
|
+
esac
|
29
|
+
}
|
30
|
+
|
31
|
+
require 'sub' "$BASH_SOURCE" "$@"
|
data/sbin/_bump
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
function bump_version {
|
4
|
+
local dirty="$1"; shift
|
5
|
+
|
6
|
+
if [[ "$dirty" = "$FLAGS_FALSE" ]]; then
|
7
|
+
ensure_clean_git_status
|
8
|
+
fi
|
9
|
+
|
10
|
+
local_file=
|
11
|
+
if [[ -f VERSION || -L VERSION ]]; then
|
12
|
+
local_file=1
|
13
|
+
if [[ ! -e VERSION ]]; then
|
14
|
+
logger_fatal "cannot write to VERSION file"
|
15
|
+
exit 1
|
16
|
+
fi
|
17
|
+
fi
|
18
|
+
|
19
|
+
tmp_version=$(mktemp -t XXXXXXXXX)
|
20
|
+
if [[ -n $local_file ]]; then
|
21
|
+
cat VERSION | perl -ne 'm{^\s*v?(\d+)\.(\d+)\.(\d+)\s*$} && printf("%03d.%03d.%03d %d.%d.%d\n",$1,$2,$3,$1,$2,$3)' | sort -r | head -1 | awk '{print $2}' > $tmp_version
|
22
|
+
else
|
23
|
+
git tag | perl -ne 'm{^v(\d+)\.(\d+)\.(\d+)$} && printf("%03d.%03d.%03d %d.%d.%d\n",$1,$2,$3,$1,$2,$3)' | sort -r | head -1 | awk '{print $2}' > $tmp_version
|
24
|
+
fi
|
25
|
+
|
26
|
+
if [[ ! -s "$tmp_version" ]]; then
|
27
|
+
logger_fatal "need at least one git tag (in the form v0.0.0) or a version in file VERSION (in the form 0.0.0)"
|
28
|
+
exit 1
|
29
|
+
fi
|
30
|
+
|
31
|
+
case "$1" in
|
32
|
+
patch|minor|major)
|
33
|
+
bump=$1; shift
|
34
|
+
set -- $(cat $tmp_version | sed 's#\.# #g')
|
35
|
+
case "$bump" in
|
36
|
+
patch)
|
37
|
+
echo "$1.$2.$(($3 + 1))"
|
38
|
+
;;
|
39
|
+
minor)
|
40
|
+
echo "$1.$(($2 + 1)).0"
|
41
|
+
;;
|
42
|
+
major)
|
43
|
+
echo "$(($1 + 1)).0.0"
|
44
|
+
;;
|
45
|
+
esac > $tmp_version
|
46
|
+
;;
|
47
|
+
*)
|
48
|
+
ver_new=$1; shift
|
49
|
+
ver_new=${ver_new#v}
|
50
|
+
echo $ver_new > $tmp_version
|
51
|
+
;;
|
52
|
+
esac
|
53
|
+
|
54
|
+
ver_new=$(cat $tmp_version)
|
55
|
+
set -- $(echo "$ver_new" | sed 's#\.# #g') 0
|
56
|
+
M=$1; shift
|
57
|
+
m=$1; shift
|
58
|
+
p=$1; shift
|
59
|
+
|
60
|
+
(echo "$(($M+0)).$(($m+0)).$(($p+0))" > $tmp_version) 2>&-
|
61
|
+
ver_new_same=$(cat $tmp_version)
|
62
|
+
|
63
|
+
if [[ $ver_new != $ver_new_same ]]; then
|
64
|
+
logger_fatal "invalid version: $ver_new"
|
65
|
+
exit 1
|
66
|
+
fi
|
67
|
+
|
68
|
+
ver_bumped="v$(cat $tmp_version)"
|
69
|
+
rm -f $tmp_version
|
70
|
+
ensure_git_tag_available $ver_bumped
|
71
|
+
|
72
|
+
if [[ -n $local_file ]]; then
|
73
|
+
echo ${ver_bumped#v} > VERSION
|
74
|
+
git add VERSION
|
75
|
+
if [[ -f Gemfile ]]; then
|
76
|
+
bundle check 2>&1 >/dev/null || { bundle --quiet install --local --path vendor/bundle || bundle check > /dev/null; }
|
77
|
+
git add Gemfile.lock
|
78
|
+
fi
|
79
|
+
|
80
|
+
git commit -m "bump: $ver_bumped"
|
81
|
+
git push
|
82
|
+
fi
|
83
|
+
|
84
|
+
git_tag "$ver_bumped"
|
85
|
+
echo $ver_bumped
|
86
|
+
}
|
87
|
+
|
88
|
+
function ensure_git_tag_available {
|
89
|
+
version=$1; shift
|
90
|
+
git fetch --tags
|
91
|
+
remote_sha=$(git ls-remote origin $version | awk '{print $1}')
|
92
|
+
if [[ -n $remote_sha ]]; then
|
93
|
+
logger_fatal "already a remote tag $version, bump again"
|
94
|
+
exit 1
|
95
|
+
fi
|
96
|
+
|
97
|
+
local_sha=$(git show-ref $version | awk '{print $1}')
|
98
|
+
if [[ -n $local_sha ]]; then
|
99
|
+
logger_fatal "already a local tag $version"
|
100
|
+
exit 1
|
101
|
+
fi
|
102
|
+
}
|
103
|
+
|
104
|
+
function git_tag {
|
105
|
+
local version=$1; shift
|
106
|
+
|
107
|
+
ensure_git_tag_available "$version"
|
108
|
+
|
109
|
+
git tag $version
|
110
|
+
git push origin tag $version
|
111
|
+
remote_sha=$(git ls-remote origin $version | awk '{print $1}')
|
112
|
+
local_sha=$(git show-ref $version | awk '{print $1}')
|
113
|
+
if [[ $remote_sha != $local_sha ]]; then
|
114
|
+
logger_fatal "remote tag $version does not match local SHA"
|
115
|
+
exit 1
|
116
|
+
fi
|
117
|
+
}
|
118
|
+
|
119
|
+
function ensure_clean_git_status {
|
120
|
+
local lines=$(git status -s -uno | wc -l | awk '{print $1}')
|
121
|
+
if [[ $lines != "0" ]]; then
|
122
|
+
logger_fatal "git status is not clean, cannot tag"
|
123
|
+
git status -s -uno
|
124
|
+
exit 1
|
125
|
+
fi
|
126
|
+
}
|
data/sbin/_jason
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
: ${__meat__:=x}
|
4
|
+
if [[ "$__meat__" != 'x' ]]; then
|
5
|
+
return 0
|
6
|
+
fi
|
7
|
+
__meat__='y'
|
8
|
+
|
9
|
+
if [[ -z "${shome:-}" ]]; then
|
10
|
+
shome="$(cd -P -- "$(dirname -- "${BASH_SOURCE}")/.." && pwd -P)"
|
11
|
+
fi
|
12
|
+
|
13
|
+
function get_started {
|
14
|
+
# if getting-started bootstrap is detected, put this in the path
|
15
|
+
# mainly useful for getopt on os x
|
16
|
+
if [[ -d "$HOME/.getting-started/bootstrap" ]]; then
|
17
|
+
PATH="$HOME/.getting-started/bootstrap:$PATH"
|
18
|
+
hash -r
|
19
|
+
fi
|
20
|
+
}
|
21
|
+
|
22
|
+
function check_help {
|
23
|
+
# taken from shocco
|
24
|
+
if expr -- "$*" : ".*--help" >/dev/null; then
|
25
|
+
display_help
|
26
|
+
exit 0
|
27
|
+
fi
|
28
|
+
}
|
29
|
+
|
30
|
+
function display_help {
|
31
|
+
flags_help
|
32
|
+
echo
|
33
|
+
|
34
|
+
# taken from shocco
|
35
|
+
grep '^#/' <"$shome/$(basename $(dirname -- "$0"))/$(basename -- "$0")" | cut -c4-
|
36
|
+
}
|
37
|
+
|
38
|
+
# Exits the script with the last error code. Servers as a marker in $0 to
|
39
|
+
# begin ronn documentation until end of file.
|
40
|
+
function __MAN__ {
|
41
|
+
exit "$!"
|
42
|
+
}
|
43
|
+
|
44
|
+
# Extracts ronn-style Markdown after __MAN__ to stdout. If a line is "MAN", it
|
45
|
+
# is assumed that a here document is used (for syntactical reasons).
|
46
|
+
#
|
47
|
+
# A limitation of detecting "MAN" will truncate the Markdown if "MAN" is a
|
48
|
+
# legimate text.
|
49
|
+
#
|
50
|
+
# __MAN__ << "MAN"
|
51
|
+
# raw ronn-style Markdown
|
52
|
+
# MAN
|
53
|
+
function display_man {
|
54
|
+
awk '/^__MAN__/,/^MAN$/ {print}' <"$shome/sbin/$(basename -- "$0")" | tail -n +2 | egrep -v '^MAN$'
|
55
|
+
}
|
56
|
+
|
57
|
+
function display_synopsis {
|
58
|
+
awk '/^#/ && !/^#!/ { print } /^[^#]/ || /^$/ { exit }' <"$shome/sbin/$(basename -- "$0")" | cut -c3-
|
59
|
+
}
|
60
|
+
|
61
|
+
function which_library {
|
62
|
+
local library="$1"; shift
|
63
|
+
if [[ -r "$shome/sbin/_$library" ]]; then
|
64
|
+
echo "$shome/sbin/_$library"
|
65
|
+
elif [[ -r "$shome/.$library/bin/_profile" ]]; then
|
66
|
+
echo "$shome/.$library/bin/_profile"
|
67
|
+
elif [[ -r "$shome/.$library/.profile" ]]; then
|
68
|
+
echo "$shome/.$library/.profile"
|
69
|
+
else
|
70
|
+
local nm_library="${library%%/*}"
|
71
|
+
if [[ "$nm_library" != "$library" ]]; then
|
72
|
+
local nm_right="${library##*/}"
|
73
|
+
if [[ -r "$shome/.$nm_library/bin/_$nm_right" ]]; then
|
74
|
+
echo "$shome/.$nm_library/bin/_$nm_right"
|
75
|
+
fi
|
76
|
+
fi
|
77
|
+
fi
|
78
|
+
}
|
79
|
+
|
80
|
+
function require {
|
81
|
+
local nm_library="$1"; shift
|
82
|
+
local pth_lib="$(which_library "$nm_library")"
|
83
|
+
if [[ -r "$pth_lib" ]]; then
|
84
|
+
if [[ "$#" == 0 ]]; then
|
85
|
+
set --
|
86
|
+
fi
|
87
|
+
source "$pth_lib" "$@"
|
88
|
+
fi
|
89
|
+
}
|
90
|
+
|
91
|
+
function parse_command_line {
|
92
|
+
if [[ "$FLAGS_SUB" = "$FLAGS_TRUE" && "$@" > 0 ]]; then
|
93
|
+
local argv
|
94
|
+
declare -a argv
|
95
|
+
|
96
|
+
local argc="0"
|
97
|
+
local arg
|
98
|
+
local passthrough=
|
99
|
+
for arg in "$@"; do
|
100
|
+
if [[ -z "$passthrough" && ! "$arg" =~ ^- ]]; then
|
101
|
+
argv[argc]="--"
|
102
|
+
argc="$((argc + 1))"
|
103
|
+
passthrough=1
|
104
|
+
fi
|
105
|
+
|
106
|
+
argv[argc]="$arg"
|
107
|
+
argc="$((argc + 1))"
|
108
|
+
done
|
109
|
+
|
110
|
+
set -- "${argv[@]}"
|
111
|
+
fi
|
112
|
+
|
113
|
+
if ! FLAGS "$@"; then
|
114
|
+
if [[ "$flags_error" = "help requested" ]]; then
|
115
|
+
echo ""
|
116
|
+
display_help
|
117
|
+
exit 0
|
118
|
+
fi
|
119
|
+
|
120
|
+
return 4
|
121
|
+
fi
|
122
|
+
return 0
|
123
|
+
}
|
124
|
+
|
125
|
+
function configure_logging {
|
126
|
+
# load log4sh (disabling properties file warning) and clear the default
|
127
|
+
# configuration
|
128
|
+
LOG4SH_CONFIGURATION='none' require 'log4sh'
|
129
|
+
log4sh_resetConfiguration
|
130
|
+
|
131
|
+
# set the global logging level to INFO
|
132
|
+
logger_setLevel INFO
|
133
|
+
|
134
|
+
# add and configure a FileAppender that outputs to STDERR, and activate the
|
135
|
+
# configuration
|
136
|
+
logger_addAppender stderr
|
137
|
+
appender_setType stderr FileAppender
|
138
|
+
appender_file_setFile stderr STDERR
|
139
|
+
appender_activateOptions stderr
|
140
|
+
}
|
141
|
+
|
142
|
+
function ryaml {
|
143
|
+
ruby -ryaml -e 'def ps x; unless x.nil?; puts x; end; end; ps ARGV[1..-1].inject(YAML.load(File.read(ARGV[0]))) {|acc, key| acc[key] }' "$@" 2>&-
|
144
|
+
}
|
145
|
+
|
146
|
+
function random_str {
|
147
|
+
echo "$(date +%s).$$.$RANDOM"
|
148
|
+
}
|
149
|
+
|
150
|
+
function runmany {
|
151
|
+
local cpu="$1"; shift
|
152
|
+
local args="$1"; shift
|
153
|
+
if [[ "$#" = 0 ]]; then
|
154
|
+
cat
|
155
|
+
else
|
156
|
+
echo "$@"
|
157
|
+
fi | xargs -P $cpu -n $args -- bash -c "$*" ""
|
158
|
+
}
|
159
|
+
|
160
|
+
function _main {
|
161
|
+
if [[ -z "$shome" ]]; then
|
162
|
+
shome="$(cd -P -- "$(dirname -- "${BASH_SOURCE}")/.." && pwd -P)"
|
163
|
+
fi
|
164
|
+
|
165
|
+
require 'shflags'
|
166
|
+
|
167
|
+
configure_logging
|
168
|
+
|
169
|
+
PATH="$shome/sbin:$PATH"
|
170
|
+
}
|
171
|
+
|
172
|
+
_main "$@"
|
data/sbin/_log4sh
ADDED
@@ -0,0 +1,3840 @@
|
|
1
|
+
# $Id: log4sh 574 2007-06-02 20:09:15Z sfsetse $
|
2
|
+
# vim:syntax=sh:sts=2
|
3
|
+
# vim:foldmethod=marker:foldmarker=/**,*/
|
4
|
+
#
|
5
|
+
#/**
|
6
|
+
# <?xml version="1.0" encoding="UTF-8"?>
|
7
|
+
# <s:shelldoc xmlns:s="http://www.forestent.com/2005/XSL/ShellDoc">
|
8
|
+
# <s:header>
|
9
|
+
# log4sh 1.4.2
|
10
|
+
#
|
11
|
+
# http://log4sh.sourceforge.net/
|
12
|
+
#
|
13
|
+
# written by Kate Ward <kate.ward@forestent.com>
|
14
|
+
# released under the LGPL
|
15
|
+
#
|
16
|
+
# this module implements something like the log4j module from the Apache group
|
17
|
+
#
|
18
|
+
# notes:
|
19
|
+
# *) the default appender is a ConsoleAppender named stdout with a level
|
20
|
+
# of ERROR and layout of SimpleLayout
|
21
|
+
# *) the appender levels are as follows (decreasing order of output):
|
22
|
+
# TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF
|
23
|
+
# </s:header>
|
24
|
+
#*/
|
25
|
+
|
26
|
+
# shell flags for log4sh:
|
27
|
+
# u - treat unset variables as an error when performing parameter expansion
|
28
|
+
__LOG4SH_SHELL_FLAGS='u'
|
29
|
+
|
30
|
+
# save the current set of shell flags, and then set some for log4sh
|
31
|
+
__log4sh_oldShellFlags=$-
|
32
|
+
for _log4sh_shellFlag in `echo "${__LOG4SH_SHELL_FLAGS}" |sed 's/\(.\)/\1 /g'`
|
33
|
+
do
|
34
|
+
set -${_log4sh_shellFlag}
|
35
|
+
done
|
36
|
+
|
37
|
+
#
|
38
|
+
# constants
|
39
|
+
#
|
40
|
+
__LOG4SH_VERSION='1.4.2'
|
41
|
+
|
42
|
+
__LOG4SH_TRUE=0
|
43
|
+
__LOG4SH_FALSE=1
|
44
|
+
__LOG4SH_ERROR=2
|
45
|
+
__LOG4SH_NULL='~'
|
46
|
+
|
47
|
+
__LOG4SH_APPENDER_FUNC_PREFIX='_log4sh_app_'
|
48
|
+
__LOG4SH_APPENDER_INCLUDE_EXT='.inc'
|
49
|
+
|
50
|
+
__LOG4SH_TYPE_CONSOLE='ConsoleAppender'
|
51
|
+
__LOG4SH_TYPE_DAILY_ROLLING_FILE='DailyRollingFileAppender'
|
52
|
+
__LOG4SH_TYPE_FILE='FileAppender'
|
53
|
+
__LOG4SH_TYPE_ROLLING_FILE='RollingFileAppender'
|
54
|
+
__LOG4SH_TYPE_ROLLING_FILE_MAX_BACKUP_INDEX=1
|
55
|
+
__LOG4SH_TYPE_ROLLING_FILE_MAX_FILE_SIZE=10485760
|
56
|
+
__LOG4SH_TYPE_SMTP='SMTPAppender'
|
57
|
+
__LOG4SH_TYPE_SYSLOG='SyslogAppender'
|
58
|
+
__LOG4SH_TYPE_SYSLOG_FACILITY_NAMES=' kern user mail daemon auth security syslog lpr news uucp cron authpriv ftp local0 local1 local2 local3 local4 local5 local6 local7 '
|
59
|
+
__LOG4SH_TYPE_SYSLOG_FACILITY='user'
|
60
|
+
|
61
|
+
__LOG4SH_LAYOUT_HTML='HTMLLayout'
|
62
|
+
__LOG4SH_LAYOUT_SIMPLE='SimpleLayout'
|
63
|
+
__LOG4SH_LAYOUT_PATTERN='PatternLayout'
|
64
|
+
|
65
|
+
__LOG4SH_LEVEL_TRACE=0
|
66
|
+
__LOG4SH_LEVEL_TRACE_STR='TRACE'
|
67
|
+
__LOG4SH_LEVEL_DEBUG=1
|
68
|
+
__LOG4SH_LEVEL_DEBUG_STR='DEBUG'
|
69
|
+
__LOG4SH_LEVEL_INFO=2
|
70
|
+
__LOG4SH_LEVEL_INFO_STR='INFO'
|
71
|
+
__LOG4SH_LEVEL_WARN=3
|
72
|
+
__LOG4SH_LEVEL_WARN_STR='WARN'
|
73
|
+
__LOG4SH_LEVEL_ERROR=4
|
74
|
+
__LOG4SH_LEVEL_ERROR_STR='ERROR'
|
75
|
+
__LOG4SH_LEVEL_FATAL=5
|
76
|
+
__LOG4SH_LEVEL_FATAL_STR='FATAL'
|
77
|
+
__LOG4SH_LEVEL_OFF=6
|
78
|
+
__LOG4SH_LEVEL_OFF_STR='OFF'
|
79
|
+
__LOG4SH_LEVEL_CLOSED=255
|
80
|
+
__LOG4SH_LEVEL_CLOSED_STR='CLOSED'
|
81
|
+
|
82
|
+
__LOG4SH_PATTERN_DEFAULT='%d %p - %m%n'
|
83
|
+
__LOG4SH_THREAD_DEFAULT='main'
|
84
|
+
|
85
|
+
__LOG4SH_CONFIGURATION="${LOG4SH_CONFIGURATION:-log4sh.properties}"
|
86
|
+
__LOG4SH_CONFIG_PREFIX="${LOG4SH_CONFIG_PREFIX:-log4sh}"
|
87
|
+
__LOG4SH_CONFIG_LOG4J_CP='org.apache.log4j'
|
88
|
+
|
89
|
+
# the following IFS is *supposed* to be on two lines!!
|
90
|
+
__LOG4SH_IFS_ARRAY="
|
91
|
+
"
|
92
|
+
__LOG4SH_IFS_DEFAULT=' '
|
93
|
+
|
94
|
+
__LOG4SH_SECONDS=`eval "expr \`date '+%H \* 3600 + %M \* 60 + %S'\`"`
|
95
|
+
|
96
|
+
# configure log4sh debugging. set the LOG4SH_INFO environment variable to any
|
97
|
+
# non-empty value to enable info output, LOG4SH_DEBUG enable debug output, or
|
98
|
+
# LOG4SH_TRACE to enable trace output. log4sh ERROR and above messages are
|
99
|
+
# always printed. to send the debug output to a file, set the LOG4SH_DEBUG_FILE
|
100
|
+
# with the filename you want debug output to be written to.
|
101
|
+
__LOG4SH_TRACE=${LOG4SH_TRACE:+'_log4sh_trace '}
|
102
|
+
__LOG4SH_TRACE=${__LOG4SH_TRACE:-':'}
|
103
|
+
[ -n "${LOG4SH_TRACE:-}" ] && LOG4SH_DEBUG=1
|
104
|
+
__LOG4SH_DEBUG=${LOG4SH_DEBUG:+'_log4sh_debug '}
|
105
|
+
__LOG4SH_DEBUG=${__LOG4SH_DEBUG:-':'}
|
106
|
+
[ -n "${LOG4SH_DEBUG:-}" ] && LOG4SH_INFO=1
|
107
|
+
__LOG4SH_INFO=${LOG4SH_INFO:+'_log4sh_info '}
|
108
|
+
__LOG4SH_INFO=${__LOG4SH_INFO:-':'}
|
109
|
+
|
110
|
+
# set the constants to readonly
|
111
|
+
for _log4sh_const in `set |grep "^__LOG4SH_" |cut -d= -f1`; do
|
112
|
+
readonly ${_log4sh_const}
|
113
|
+
done
|
114
|
+
unset _log4sh_const
|
115
|
+
|
116
|
+
#
|
117
|
+
# internal variables
|
118
|
+
#
|
119
|
+
|
120
|
+
__log4sh_filename=`basename -- $0`
|
121
|
+
__log4sh_tmpDir=''
|
122
|
+
__log4sh_trapsFile=''
|
123
|
+
|
124
|
+
__log4sh_alternative_mail='mail'
|
125
|
+
|
126
|
+
__log4sh_threadName=${__LOG4SH_THREAD_DEFAULT}
|
127
|
+
__log4sh_threadStack=${__LOG4SH_THREAD_DEFAULT}
|
128
|
+
|
129
|
+
__log4sh_seconds=0
|
130
|
+
__log4sh_secondsLast=0
|
131
|
+
__log4sh_secondsWrap=0
|
132
|
+
|
133
|
+
# workarounds for various commands
|
134
|
+
__log4sh_wa_strictBehavior=${__LOG4SH_FALSE}
|
135
|
+
(
|
136
|
+
# determine if the set builtin needs to be evaluated. if the string is parsed
|
137
|
+
# into two separate strings (common in ksh), then set needs to be evaled.
|
138
|
+
str='x{1,2}'
|
139
|
+
set -- ${str}
|
140
|
+
test ! "$1" = 'x1' -a ! "${2:-}" = 'x2'
|
141
|
+
)
|
142
|
+
__log4sh_wa_setNeedsEval=$?
|
143
|
+
|
144
|
+
|
145
|
+
#=============================================================================
|
146
|
+
# Log4sh
|
147
|
+
#
|
148
|
+
|
149
|
+
#-----------------------------------------------------------------------------
|
150
|
+
# internal debugging
|
151
|
+
#
|
152
|
+
|
153
|
+
#/**
|
154
|
+
# <s:function group="Log4sh" modifier="private">
|
155
|
+
# <entry align="right">
|
156
|
+
# <emphasis>void</emphasis>
|
157
|
+
# </entry>
|
158
|
+
# <entry>
|
159
|
+
# <funcsynopsis>
|
160
|
+
# <funcprototype>
|
161
|
+
# <funcdef><function>_log4sh_log</function></funcdef>
|
162
|
+
# <paramdef>string <parameter>level</parameter></paramdef>
|
163
|
+
# </funcprototype>
|
164
|
+
# </funcsynopsis>
|
165
|
+
# <para>
|
166
|
+
# This is an internal debugging function. It should not be called.
|
167
|
+
# </para>
|
168
|
+
# <funcsynopsis>
|
169
|
+
# <funcsynopsisinfo>_log4sh_log</funcsynopsisinfo>
|
170
|
+
# </funcsynopsis>
|
171
|
+
# </entry>
|
172
|
+
# </s:function>
|
173
|
+
#*/
|
174
|
+
_log4sh_log()
|
175
|
+
{
|
176
|
+
_ll__level=$1
|
177
|
+
shift
|
178
|
+
if [ -z "${LOG4SH_DEBUG_FILE:-}" ]; then
|
179
|
+
echo "log4sh:${_ll__level} $@" >&2
|
180
|
+
else
|
181
|
+
echo "${_ll__level} $@" >>${LOG4SH_DEBUG_FILE}
|
182
|
+
fi
|
183
|
+
unset _ll__level
|
184
|
+
}
|
185
|
+
|
186
|
+
#/**
|
187
|
+
# <s:function group="Log4sh" modifier="private">
|
188
|
+
# <entry align="right">
|
189
|
+
# <emphasis>void</emphasis>
|
190
|
+
# </entry>
|
191
|
+
# <entry>
|
192
|
+
# <funcsynopsis>
|
193
|
+
# <funcprototype>
|
194
|
+
# <funcdef><function>_log4sh_trace</function></funcdef>
|
195
|
+
# <paramdef>string <parameter>level</parameter></paramdef>
|
196
|
+
# </funcprototype>
|
197
|
+
# </funcsynopsis>
|
198
|
+
# <para>
|
199
|
+
# This is an internal debugging function. It should not be called.
|
200
|
+
# </para>
|
201
|
+
# <funcsynopsis>
|
202
|
+
# <funcsynopsisinfo>_log4sh_log</funcsynopsisinfo>
|
203
|
+
# </funcsynopsis>
|
204
|
+
# </entry>
|
205
|
+
# </s:function>
|
206
|
+
#*/
|
207
|
+
_log4sh_trace()
|
208
|
+
{
|
209
|
+
_log4sh_log "${__LOG4SH_LEVEL_TRACE_STR}" "${BASH_LINENO:+(${BASH_LINENO}) }- $@";
|
210
|
+
}
|
211
|
+
|
212
|
+
#/**
|
213
|
+
# <s:function group="Log4sh" modifier="private">
|
214
|
+
# <entry align="right">
|
215
|
+
# <emphasis>void</emphasis>
|
216
|
+
# </entry>
|
217
|
+
# <entry>
|
218
|
+
# <funcsynopsis>
|
219
|
+
# <funcprototype>
|
220
|
+
# <funcdef><function>_log4sh_debug</function></funcdef>
|
221
|
+
# <paramdef>string <parameter>level</parameter></paramdef>
|
222
|
+
# </funcprototype>
|
223
|
+
# </funcsynopsis>
|
224
|
+
# <para>
|
225
|
+
# This is an internal debugging function. It should not be called.
|
226
|
+
# </para>
|
227
|
+
# <funcsynopsis>
|
228
|
+
# <funcsynopsisinfo>_log4sh_log</funcsynopsisinfo>
|
229
|
+
# </funcsynopsis>
|
230
|
+
# </entry>
|
231
|
+
# </s:function>
|
232
|
+
#*/
|
233
|
+
_log4sh_debug()
|
234
|
+
{
|
235
|
+
_log4sh_log "${__LOG4SH_LEVEL_DEBUG_STR}" "${BASH_LINENO:+(${BASH_LINENO}) }- $@";
|
236
|
+
}
|
237
|
+
|
238
|
+
#/**
|
239
|
+
# <s:function group="Log4sh" modifier="private">
|
240
|
+
# <entry align="right">
|
241
|
+
# <emphasis>void</emphasis>
|
242
|
+
# </entry>
|
243
|
+
# <entry>
|
244
|
+
# <funcsynopsis>
|
245
|
+
# <funcprototype>
|
246
|
+
# <funcdef><function>_log4sh_info</function></funcdef>
|
247
|
+
# <paramdef>string <parameter>level</parameter></paramdef>
|
248
|
+
# </funcprototype>
|
249
|
+
# </funcsynopsis>
|
250
|
+
# <para>
|
251
|
+
# This is an internal debugging function. It should not be called.
|
252
|
+
# </para>
|
253
|
+
# <funcsynopsis>
|
254
|
+
# <funcsynopsisinfo>_log4sh_log</funcsynopsisinfo>
|
255
|
+
# </funcsynopsis>
|
256
|
+
# </entry>
|
257
|
+
# </s:function>
|
258
|
+
#*/
|
259
|
+
_log4sh_info()
|
260
|
+
{
|
261
|
+
_log4sh_log "${__LOG4SH_LEVEL_INFO_STR}" "${BASH_LINENO:+(${BASH_LINENO}) }- $@";
|
262
|
+
}
|
263
|
+
|
264
|
+
#/**
|
265
|
+
# <s:function group="Log4sh" modifier="private">
|
266
|
+
# <entry align="right">
|
267
|
+
# <emphasis>void</emphasis>
|
268
|
+
# </entry>
|
269
|
+
# <entry>
|
270
|
+
# <funcsynopsis>
|
271
|
+
# <funcprototype>
|
272
|
+
# <funcdef><function>_log4sh_warn</function></funcdef>
|
273
|
+
# <paramdef>string <parameter>level</parameter></paramdef>
|
274
|
+
# </funcprototype>
|
275
|
+
# </funcsynopsis>
|
276
|
+
# <para>
|
277
|
+
# This is an internal debugging function. It should not be called.
|
278
|
+
# </para>
|
279
|
+
# <funcsynopsis>
|
280
|
+
# <funcsynopsisinfo>_log4sh_log</funcsynopsisinfo>
|
281
|
+
# </funcsynopsis>
|
282
|
+
# </entry>
|
283
|
+
# </s:function>
|
284
|
+
#*/
|
285
|
+
_log4sh_warn()
|
286
|
+
{
|
287
|
+
echo "log4sh:${__LOG4SH_LEVEL_WARN_STR} $@" >&2
|
288
|
+
[ -n "${LOG4SH_DEBUG_FILE:-}" ] \
|
289
|
+
&& _log4sh_log "${__LOG4SH_LEVEL_WARN_STR}" "$@"
|
290
|
+
}
|
291
|
+
|
292
|
+
#/**
|
293
|
+
# <s:function group="Log4sh" modifier="private">
|
294
|
+
# <entry align="right">
|
295
|
+
# <emphasis>void</emphasis>
|
296
|
+
# </entry>
|
297
|
+
# <entry>
|
298
|
+
# <funcsynopsis>
|
299
|
+
# <funcprototype>
|
300
|
+
# <funcdef><function>_log4sh_error</function></funcdef>
|
301
|
+
# <paramdef>string <parameter>level</parameter></paramdef>
|
302
|
+
# </funcprototype>
|
303
|
+
# </funcsynopsis>
|
304
|
+
# <para>
|
305
|
+
# This is an internal debugging function. It should not be called.
|
306
|
+
# </para>
|
307
|
+
# <funcsynopsis>
|
308
|
+
# <funcsynopsisinfo>_log4sh_log</funcsynopsisinfo>
|
309
|
+
# </funcsynopsis>
|
310
|
+
# </entry>
|
311
|
+
# </s:function>
|
312
|
+
#*/
|
313
|
+
_log4sh_error()
|
314
|
+
{
|
315
|
+
echo "log4sh:${__LOG4SH_LEVEL_ERROR_STR} $@" >&2
|
316
|
+
[ -n "${LOG4SH_DEBUG_FILE:-}" ] \
|
317
|
+
&& _log4sh_log "${__LOG4SH_LEVEL_ERROR_STR}" "$@"
|
318
|
+
}
|
319
|
+
|
320
|
+
#/**
|
321
|
+
# <s:function group="Log4sh" modifier="private">
|
322
|
+
# <entry align="right">
|
323
|
+
# <emphasis>void</emphasis>
|
324
|
+
# </entry>
|
325
|
+
# <entry>
|
326
|
+
# <funcsynopsis>
|
327
|
+
# <funcprototype>
|
328
|
+
# <funcdef><function>_log4sh_fatal</function></funcdef>
|
329
|
+
# <paramdef>string <parameter>level</parameter></paramdef>
|
330
|
+
# </funcprototype>
|
331
|
+
# </funcsynopsis>
|
332
|
+
# <para>
|
333
|
+
# This is an internal debugging function. It should not be called.
|
334
|
+
# </para>
|
335
|
+
# <funcsynopsis>
|
336
|
+
# <funcsynopsisinfo>_log4sh_log</funcsynopsisinfo>
|
337
|
+
# </funcsynopsis>
|
338
|
+
# </entry>
|
339
|
+
# </s:function>
|
340
|
+
#*/
|
341
|
+
_log4sh_fatal()
|
342
|
+
{
|
343
|
+
echo "log4sh:${__LOG4SH_LEVEL_FATAL_STR} $@" >&2
|
344
|
+
[ -n "${LOG4SH_DEBUG_FILE:-}" ] \
|
345
|
+
&& _log4sh_log "${__LOG4SH_LEVEL_FATAL_STR}" "$@"
|
346
|
+
}
|
347
|
+
|
348
|
+
#-----------------------------------------------------------------------------
|
349
|
+
# miscellaneous
|
350
|
+
#
|
351
|
+
|
352
|
+
#/**
|
353
|
+
# <s:function group="Log4sh" modifier="private">
|
354
|
+
# <entry align="right">
|
355
|
+
# <code>string</code>
|
356
|
+
# </entry>
|
357
|
+
# <entry>
|
358
|
+
# <funcsynopsis>
|
359
|
+
# <funcprototype>
|
360
|
+
# <funcdef><function>_log4sh_mktempDir</function></funcdef>
|
361
|
+
# <void />
|
362
|
+
# </funcprototype>
|
363
|
+
# </funcsynopsis>
|
364
|
+
# <para>
|
365
|
+
# Creates a secure temporary directory within which temporary files can be
|
366
|
+
# created. Honors the <code>TMPDIR</code> environment variable if it is
|
367
|
+
# set.
|
368
|
+
# </para>
|
369
|
+
# <funcsynopsis>
|
370
|
+
# <funcsynopsisinfo>tmpDir=`_log4sh_mktempDir`</funcsynopsisinfo>
|
371
|
+
# </funcsynopsis>
|
372
|
+
# </entry>
|
373
|
+
# </s:function>
|
374
|
+
#*/
|
375
|
+
_log4sh_mktempDir()
|
376
|
+
{
|
377
|
+
_lmd_tmpPrefix='log4sh'
|
378
|
+
|
379
|
+
# try the standard mktemp function
|
380
|
+
( exec mktemp -dqt ${_lmd_tmpPrefix}.XXXXXX 2>/dev/null ) && return
|
381
|
+
|
382
|
+
# the standard mktemp didn't work. doing our own.
|
383
|
+
if [ -n "${RANDOM:-}" ]; then
|
384
|
+
# $RANDOM works
|
385
|
+
_lmd_random=${RANDOM}${RANDOM}${RANDOM}$$
|
386
|
+
elif [ -r '/dev/urandom' ]; then
|
387
|
+
_lmd_random=`od -vAn -N4 -tu4 </dev/urandom |sed 's/^[^0-9]*//'`
|
388
|
+
else
|
389
|
+
# $RANDOM doesn't work
|
390
|
+
_lmd_date=`date '+%Y%m%d%H%M%S'`
|
391
|
+
_lmd_random=`expr ${_lmd_date} / $$`
|
392
|
+
unset _lmd_date
|
393
|
+
fi
|
394
|
+
|
395
|
+
_lmd_tmpDir="${TMPDIR:-/tmp}/${_lmd_tmpPrefix}.${_lmd_random}"
|
396
|
+
( umask 077 && mkdir "${_lmd_tmpDir}" ) || {
|
397
|
+
_log4sh_fatal 'could not create temporary directory! exiting'
|
398
|
+
exit 1
|
399
|
+
}
|
400
|
+
|
401
|
+
${__LOG4SH_DEBUG} "created temporary directory (${_lmd_tmpDir})"
|
402
|
+
echo "${_lmd_tmpDir}"
|
403
|
+
unset _lmd_random _lmd_tmpDir _lmd_tmpPrefix
|
404
|
+
}
|
405
|
+
|
406
|
+
#/**
|
407
|
+
# <s:function group="Log4sh" modifier="private">
|
408
|
+
# <entry align="right">
|
409
|
+
# <emphasis>void</emphasis>
|
410
|
+
# </entry>
|
411
|
+
# <entry>
|
412
|
+
# <funcsynopsis>
|
413
|
+
# <funcprototype>
|
414
|
+
# <funcdef><function>_log4sh_updateSeconds</function></funcdef>
|
415
|
+
# <void />
|
416
|
+
# </funcprototype>
|
417
|
+
# </funcsynopsis>
|
418
|
+
# <para>
|
419
|
+
# Set the <code>__log4sh_seconds</code> variable to the number of seconds
|
420
|
+
# elapsed since the start of the script.
|
421
|
+
# </para>
|
422
|
+
# <funcsynopsis>
|
423
|
+
# <funcsynopsisinfo>_log4sh_updateSeconds`</funcsynopsisinfo>
|
424
|
+
# </funcsynopsis>
|
425
|
+
# </entry>
|
426
|
+
# </s:function>
|
427
|
+
#*/
|
428
|
+
_log4sh_updateSeconds()
|
429
|
+
{
|
430
|
+
if [ -n "${SECONDS:-}" ]; then
|
431
|
+
__log4sh_seconds=${SECONDS}
|
432
|
+
else
|
433
|
+
_lgs__date=`date '+%H \* 3600 + %M \* 60 + %S'`
|
434
|
+
_lgs__seconds=`eval "expr ${_lgs__date} + ${__log4sh_secondsWrap} \* 86400"`
|
435
|
+
if [ ${_lgs__seconds} -lt ${__log4sh_secondsLast} ]; then
|
436
|
+
__log4sh_secondsWrap=`expr ${__log4sh_secondsWrap} + 1`
|
437
|
+
_lgs__seconds=`expr ${_lgs_seconds} + 86400`
|
438
|
+
fi
|
439
|
+
__log4sh_seconds=`expr ${_lgs__seconds} - ${__LOG4SH_SECONDS}`
|
440
|
+
__log4sh_secondsLast=${__log4sh_seconds}
|
441
|
+
unset _lgs__date _lgs__seconds
|
442
|
+
fi
|
443
|
+
}
|
444
|
+
|
445
|
+
#/**
|
446
|
+
# <s:function group="Log4sh" modifier="public">
|
447
|
+
# <entry align="right">
|
448
|
+
# <emphasis>void</emphasis>/boolean
|
449
|
+
# </entry>
|
450
|
+
# <entry>
|
451
|
+
# <funcsynopsis>
|
452
|
+
# <funcprototype>
|
453
|
+
# <funcdef><function>log4sh_enableStrictBehavior</function></funcdef>
|
454
|
+
# <void />
|
455
|
+
# </funcprototype>
|
456
|
+
# </funcsynopsis>
|
457
|
+
# <para>
|
458
|
+
# Enables strict log4j behavior.
|
459
|
+
# </para>
|
460
|
+
# <para><emphasis role="strong">Since:</emphasis> 1.3.7</para>
|
461
|
+
# <funcsynopsis>
|
462
|
+
# <funcsynopsisinfo>log4sh_enableStrictBehavior</funcsynopsisinfo>
|
463
|
+
# </funcsynopsis>
|
464
|
+
# </entry>
|
465
|
+
# </s:function>
|
466
|
+
#*/
|
467
|
+
log4sh_enableStrictBehavior()
|
468
|
+
{
|
469
|
+
__log4sh_wa_strictBehavior=${__LOG4SH_TRUE}
|
470
|
+
}
|
471
|
+
|
472
|
+
#/**
|
473
|
+
# <s:function group="Log4sh" modifier="public">
|
474
|
+
# <entry align="right">
|
475
|
+
# <emphasis>void</emphasis>/boolean
|
476
|
+
# </entry>
|
477
|
+
# <entry>
|
478
|
+
# <funcsynopsis>
|
479
|
+
# <funcprototype>
|
480
|
+
# <funcdef><function>log4sh_setAlternative</function></funcdef>
|
481
|
+
# <paramdef>string <parameter>command</parameter></paramdef>
|
482
|
+
# <paramdef>string <parameter>path</parameter></paramdef>
|
483
|
+
# <paramdef>boolean <parameter>useRuntimePath</parameter> (optional)</paramdef>
|
484
|
+
# </funcprototype>
|
485
|
+
# </funcsynopsis>
|
486
|
+
# <para>
|
487
|
+
# Specifies an alternative path for a command.
|
488
|
+
# </para>
|
489
|
+
# <para><emphasis role="strong">Since:</emphasis> 1.3.7</para>
|
490
|
+
# <funcsynopsis>
|
491
|
+
# <funcsynopsisinfo>log4sh_setAlternative nc /bin/nc</funcsynopsisinfo>
|
492
|
+
# </funcsynopsis>
|
493
|
+
# </entry>
|
494
|
+
# </s:function>
|
495
|
+
#*/
|
496
|
+
log4sh_setAlternative()
|
497
|
+
{
|
498
|
+
if [ $# -lt 2 ]; then
|
499
|
+
_log4sh_error 'log4sh_setAlternative(): invalid number of parameters'
|
500
|
+
return ${__LOG4SH_FALSE}
|
501
|
+
fi
|
502
|
+
|
503
|
+
lsa_cmdName=$1
|
504
|
+
lsa_cmdPath=$2
|
505
|
+
lsa_useRuntimePath=${3:-}
|
506
|
+
__log4sh_return=${__LOG4SH_TRUE}
|
507
|
+
|
508
|
+
# check that the alternative command exists and is executable
|
509
|
+
if [ \
|
510
|
+
! -x "${lsa_cmdPath}" \
|
511
|
+
-a ${lsa_useRuntimePath:-${__LOG4SH_FALSE}} -eq ${__LOG4SH_FALSE} \
|
512
|
+
]; then
|
513
|
+
# the alternative command is not executable
|
514
|
+
_log4sh_error "log4sh_setAlternative(): ${lsa_cmdName}: command not found"
|
515
|
+
__log4sh_return=${__LOG4SH_ERROR}
|
516
|
+
fi
|
517
|
+
|
518
|
+
# check for valid alternative
|
519
|
+
if [ ${__log4sh_return} -eq ${__LOG4SH_TRUE} ]; then
|
520
|
+
case ${lsa_cmdName} in
|
521
|
+
mail) ;;
|
522
|
+
nc)
|
523
|
+
lsa_cmdVers=`${lsa_cmdPath} --version 2>&1 |head -1`
|
524
|
+
if echo "${lsa_cmdVers}" |grep '^netcat' >/dev/null; then
|
525
|
+
# GNU Netcat
|
526
|
+
__log4sh_alternative_nc_opts='-c'
|
527
|
+
else
|
528
|
+
# older netcat (v1.10)
|
529
|
+
if nc -q 0 2>&1 |grep '^no destination$' >/dev/null 2>&1; then
|
530
|
+
# supports -q option
|
531
|
+
__log4sh_alternative_nc_opts='-q 0'
|
532
|
+
else
|
533
|
+
# doesn't support the -q option
|
534
|
+
__log4sh_alternative_nc_opts=''
|
535
|
+
fi
|
536
|
+
fi
|
537
|
+
unset lsa_cmdVers
|
538
|
+
;;
|
539
|
+
*)
|
540
|
+
# the alternative is not valid
|
541
|
+
_log4sh_error "unrecognized command alternative '${lsa_cmdName}'"
|
542
|
+
__log4sh_return=${__LOG4SH_FALSE}
|
543
|
+
;;
|
544
|
+
esac
|
545
|
+
fi
|
546
|
+
|
547
|
+
# set the alternative
|
548
|
+
if [ ${__log4sh_return} -eq ${__LOG4SH_TRUE} ]; then
|
549
|
+
eval __log4sh_alternative_${lsa_cmdName}="\${lsa_cmdPath}"
|
550
|
+
${__LOG4SH_DEBUG} "alternative '${lsa_cmdName}' command set to '${lsa_cmdPath}'"
|
551
|
+
fi
|
552
|
+
|
553
|
+
unset lsa_cmdName lsa_cmdPath
|
554
|
+
return ${__log4sh_return}
|
555
|
+
}
|
556
|
+
|
557
|
+
#-----------------------------------------------------------------------------
|
558
|
+
# array handling
|
559
|
+
#
|
560
|
+
# note: arrays are '1' based
|
561
|
+
#
|
562
|
+
|
563
|
+
#/**
|
564
|
+
# <s:function group="Log4sh" modifier="private">
|
565
|
+
# <entry align="right">
|
566
|
+
# <code>integer</code>
|
567
|
+
# </entry>
|
568
|
+
# <entry>
|
569
|
+
# <funcsynopsis>
|
570
|
+
# <funcprototype>
|
571
|
+
# <funcdef><function>_log4sh_findArrayElement</function></funcdef>
|
572
|
+
# <paramdef>string[] <parameter>array</parameter></paramdef>
|
573
|
+
# <paramdef>string <parameter>element</parameter></paramdef>
|
574
|
+
# </funcprototype>
|
575
|
+
# </funcsynopsis>
|
576
|
+
# <para>Find the position of element in an array</para>
|
577
|
+
# <funcsynopsis>
|
578
|
+
# <funcsynopsisinfo>
|
579
|
+
# pos=`_log4sh_findArrayElement "$array" $element`
|
580
|
+
# </funcsynopsisinfo>
|
581
|
+
# </funcsynopsis>
|
582
|
+
# </entry>
|
583
|
+
# </s:function>
|
584
|
+
#*/
|
585
|
+
_log4sh_findArrayElement()
|
586
|
+
{
|
587
|
+
__pos=`echo "$1" |awk '$0==e{print NR}' e="$2"`
|
588
|
+
[ -n "${__pos}" ] && echo "${__pos}" || echo 0
|
589
|
+
unset __pos
|
590
|
+
}
|
591
|
+
|
592
|
+
#/**
|
593
|
+
# <s:function group="Log4sh" modifier="private">
|
594
|
+
# <entry align="right">
|
595
|
+
# <code>string</code>
|
596
|
+
# </entry>
|
597
|
+
# <entry>
|
598
|
+
# <funcsynopsis>
|
599
|
+
# <funcprototype>
|
600
|
+
# <funcdef><function>_log4sh_getArrayElement</function></funcdef>
|
601
|
+
# <paramdef>string[] <parameter>array</parameter></paramdef>
|
602
|
+
# <paramdef>integer <parameter>position</parameter></paramdef>
|
603
|
+
# </funcprototype>
|
604
|
+
# </funcsynopsis>
|
605
|
+
# <para>Retrieve the element at the given position from an array</para>
|
606
|
+
# <funcsynopsis>
|
607
|
+
# <funcsynopsisinfo>element=`_log4sh_getArrayElement "$array" $position`</funcsynopsisinfo>
|
608
|
+
# </funcsynopsis>
|
609
|
+
# </entry>
|
610
|
+
# </s:function>
|
611
|
+
#*/
|
612
|
+
_log4sh_getArrayElement()
|
613
|
+
{
|
614
|
+
[ -n "${FUNCNAME:-}" ] && ${__LOG4SH_TRACE} "${FUNCNAME}()${BASH_LINENO:+'(called from ${BASH_LINENO})'}"
|
615
|
+
_lgae_array=$1
|
616
|
+
_lgae_index=$2
|
617
|
+
${__LOG4SH_TRACE} "_lgae_array='${_lgae_array}' _lgae_index='${_lgae_index}'"
|
618
|
+
|
619
|
+
_lgae_oldIFS=${IFS} IFS=${__LOG4SH_IFS_ARRAY}
|
620
|
+
if [ ${__log4sh_wa_setNeedsEval} -eq 0 ]; then
|
621
|
+
set -- junk ${_lgae_array}
|
622
|
+
else
|
623
|
+
eval "set -- junk \"${_lgae_array}\""
|
624
|
+
_lgae_arraySize=$#
|
625
|
+
|
626
|
+
if [ ${_lgae_arraySize} -le ${__log4shAppenderCount} ]; then
|
627
|
+
# the evaled set *didn't* work; failing back to original set command and
|
628
|
+
# disabling the work around. (pdksh)
|
629
|
+
__log4sh_wa_setNeedsEval=${__LOG4SH_FALSE}
|
630
|
+
set -- junk ${_lgae_array}
|
631
|
+
fi
|
632
|
+
fi
|
633
|
+
IFS=${_lgae_oldIFS}
|
634
|
+
|
635
|
+
shift ${_lgae_index}
|
636
|
+
${__LOG4SH_TRACE} "1='${1:-}' 2='${2:-}' 3='${3:-}' ..."
|
637
|
+
echo "$1"
|
638
|
+
|
639
|
+
unset _lgae_array _lgae_arraySize _lgae_index _lgae_oldIFS
|
640
|
+
return ${__LOG4SH_TRUE}
|
641
|
+
}
|
642
|
+
|
643
|
+
#/**
|
644
|
+
# <s:function group="Log4sh" modifier="private">
|
645
|
+
# <entry align="right">
|
646
|
+
# <code>integer</code>
|
647
|
+
# </entry>
|
648
|
+
# <entry align="left">
|
649
|
+
# <funcsynopsis>
|
650
|
+
# <funcprototype>
|
651
|
+
# <funcdef><function>_log4sh_getArrayLength</function></funcdef>
|
652
|
+
# <paramdef>string[] <parameter>array</parameter></paramdef>
|
653
|
+
# </funcprototype>
|
654
|
+
# </funcsynopsis>
|
655
|
+
# <para>Get the length of an array</para>
|
656
|
+
# <funcsynopsis>
|
657
|
+
# <funcsynopsisinfo>length=`_log4sh_getArrayLength "$array"`</funcsynopsisinfo>
|
658
|
+
# </funcsynopsis>
|
659
|
+
# </entry>
|
660
|
+
# </s:function>
|
661
|
+
#*/
|
662
|
+
_log4sh_getArrayLength()
|
663
|
+
{
|
664
|
+
_oldIFS=${IFS} IFS=${__LOG4SH_IFS_ARRAY}
|
665
|
+
set -- $1
|
666
|
+
IFS=${_oldIFS} unset _oldIFS
|
667
|
+
echo $#
|
668
|
+
}
|
669
|
+
|
670
|
+
#/**
|
671
|
+
# <s:function group="Log4sh" modifier="private">
|
672
|
+
# <entry align="right">
|
673
|
+
# <code>string[]</code>
|
674
|
+
# </entry>
|
675
|
+
# <entry>
|
676
|
+
# <funcsynopsis>
|
677
|
+
# <funcprototype>
|
678
|
+
# <funcdef><function>_log4sh_setArrayElement</function></funcdef>
|
679
|
+
# <paramdef>string[] <parameter>array</parameter></paramdef>
|
680
|
+
# <paramdef>integer <parameter>position</parameter></paramdef>
|
681
|
+
# <paramdef>string <parameter>element</parameter></paramdef>
|
682
|
+
# </funcprototype>
|
683
|
+
# </funcsynopsis>
|
684
|
+
# <para>Place an element at a given location in an array</para>
|
685
|
+
# <funcsynopsis>
|
686
|
+
# <funcsynopsisinfo>newArray=`_log4sh_setArrayElement "$array" $position $element`</funcsynopsisinfo>
|
687
|
+
# </funcsynopsis>
|
688
|
+
# </entry>
|
689
|
+
# </s:function>
|
690
|
+
#*/
|
691
|
+
_log4sh_setArrayElement()
|
692
|
+
{
|
693
|
+
echo "$1" |awk '{if(NR==r){print e}else{print $0}}' r=$2 e="$3"
|
694
|
+
}
|
695
|
+
|
696
|
+
#/**
|
697
|
+
# <s:function group="Log4sh" modifier="private">
|
698
|
+
# <entry align="right">
|
699
|
+
# <code>string</code>
|
700
|
+
# </entry>
|
701
|
+
# <entry>
|
702
|
+
# <funcsynopsis>
|
703
|
+
# <funcprototype>
|
704
|
+
# <funcdef><function>_log4sh_peekStack</function></funcdef>
|
705
|
+
# <paramdef>string[] <parameter>array</parameter></paramdef>
|
706
|
+
# </funcprototype>
|
707
|
+
# </funcsynopsis>
|
708
|
+
# <para>Return the topmost element on a stack without removing the
|
709
|
+
# element.</para>
|
710
|
+
# <funcsynopsis>
|
711
|
+
# <funcsynopsisinfo>element=`_log4sh_peekStack "$array"`</funcsynopsisinfo>
|
712
|
+
# </funcsynopsis>
|
713
|
+
# </entry>
|
714
|
+
# </s:function>
|
715
|
+
#*/
|
716
|
+
_log4sh_peekStack()
|
717
|
+
{
|
718
|
+
echo "$@" |awk '{line=$0}END{print line}'
|
719
|
+
}
|
720
|
+
|
721
|
+
#/**
|
722
|
+
# <s:function group="Log4sh" modifier="private">
|
723
|
+
# <entry align="right">
|
724
|
+
# <code>string[]</code>
|
725
|
+
# </entry>
|
726
|
+
# <entry>
|
727
|
+
# <funcsynopsis>
|
728
|
+
# <funcprototype>
|
729
|
+
# <funcdef><function>_log4sh_popStack</function></funcdef>
|
730
|
+
# <paramdef>string[] <parameter>array</parameter></paramdef>
|
731
|
+
# </funcprototype>
|
732
|
+
# </funcsynopsis>
|
733
|
+
# <para>Remove the top-most element from a stack. This command takes a
|
734
|
+
# normal log4sh string array as input, but treats it as though it were a
|
735
|
+
# stack.</para>
|
736
|
+
# <funcsynopsis>
|
737
|
+
# <funcsynopsisinfo>newArray=`_log4sh_popStack "$array"`</funcsynopsisinfo>
|
738
|
+
# </funcsynopsis>
|
739
|
+
# </entry>
|
740
|
+
# </s:function>
|
741
|
+
#*/
|
742
|
+
_log4sh_popStack()
|
743
|
+
{
|
744
|
+
_array=$1
|
745
|
+
_length=`_log4sh_getArrayLength "${_array}"`
|
746
|
+
echo "${_array}" |awk '{if(NR<r){print $0}}' r=${_length}
|
747
|
+
unset _array _length
|
748
|
+
}
|
749
|
+
|
750
|
+
#/**
|
751
|
+
# <s:function group="Log4sh" modifier="private">
|
752
|
+
# <entry align="right">
|
753
|
+
# <code>string</code>
|
754
|
+
# </entry>
|
755
|
+
# <entry>
|
756
|
+
# <funcsynopsis>
|
757
|
+
# <funcprototype>
|
758
|
+
# <funcdef><function>_log4sh_pushStack</function></funcdef>
|
759
|
+
# <paramdef>string[] <parameter>array</parameter></paramdef>
|
760
|
+
# <paramdef>string <parameter>element</parameter></paramdef>
|
761
|
+
# </funcprototype>
|
762
|
+
# </funcsynopsis>
|
763
|
+
# <para>Add a new element to the top of a stack. This command takes a normal
|
764
|
+
# log4sh string array as input, but treats it as though it were a
|
765
|
+
# stack.</para>
|
766
|
+
# <funcsynopsis>
|
767
|
+
# <funcsynopsisinfo>newArray=`_log4sh_pushStack "$array" $element`</funcsynopsisinfo>
|
768
|
+
# </funcsynopsis>
|
769
|
+
# </entry>
|
770
|
+
# </s:function>
|
771
|
+
#*/
|
772
|
+
_log4sh_pushStack()
|
773
|
+
{
|
774
|
+
echo "${1:+$1${__LOG4SH_IFS_ARRAY}}$2"
|
775
|
+
}
|
776
|
+
|
777
|
+
#=============================================================================
|
778
|
+
# Appender
|
779
|
+
#
|
780
|
+
|
781
|
+
#/**
|
782
|
+
# <s:function group="Appender" modifier="public">
|
783
|
+
# <entry align="right">
|
784
|
+
# <emphasis>void</emphasis>
|
785
|
+
# </entry>
|
786
|
+
# <entry>
|
787
|
+
# <funcsynopsis>
|
788
|
+
# <funcprototype>
|
789
|
+
# <funcdef><function>appender_activateOptions</function></funcdef>
|
790
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
791
|
+
# </funcprototype>
|
792
|
+
# </funcsynopsis>
|
793
|
+
# <para>
|
794
|
+
# Activate an appender's configuration. This should be called after
|
795
|
+
# reconfiguring an appender via code. It needs only to be called once
|
796
|
+
# before any logging statements are called. This calling of this function
|
797
|
+
# will be required in log4sh 1.4.x.
|
798
|
+
# </para>
|
799
|
+
# <funcsynopsis>
|
800
|
+
# <funcsynopsisinfo>appender_activateAppender myAppender</funcsynopsisinfo>
|
801
|
+
# </funcsynopsis>
|
802
|
+
# </entry>
|
803
|
+
# </s:function>
|
804
|
+
#*/
|
805
|
+
appender_activateOptions()
|
806
|
+
{
|
807
|
+
_aao_appender=$1
|
808
|
+
${__LOG4SH_APPENDER_FUNC_PREFIX}${_aao_appender}_activateOptions
|
809
|
+
unset _aao_appender
|
810
|
+
}
|
811
|
+
|
812
|
+
#/**
|
813
|
+
# <s:function group="Appender" modifier="public">
|
814
|
+
# <entry align="right">
|
815
|
+
# <emphasis>void</emphasis>
|
816
|
+
# </entry>
|
817
|
+
# <entry>
|
818
|
+
# <funcsynopsis>
|
819
|
+
# <funcprototype>
|
820
|
+
# <funcdef><function>appender_close</function></funcdef>
|
821
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
822
|
+
# </funcprototype>
|
823
|
+
# </funcsynopsis>
|
824
|
+
# <para>Disable any further logging via an appender. Once closed, the
|
825
|
+
# appender can be reopened by setting it to any logging Level (e.g.
|
826
|
+
# INFO).</para>
|
827
|
+
# <funcsynopsis>
|
828
|
+
# <funcsynopsisinfo>appender_close myAppender</funcsynopsisinfo>
|
829
|
+
# </funcsynopsis>
|
830
|
+
# </entry>
|
831
|
+
# </s:function>
|
832
|
+
#*/
|
833
|
+
appender_close()
|
834
|
+
{
|
835
|
+
appender_setLevel $1 ${__LOG4SH_LEVEL_CLOSED_STR}
|
836
|
+
}
|
837
|
+
|
838
|
+
#/**
|
839
|
+
# <s:function group="Appender" modifier="public">
|
840
|
+
# <entry align="right">
|
841
|
+
# <code>boolean</code>
|
842
|
+
# </entry>
|
843
|
+
# <entry>
|
844
|
+
# <funcsynopsis>
|
845
|
+
# <funcprototype>
|
846
|
+
# <funcdef><function>appender_exists</function></funcdef>
|
847
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
848
|
+
# </funcprototype>
|
849
|
+
# </funcsynopsis>
|
850
|
+
# <para>Checks for the existance of a named appender</para>
|
851
|
+
# <funcsynopsis>
|
852
|
+
# <funcsynopsisinfo>exists=`appender_exists myAppender`</funcsynopsisinfo>
|
853
|
+
# </funcsynopsis>
|
854
|
+
# </entry>
|
855
|
+
# </s:function>
|
856
|
+
#*/
|
857
|
+
appender_exists()
|
858
|
+
{
|
859
|
+
_ae_index=`_log4sh_findArrayElement "${__log4shAppenders}" $1`
|
860
|
+
[ "${_ae_index}" -gt 0 ] \
|
861
|
+
&& _ae_return=${__LOG4SH_TRUE} \
|
862
|
+
|| _ae_return=${__LOG4SH_FALSE}
|
863
|
+
unset _ae_index
|
864
|
+
return ${_ae_return}
|
865
|
+
}
|
866
|
+
|
867
|
+
#/**
|
868
|
+
# <s:function group="Appender" modifier="public">
|
869
|
+
# <entry align="right">
|
870
|
+
# <code>string</code>
|
871
|
+
# </entry>
|
872
|
+
# <entry>
|
873
|
+
# <funcsynopsis>
|
874
|
+
# <funcprototype>
|
875
|
+
# <funcdef><function>appender_getLayout</function></funcdef>
|
876
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
877
|
+
# </funcprototype>
|
878
|
+
# </funcsynopsis>
|
879
|
+
# <para>Gets the Layout of an Appender</para>
|
880
|
+
# <funcsynopsis>
|
881
|
+
# <funcsynopsisinfo>type=`appender_getLayout myAppender`</funcsynopsisinfo>
|
882
|
+
# </funcsynopsis>
|
883
|
+
# </entry>
|
884
|
+
# </s:function>
|
885
|
+
#*/
|
886
|
+
appender_getLayout()
|
887
|
+
{
|
888
|
+
_agl_index=`_log4sh_findArrayElement "${__log4shAppenders}" $1`
|
889
|
+
_log4sh_getArrayElement "${__log4shAppenderLayouts}" ${_agl_index}
|
890
|
+
unset _agl_index
|
891
|
+
}
|
892
|
+
|
893
|
+
#/**
|
894
|
+
# <s:function group="Appender" modifier="public">
|
895
|
+
# <entry align="right">
|
896
|
+
# <emphasis>void</emphasis>
|
897
|
+
# </entry>
|
898
|
+
# <entry>
|
899
|
+
# <funcsynopsis>
|
900
|
+
# <funcprototype>
|
901
|
+
# <funcdef><function>appender_setLayout</function></funcdef>
|
902
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
903
|
+
# <paramdef>string <parameter>layout</parameter></paramdef>
|
904
|
+
# </funcprototype>
|
905
|
+
# </funcsynopsis>
|
906
|
+
# <para>Sets the Layout of an Appender (e.g. PatternLayout)</para>
|
907
|
+
# <funcsynopsis>
|
908
|
+
# <funcsynopsisinfo>appender_setLayout myAppender PatternLayout</funcsynopsisinfo>
|
909
|
+
# </funcsynopsis>
|
910
|
+
# </entry>
|
911
|
+
# </s:function>
|
912
|
+
#*/
|
913
|
+
appender_setLayout()
|
914
|
+
{
|
915
|
+
_asl_appender=$1
|
916
|
+
_asl_layout=$2
|
917
|
+
|
918
|
+
case ${_asl_layout} in
|
919
|
+
${__LOG4SH_LAYOUT_HTML}|\
|
920
|
+
${__LOG4SH_CONFIG_LOG4J_CP}.${__LOG4SH_LAYOUT_HTML})
|
921
|
+
_asl_layout=${__LOG4SH_LAYOUT_HTML}
|
922
|
+
;;
|
923
|
+
|
924
|
+
${__LOG4SH_LAYOUT_SIMPLE}|\
|
925
|
+
${__LOG4SH_CONFIG_LOG4J_CP}.${__LOG4SH_LAYOUT_SIMPLE})
|
926
|
+
_asl_layout=${__LOG4SH_LAYOUT_SIMPLE}
|
927
|
+
;;
|
928
|
+
|
929
|
+
${__LOG4SH_LAYOUT_PATTERN}|\
|
930
|
+
${__LOG4SH_CONFIG_LOG4J_CP}.${__LOG4SH_LAYOUT_PATTERN})
|
931
|
+
_asl_layout=${__LOG4SH_LAYOUT_PATTERN}
|
932
|
+
;;
|
933
|
+
|
934
|
+
*)
|
935
|
+
_log4sh_error "unknown layout: ${_asl_layout}"
|
936
|
+
return ${__LOG4SH_FALSE}
|
937
|
+
;;
|
938
|
+
esac
|
939
|
+
|
940
|
+
_asl_index=`_log4sh_findArrayElement "${__log4shAppenders}" $1`
|
941
|
+
__log4shAppenderLayouts=`_log4sh_setArrayElement \
|
942
|
+
"${__log4shAppenderLayouts}" ${_asl_index} "${_asl_layout}"`
|
943
|
+
|
944
|
+
# resource the appender
|
945
|
+
_appender_cache ${_asl_appender}
|
946
|
+
|
947
|
+
unset _asl_appender _asl_index _asl_layout
|
948
|
+
return ${__LOG4SH_TRUE}
|
949
|
+
}
|
950
|
+
|
951
|
+
#/**
|
952
|
+
# <s:function group="Appender" modifier="private">
|
953
|
+
# <entry align="right">
|
954
|
+
# <code>string</code>
|
955
|
+
# </entry>
|
956
|
+
# <entry>
|
957
|
+
# <funcsynopsis>
|
958
|
+
# <funcprototype>
|
959
|
+
# <funcdef><function>_appender_getLayoutByIndex</function></funcdef>
|
960
|
+
# <paramdef>integer <parameter>index</parameter></paramdef>
|
961
|
+
# </funcprototype>
|
962
|
+
# </funcsynopsis>
|
963
|
+
# <para>Gets the Layout of an Appender at the given array index</para>
|
964
|
+
# <funcsynopsis>
|
965
|
+
# <funcsynopsisinfo>type=`_appender_getLayoutByIndex 3`</funcsynopsisinfo>
|
966
|
+
# </funcsynopsis>
|
967
|
+
# </entry>
|
968
|
+
# </s:function>
|
969
|
+
#*/
|
970
|
+
_appender_getLayoutByIndex()
|
971
|
+
{
|
972
|
+
_log4sh_getArrayElement "${__log4shAppenderLayouts}" $1
|
973
|
+
}
|
974
|
+
|
975
|
+
#/**
|
976
|
+
# <s:function group="Appender" modifier="public">
|
977
|
+
# <entry align="right">
|
978
|
+
# <code>string</code>/boolean
|
979
|
+
# </entry>
|
980
|
+
# <entry>
|
981
|
+
# <funcsynopsis>
|
982
|
+
# <funcprototype>
|
983
|
+
# <funcdef><function>appender_getLevel</function></funcdef>
|
984
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
985
|
+
# </funcprototype>
|
986
|
+
# </funcsynopsis>
|
987
|
+
# <para>Gets the current logging Level of an Appender</para>
|
988
|
+
# <funcsynopsis>
|
989
|
+
# <funcsynopsisinfo>type=`appender_getLevel myAppender`</funcsynopsisinfo>
|
990
|
+
# </funcsynopsis>
|
991
|
+
# </entry>
|
992
|
+
# </s:function>
|
993
|
+
#*/
|
994
|
+
appender_getLevel()
|
995
|
+
{
|
996
|
+
if [ $# -ne 1 ]; then
|
997
|
+
_log4sh_error 'appender_getLevel(): invalid number of parameters'
|
998
|
+
return ${__LOG4SH_FALSE}
|
999
|
+
fi
|
1000
|
+
|
1001
|
+
agl_appender=$1
|
1002
|
+
|
1003
|
+
agl_index=`_log4sh_findArrayElement "${__log4shAppenders}" ${agl_appender}`
|
1004
|
+
# TODO: put check for valid index here
|
1005
|
+
agl_level=`_log4sh_getArrayElement \
|
1006
|
+
"${__log4shAppenderLevels}" ${agl_index}`
|
1007
|
+
__log4sh_return=$?
|
1008
|
+
|
1009
|
+
echo "${agl_level}"
|
1010
|
+
|
1011
|
+
unset agl_appender agl_index agl_level
|
1012
|
+
return ${__log4sh_return}
|
1013
|
+
}
|
1014
|
+
|
1015
|
+
#/**
|
1016
|
+
# <s:function group="Appender" modifier="public">
|
1017
|
+
# <entry align="right">
|
1018
|
+
# <emphasis>void</emphasis>/<code>boolean</code>
|
1019
|
+
# </entry>
|
1020
|
+
# <entry>
|
1021
|
+
# <funcsynopsis>
|
1022
|
+
# <funcprototype>
|
1023
|
+
# <funcdef><function>appender_setLevel</function></funcdef>
|
1024
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
1025
|
+
# <paramdef>string <parameter>level</parameter></paramdef>
|
1026
|
+
# </funcprototype>
|
1027
|
+
# </funcsynopsis>
|
1028
|
+
# <para>Sets the Level of an Appender (e.g. INFO)</para>
|
1029
|
+
# <funcsynopsis>
|
1030
|
+
# <funcsynopsisinfo>appender_setLevel myAppender INFO</funcsynopsisinfo>
|
1031
|
+
# </funcsynopsis>
|
1032
|
+
# </entry>
|
1033
|
+
# </s:function>
|
1034
|
+
#*/
|
1035
|
+
appender_setLevel()
|
1036
|
+
{
|
1037
|
+
asl_appender=$1
|
1038
|
+
asl_level=$2
|
1039
|
+
|
1040
|
+
_index=`_log4sh_findArrayElement "${__log4shAppenders}" ${asl_appender}`
|
1041
|
+
__log4shAppenderLevels=`_log4sh_setArrayElement \
|
1042
|
+
"${__log4shAppenderLevels}" ${_index} "${asl_level}"`
|
1043
|
+
|
1044
|
+
# resource the appender
|
1045
|
+
_appender_cache ${asl_appender}
|
1046
|
+
|
1047
|
+
unset asl_appender asl_level _index
|
1048
|
+
return ${__LOG4SH_TRUE}
|
1049
|
+
}
|
1050
|
+
|
1051
|
+
#/**
|
1052
|
+
# <s:function group="Appender" modifier="private">
|
1053
|
+
# <entry align="right">
|
1054
|
+
# <code>string</code>
|
1055
|
+
# </entry>
|
1056
|
+
# <entry>
|
1057
|
+
# <funcsynopsis>
|
1058
|
+
# <funcprototype>
|
1059
|
+
# <funcdef><function>_appender_getLevelByIndex</function></funcdef>
|
1060
|
+
# <paramdef>integer <parameter>index</parameter></paramdef>
|
1061
|
+
# </funcprototype>
|
1062
|
+
# </funcsynopsis>
|
1063
|
+
# <para>Gets the current logging Level of an Appender at the given array
|
1064
|
+
# index</para>
|
1065
|
+
# <funcsynopsis>
|
1066
|
+
# <funcsynopsisinfo>type=`_appender_getLevelByIndex 3`</funcsynopsisinfo>
|
1067
|
+
# </funcsynopsis>
|
1068
|
+
# </entry>
|
1069
|
+
# </s:function>
|
1070
|
+
#*/
|
1071
|
+
_appender_getLevelByIndex()
|
1072
|
+
{
|
1073
|
+
[ -n "${FUNCNAME:-}" ] && ${__LOG4SH_TRACE} "${FUNCNAME}()${BASH_LINENO:+'(called from ${BASH_LINENO})'}"
|
1074
|
+
_log4sh_getArrayElement "${__log4shAppenderLevels}" $1
|
1075
|
+
}
|
1076
|
+
|
1077
|
+
#/**
|
1078
|
+
# <s:function group="Appender" modifier="public">
|
1079
|
+
# <entry align="right">
|
1080
|
+
# <code>string</code>
|
1081
|
+
# </entry>
|
1082
|
+
# <entry>
|
1083
|
+
# <funcsynopsis>
|
1084
|
+
# <funcprototype>
|
1085
|
+
# <funcdef><function>appender_getPattern</function></funcdef>
|
1086
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
1087
|
+
# </funcprototype>
|
1088
|
+
# </funcsynopsis>
|
1089
|
+
# <para>Gets the Pattern of an Appender</para>
|
1090
|
+
# <funcsynopsis>
|
1091
|
+
# <funcsynopsisinfo>pattern=`appender_getPattern myAppender`</funcsynopsisinfo>
|
1092
|
+
# </funcsynopsis>
|
1093
|
+
# </entry>
|
1094
|
+
# </s:function>
|
1095
|
+
#*/
|
1096
|
+
appender_getPattern()
|
1097
|
+
{
|
1098
|
+
_index=`_log4sh_findArrayElement "$__log4shAppenders" $1`
|
1099
|
+
_log4sh_getArrayElement "$__log4shAppenderPatterns" $_index
|
1100
|
+
unset _index
|
1101
|
+
}
|
1102
|
+
|
1103
|
+
#/**
|
1104
|
+
# <s:function group="Appender" modifier="public">
|
1105
|
+
# <entry align="right">
|
1106
|
+
# <emphasis>void</emphasis>/<code>boolean</code>
|
1107
|
+
# </entry>
|
1108
|
+
# <entry>
|
1109
|
+
# <funcsynopsis>
|
1110
|
+
# <funcprototype>
|
1111
|
+
# <funcdef><function>appender_setPattern</function></funcdef>
|
1112
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
1113
|
+
# <paramdef>string <parameter>pattern</parameter></paramdef>
|
1114
|
+
# </funcprototype>
|
1115
|
+
# </funcsynopsis>
|
1116
|
+
# <para>Sets the Pattern of an Appender</para>
|
1117
|
+
# <funcsynopsis>
|
1118
|
+
# <funcsynopsisinfo>appender_setPattern myAppender '%d %p - %m%n'</funcsynopsisinfo>
|
1119
|
+
# </funcsynopsis>
|
1120
|
+
# </entry>
|
1121
|
+
# </s:function>
|
1122
|
+
#*/
|
1123
|
+
appender_setPattern()
|
1124
|
+
{
|
1125
|
+
asp_appender=$1
|
1126
|
+
asp_pattern=$2
|
1127
|
+
|
1128
|
+
_index=`_log4sh_findArrayElement "${__log4shAppenders}" ${asp_appender}`
|
1129
|
+
__log4shAppenderPatterns=`_log4sh_setArrayElement \
|
1130
|
+
"${__log4shAppenderPatterns}" ${_index} "${asp_pattern}"`
|
1131
|
+
|
1132
|
+
# resource the appender
|
1133
|
+
_appender_cache ${asp_appender}
|
1134
|
+
|
1135
|
+
unset asp_appender asp_pattern _index
|
1136
|
+
return ${__LOG4SH_TRUE}
|
1137
|
+
}
|
1138
|
+
|
1139
|
+
#/**
|
1140
|
+
# <s:function group="Appender" modifier="private">
|
1141
|
+
# <entry align="right">
|
1142
|
+
# <code>string</code>
|
1143
|
+
# </entry>
|
1144
|
+
# <entry>
|
1145
|
+
# <funcsynopsis>
|
1146
|
+
# <funcprototype>
|
1147
|
+
# <funcdef><function>_appender_getPatternByIndex</function></funcdef>
|
1148
|
+
# <paramdef>integer <parameter>index</parameter></paramdef>
|
1149
|
+
# </funcprototype>
|
1150
|
+
# </funcsynopsis>
|
1151
|
+
# <para>Gets the Pattern of an Appender at the specified array index</para>
|
1152
|
+
# <funcsynopsis>
|
1153
|
+
# <funcsynopsisinfo>pattern=`_appender_getPatternByIndex 3`</funcsynopsisinfo>
|
1154
|
+
# </funcsynopsis>
|
1155
|
+
# </entry>
|
1156
|
+
# </s:function>
|
1157
|
+
#*/
|
1158
|
+
_appender_getPatternByIndex()
|
1159
|
+
{
|
1160
|
+
_log4sh_getArrayElement "$__log4shAppenderPatterns" $1
|
1161
|
+
}
|
1162
|
+
|
1163
|
+
#/**
|
1164
|
+
# <s:function group="Appender" modifier="private">
|
1165
|
+
# <entry align="right">
|
1166
|
+
# <code>string</code>
|
1167
|
+
# </entry>
|
1168
|
+
# <entry>
|
1169
|
+
# <funcsynopsis>
|
1170
|
+
# <funcprototype>
|
1171
|
+
# <funcdef><function>_appender_parsePattern</function></funcdef>
|
1172
|
+
# <paramdef>string <parameter>pattern</parameter></paramdef>
|
1173
|
+
# <paramdef>string <parameter>priority</parameter></paramdef>
|
1174
|
+
# <paramdef>string <parameter>message</parameter></paramdef>
|
1175
|
+
# </funcprototype>
|
1176
|
+
# </funcsynopsis>
|
1177
|
+
# <para>Generate a logging message given a Pattern, priority, and message.
|
1178
|
+
# All dates will be represented as ISO 8601 dates (YYYY-MM-DD
|
1179
|
+
# HH:MM:SS).</para>
|
1180
|
+
# <para>Note: the '<code>%r</code>' character modifier does not work in the
|
1181
|
+
# Solaris <code>/bin/sh</code> shell</para>
|
1182
|
+
# <para>Example:
|
1183
|
+
# <blockquote>
|
1184
|
+
# <funcsynopsis>
|
1185
|
+
# <funcsynopsisinfo>_appender_parsePattern '%d %p - %m%n' INFO "message to log"</funcsynopsisinfo>
|
1186
|
+
# </funcsynopsis>
|
1187
|
+
# </blockquote>
|
1188
|
+
# </para>
|
1189
|
+
# </entry>
|
1190
|
+
# </s:function>
|
1191
|
+
#*/
|
1192
|
+
_appender_parsePattern()
|
1193
|
+
{
|
1194
|
+
_pattern=$1
|
1195
|
+
_priority=$2
|
1196
|
+
_msg=$3
|
1197
|
+
|
1198
|
+
_date=''
|
1199
|
+
_doEval=${__LOG4SH_FALSE}
|
1200
|
+
|
1201
|
+
# determine if various commands must be run
|
1202
|
+
_oldIFS="${IFS}"; IFS='%'; set -- x${_pattern}; IFS="${_oldIFS}"
|
1203
|
+
if [ $# -gt 1 ]; then
|
1204
|
+
# run the date command??
|
1205
|
+
IFS='d'; set -- ${_pattern}x; IFS="${_oldIFS}"
|
1206
|
+
[ $# -gt 1 ] && _date=`date '+%Y-%m-%d %H:%M:%S'`
|
1207
|
+
|
1208
|
+
# run the eval command?
|
1209
|
+
IFS='X'; set -- ${_pattern}x; IFS="${_oldIFS}"
|
1210
|
+
[ $# -gt 1 ] && _doEval=${__LOG4SH_TRUE}
|
1211
|
+
fi
|
1212
|
+
unset _oldIFS
|
1213
|
+
|
1214
|
+
# escape any '\' and '&' chars in the message
|
1215
|
+
_msg=`echo "${_msg}" |sed 's/\\\\/\\\\\\\\/g;s/&/\\\\&/g'`
|
1216
|
+
|
1217
|
+
# deal with any newlines in the message
|
1218
|
+
_msg=`echo "${_msg}" |tr '\n' ''`
|
1219
|
+
|
1220
|
+
# parse the pattern
|
1221
|
+
_pattern=`echo "${_pattern}" |sed \
|
1222
|
+
-e 's/%c/shell/g' \
|
1223
|
+
-e 's/%d{[^}]*}/%d/g' -e "s/%d/${_date}/g" \
|
1224
|
+
-e "s/%F/${__log4sh_filename}/g" \
|
1225
|
+
-e 's/%L//g' \
|
1226
|
+
-e 's/%n//g' \
|
1227
|
+
-e "s/%-*[0-9]*p/${_priority}/g" \
|
1228
|
+
-e "s/%-*[0-9]*r/${__log4sh_seconds}/g" \
|
1229
|
+
-e "s/%t/${__log4sh_threadName}/g" \
|
1230
|
+
-e 's/%x//g' \
|
1231
|
+
-e 's/%X{/$\{/g' \
|
1232
|
+
-e 's/%%m/%%%m/g' -e 's/%%/%/g' \
|
1233
|
+
-e "s%m${_msg}" |tr '' '\n'`
|
1234
|
+
if [ ${_doEval} -eq ${__LOG4SH_FALSE} ]; then
|
1235
|
+
echo "${_pattern}"
|
1236
|
+
else
|
1237
|
+
eval "echo \"${_pattern}\""
|
1238
|
+
fi
|
1239
|
+
|
1240
|
+
unset _date _doEval _msg _pattern _tag
|
1241
|
+
}
|
1242
|
+
|
1243
|
+
#/**
|
1244
|
+
# <s:function group="Appender" modifier="public">
|
1245
|
+
# <entry align="right">
|
1246
|
+
# <code>string</code>
|
1247
|
+
# </entry>
|
1248
|
+
# <entry>
|
1249
|
+
# <funcsynopsis>
|
1250
|
+
# <funcprototype>
|
1251
|
+
# <funcdef><function>appender_getType</function></funcdef>
|
1252
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
1253
|
+
# </funcprototype>
|
1254
|
+
# </funcsynopsis>
|
1255
|
+
# <para>Gets the Type of an Appender</para>
|
1256
|
+
# <funcsynopsis>
|
1257
|
+
# <funcsynopsisinfo>type=`appender_getType myAppender`</funcsynopsisinfo>
|
1258
|
+
# </funcsynopsis>
|
1259
|
+
# </entry>
|
1260
|
+
# </s:function>
|
1261
|
+
#*/
|
1262
|
+
appender_getType()
|
1263
|
+
{
|
1264
|
+
_index=`_log4sh_findArrayElement "$__log4shAppenders" $1`
|
1265
|
+
_log4sh_getArrayElement "$__log4shAppenderTypes" $_index
|
1266
|
+
unset _index
|
1267
|
+
}
|
1268
|
+
|
1269
|
+
#/**
|
1270
|
+
# <s:function group="Appender" modifier="public">
|
1271
|
+
# <entry align="right">
|
1272
|
+
# <code>string</code>
|
1273
|
+
# </entry>
|
1274
|
+
# <entry>
|
1275
|
+
# <funcsynopsis>
|
1276
|
+
# <funcprototype>
|
1277
|
+
# <funcdef><function>appender_getAppenderType</function></funcdef>
|
1278
|
+
# <paramdef>integer <parameter>index</parameter></paramdef>
|
1279
|
+
# </funcprototype>
|
1280
|
+
# </funcsynopsis>
|
1281
|
+
# <para><emphasis role="strong">Deprecated as of 1.3.1</emphasis></para>
|
1282
|
+
# <para>
|
1283
|
+
# Gets the Type of an Appender at the given array index
|
1284
|
+
# </para>
|
1285
|
+
# <funcsynopsis>
|
1286
|
+
# <funcsynopsisinfo>type=`appender_getAppenderType 3`</funcsynopsisinfo>
|
1287
|
+
# </funcsynopsis>
|
1288
|
+
# </entry>
|
1289
|
+
# </s:function>
|
1290
|
+
#*/
|
1291
|
+
appender_getAppenderType()
|
1292
|
+
{
|
1293
|
+
_appender_getTypeByIndex "$@"
|
1294
|
+
}
|
1295
|
+
|
1296
|
+
#/**
|
1297
|
+
# <s:function group="Appender" modifier="public">
|
1298
|
+
# <entry align="right">
|
1299
|
+
# <emphasis>void</emphasis>/<code>boolean</code>
|
1300
|
+
# </entry>
|
1301
|
+
# <entry>
|
1302
|
+
# <funcsynopsis>
|
1303
|
+
# <funcprototype>
|
1304
|
+
# <funcdef><function>appender_setType</function></funcdef>
|
1305
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
1306
|
+
# <paramdef>string <parameter>type</parameter></paramdef>
|
1307
|
+
# </funcprototype>
|
1308
|
+
# </funcsynopsis>
|
1309
|
+
# <para>Sets the Type of an Appender (e.g. FileAppender)</para>
|
1310
|
+
# <funcsynopsis>
|
1311
|
+
# <funcsynopsisinfo>appender_setType myAppender FileAppender</funcsynopsisinfo>
|
1312
|
+
# </funcsynopsis>
|
1313
|
+
# </entry>
|
1314
|
+
# </s:function>
|
1315
|
+
#*/
|
1316
|
+
appender_setType()
|
1317
|
+
{
|
1318
|
+
ast_appender=$1
|
1319
|
+
ast_type=$2
|
1320
|
+
|
1321
|
+
# XXX need to verify types
|
1322
|
+
|
1323
|
+
_index=`_log4sh_findArrayElement "${__log4shAppenders}" ${ast_appender}`
|
1324
|
+
__log4shAppenderTypes=`_log4sh_setArrayElement \
|
1325
|
+
"${__log4shAppenderTypes}" ${_index} "${ast_type}"`
|
1326
|
+
|
1327
|
+
# resource the appender
|
1328
|
+
_appender_cache ${ast_appender}
|
1329
|
+
|
1330
|
+
unset ast_appender ast_type _index
|
1331
|
+
return ${__LOG4SH_TRUE}
|
1332
|
+
}
|
1333
|
+
|
1334
|
+
#/**
|
1335
|
+
# <s:function group="Appender" modifier="public">
|
1336
|
+
# <entry align="right">
|
1337
|
+
# <emphasis>void</emphasis>
|
1338
|
+
# </entry>
|
1339
|
+
# <entry>
|
1340
|
+
# <funcsynopsis>
|
1341
|
+
# <funcprototype>
|
1342
|
+
# <funcdef><function>appender_setAppenderType</function></funcdef>
|
1343
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
1344
|
+
# <paramdef>string <parameter>type</parameter></paramdef>
|
1345
|
+
# </funcprototype>
|
1346
|
+
# </funcsynopsis>
|
1347
|
+
# <para><emphasis role="strong">Deprecated as of 1.3.1</emphasis></para>
|
1348
|
+
# <para>
|
1349
|
+
# Sets the Type of an Appender (e.g. FileAppender)
|
1350
|
+
# </para>
|
1351
|
+
# <funcsynopsis>
|
1352
|
+
# <funcsynopsisinfo>appender_setAppenderType myAppender FileAppender</funcsynopsisinfo>
|
1353
|
+
# </funcsynopsis>
|
1354
|
+
# </entry>
|
1355
|
+
# </s:function>
|
1356
|
+
#*/
|
1357
|
+
appender_setAppenderType()
|
1358
|
+
{
|
1359
|
+
appender_setType "$@"
|
1360
|
+
}
|
1361
|
+
|
1362
|
+
#/**
|
1363
|
+
# <s:function group="Appender" modifier="private">
|
1364
|
+
# <entry align="right">
|
1365
|
+
# <code>string</code>
|
1366
|
+
# </entry>
|
1367
|
+
# <entry>
|
1368
|
+
# <funcsynopsis>
|
1369
|
+
# <funcprototype>
|
1370
|
+
# <funcdef><function>_appender_getTypeByIndex</function></funcdef>
|
1371
|
+
# <paramdef>integer <parameter>index</parameter></paramdef>
|
1372
|
+
# </funcprototype>
|
1373
|
+
# </funcsynopsis>
|
1374
|
+
# <para>Gets the Type of an Appender at the given array index</para>
|
1375
|
+
# <funcsynopsis>
|
1376
|
+
# <funcsynopsisinfo>type=`_appender_getTypeByIndex 3`</funcsynopsisinfo>
|
1377
|
+
# </funcsynopsis>
|
1378
|
+
# </entry>
|
1379
|
+
# </s:function>
|
1380
|
+
#*/
|
1381
|
+
_appender_getTypeByIndex()
|
1382
|
+
{
|
1383
|
+
_log4sh_getArrayElement "$__log4shAppenderTypes" $1
|
1384
|
+
}
|
1385
|
+
|
1386
|
+
#/**
|
1387
|
+
# <s:function group="Appender" modifier="private">
|
1388
|
+
# <entry align="right">
|
1389
|
+
# <emphasis>void</emphasis>
|
1390
|
+
# </entry>
|
1391
|
+
# <entry>
|
1392
|
+
# <funcsynopsis>
|
1393
|
+
# <funcprototype>
|
1394
|
+
# <funcdef><function>_appender_cache</function></funcdef>
|
1395
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
1396
|
+
# </funcprototype>
|
1397
|
+
# </funcsynopsis>
|
1398
|
+
# <para>Dynamically creates an appender function in memory that will fully
|
1399
|
+
# instantiate itself when it is called.</para>
|
1400
|
+
# <funcsynopsis>
|
1401
|
+
# <funcsynopsisinfo>_appender_cache myAppender</funcsynopsisinfo>
|
1402
|
+
# </funcsynopsis>
|
1403
|
+
# </entry>
|
1404
|
+
# </s:function>
|
1405
|
+
#*/
|
1406
|
+
_appender_cache()
|
1407
|
+
{
|
1408
|
+
_ac__appender=$1
|
1409
|
+
|
1410
|
+
_ac__inc="${__log4sh_tmpDir}/${_ac__appender}${__LOG4SH_APPENDER_INCLUDE_EXT}"
|
1411
|
+
|
1412
|
+
cat >"${_ac__inc}" <<EOF
|
1413
|
+
${__LOG4SH_APPENDER_FUNC_PREFIX}${_ac__appender}_activateOptions()
|
1414
|
+
{
|
1415
|
+
[ -n "\${FUNCNAME:-}" ] && \${__LOG4SH_TRACE} "\${FUNCNAME}()\${BASH_LINENO:+'(called from \${BASH_LINENO})'}"
|
1416
|
+
_appender_activate ${_ac__appender}
|
1417
|
+
}
|
1418
|
+
|
1419
|
+
${__LOG4SH_APPENDER_FUNC_PREFIX}${_ac__appender}_append() { :; }
|
1420
|
+
EOF
|
1421
|
+
|
1422
|
+
# source the new functions
|
1423
|
+
. "${_ac__inc}"
|
1424
|
+
|
1425
|
+
# call the activateOptions function
|
1426
|
+
# XXX will be removed in log4sh-1.5.x
|
1427
|
+
appender_activateOptions ${_ac__appender}
|
1428
|
+
}
|
1429
|
+
|
1430
|
+
#/**
|
1431
|
+
# <s:function group="Appender" modifier="private">
|
1432
|
+
# <entry align="right">
|
1433
|
+
# <emphasis>void</emphasis>
|
1434
|
+
# </entry>
|
1435
|
+
# <entry>
|
1436
|
+
# <funcsynopsis>
|
1437
|
+
# <funcprototype>
|
1438
|
+
# <funcdef><function>_appender_activate</function></funcdef>
|
1439
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
1440
|
+
# </funcprototype>
|
1441
|
+
# </funcsynopsis>
|
1442
|
+
# <para>
|
1443
|
+
# Dynamically regenerates an appender function in memory that is fully
|
1444
|
+
# instantiated for a specific logging task.
|
1445
|
+
# </para>
|
1446
|
+
# <funcsynopsis>
|
1447
|
+
# <funcsynopsisinfo>_appender_activate myAppender</funcsynopsisinfo>
|
1448
|
+
# </funcsynopsis>
|
1449
|
+
# </entry>
|
1450
|
+
# </s:function>
|
1451
|
+
#*/
|
1452
|
+
_appender_activate()
|
1453
|
+
{
|
1454
|
+
[ -n "${FUNCNAME:-}" ] && ${__LOG4SH_TRACE} "${FUNCNAME}()${BASH_LINENO:+'(called from ${BASH_LINENO})'}"
|
1455
|
+
${__LOG4SH_TRACE} "_appender_activate($#)"
|
1456
|
+
_aa_appender=$1
|
1457
|
+
${__LOG4SH_TRACE} "_aa_appender='${_aa_appender}'"
|
1458
|
+
|
1459
|
+
_aa_index=`_log4sh_findArrayElement "${__log4shAppenders}" ${_aa_appender}`
|
1460
|
+
_aa_inc="${__log4sh_tmpDir}/${_aa_appender}${__LOG4SH_APPENDER_INCLUDE_EXT}"
|
1461
|
+
|
1462
|
+
### generate function for inclusion
|
1463
|
+
# TODO can we modularize this in the future?
|
1464
|
+
|
1465
|
+
# send STDOUT to our include file
|
1466
|
+
exec 4>&1 >${_aa_inc}
|
1467
|
+
|
1468
|
+
# header
|
1469
|
+
cat <<EOF
|
1470
|
+
${__LOG4SH_APPENDER_FUNC_PREFIX}${_aa_appender}_append()
|
1471
|
+
{
|
1472
|
+
[ -n "\${FUNCNAME:-}" ] && \${__LOG4SH_TRACE} "\${FUNCNAME}()\${BASH_LINENO:+'(called from \${BASH_LINENO})'}"
|
1473
|
+
_la_level=\$1
|
1474
|
+
_la_message=\$2
|
1475
|
+
EOF
|
1476
|
+
|
1477
|
+
# determine the 'layout'
|
1478
|
+
_aa_layout=`_appender_getLayoutByIndex ${_aa_index}`
|
1479
|
+
${__LOG4SH_TRACE} "_aa_layout='${_aa_layout}'"
|
1480
|
+
case ${_aa_layout} in
|
1481
|
+
${__LOG4SH_LAYOUT_SIMPLE}|\
|
1482
|
+
${__LOG4SH_LAYOUT_HTML})
|
1483
|
+
${__LOG4SH_DEBUG} 'using simple/html layout'
|
1484
|
+
echo " _la_layout=\"\${_la_level} - \${_la_message}\""
|
1485
|
+
;;
|
1486
|
+
|
1487
|
+
${__LOG4SH_LAYOUT_PATTERN})
|
1488
|
+
${__LOG4SH_DEBUG} 'using pattern layout'
|
1489
|
+
_aa_pattern=`_appender_getPatternByIndex ${_aa_index}`
|
1490
|
+
echo " _la_layout=\`_appender_parsePattern '${_aa_pattern}' \${_la_level} \"\${_la_message}\"\`"
|
1491
|
+
;;
|
1492
|
+
esac
|
1493
|
+
|
1494
|
+
# what appender 'type' do we have? TODO check not missing
|
1495
|
+
_aa_type=`_appender_getTypeByIndex ${_aa_index}`
|
1496
|
+
${__LOG4SH_TRACE} "_aa_type='${_aa_type}'"
|
1497
|
+
case ${_aa_type} in
|
1498
|
+
${__LOG4SH_TYPE_CONSOLE})
|
1499
|
+
echo " echo \"\${_la_layout}\""
|
1500
|
+
;;
|
1501
|
+
|
1502
|
+
${__LOG4SH_TYPE_FILE}|\
|
1503
|
+
${__LOG4SH_TYPE_ROLLING_FILE}|\
|
1504
|
+
${__LOG4SH_TYPE_DAILY_ROLLING_FILE})
|
1505
|
+
_aa_file=`_appender_file_getFileByIndex ${_aa_index}`
|
1506
|
+
${__LOG4SH_TRACE} "_aa_file='${_aa_file}'"
|
1507
|
+
if [ "${_aa_file}" = 'STDERR' ]; then
|
1508
|
+
echo " echo \"\${_la_layout}\" >&2"
|
1509
|
+
elif [ "${_aa_file}" != "${__LOG4SH_NULL}" ]; then
|
1510
|
+
# do rotation
|
1511
|
+
case ${_aa_type} in
|
1512
|
+
${__LOG4SH_TYPE_ROLLING_FILE})
|
1513
|
+
# check whether the max file size has been exceeded
|
1514
|
+
_aa_rotIndex=`appender_file_getMaxBackupIndex ${_aa_appender}`
|
1515
|
+
_aa_rotSize=`appender_file_getMaxFileSize ${_aa_appender}`
|
1516
|
+
cat <<EOF
|
1517
|
+
_la_rotSize=${_aa_rotSize}
|
1518
|
+
_la_size=\`wc -c '${_aa_file}' |awk '{print \$1}'\`
|
1519
|
+
if [ \${_la_size} -ge \${_la_rotSize} ]; then
|
1520
|
+
if [ ${_aa_rotIndex} -gt 0 ]; then
|
1521
|
+
# rotate the appender file(s)
|
1522
|
+
_la_rotIndex=`expr ${_aa_rotIndex} - 1`
|
1523
|
+
_la_rotFile="${_aa_file}.\${_la_rotIndex}"
|
1524
|
+
[ -f "\${_la_rotFile}" ] && rm -f "\${_la_rotFile}"
|
1525
|
+
while [ \${_la_rotIndex} -gt 0 ]; do
|
1526
|
+
_la_rotFileLast="\${_la_rotFile}"
|
1527
|
+
_la_rotIndex=\`expr \${_la_rotIndex} - 1\`
|
1528
|
+
_la_rotFile="${_aa_file}.\${_la_rotIndex}"
|
1529
|
+
[ -f "\${_la_rotFile}" ] && mv -f "\${_la_rotFile}" "\${_la_rotFileLast}"
|
1530
|
+
done
|
1531
|
+
mv -f '${_aa_file}' "\${_la_rotFile}"
|
1532
|
+
else
|
1533
|
+
# keep no backups; truncate the file
|
1534
|
+
cp /dev/null "${_aa_file}"
|
1535
|
+
fi
|
1536
|
+
unset _la_rotFile _la_rotFileLast _la_rotIndex
|
1537
|
+
fi
|
1538
|
+
unset _la_rotSize _la_size
|
1539
|
+
EOF
|
1540
|
+
;;
|
1541
|
+
${__LOG4SH_TYPE_DAILY_ROLLING_FILE})
|
1542
|
+
;;
|
1543
|
+
esac
|
1544
|
+
echo " echo \"\${_la_layout}\" >>'${_aa_file}'"
|
1545
|
+
else
|
1546
|
+
# the file "${__LOG4SH_NULL}" is closed?? Why did we get here, and why
|
1547
|
+
# did I care when I wrote this bit of code?
|
1548
|
+
:
|
1549
|
+
fi
|
1550
|
+
|
1551
|
+
unset _aa_file
|
1552
|
+
;;
|
1553
|
+
|
1554
|
+
${__LOG4SH_TYPE_SMTP})
|
1555
|
+
_aa_smtpTo=`appender_smtp_getTo ${_aa_appender}`
|
1556
|
+
_aa_smtpSubject=`appender_smtp_getSubject ${_aa_appender}`
|
1557
|
+
|
1558
|
+
cat <<EOF
|
1559
|
+
echo "\${_la_layout}" |\\
|
1560
|
+
${__log4sh_alternative_mail} -s "${_aa_smtpSubject}" ${_aa_smtpTo}
|
1561
|
+
EOF
|
1562
|
+
;;
|
1563
|
+
|
1564
|
+
${__LOG4SH_TYPE_SYSLOG})
|
1565
|
+
cat <<EOF
|
1566
|
+
case "\${_la_level}" in
|
1567
|
+
${__LOG4SH_LEVEL_TRACE_STR}) _la_tag='debug' ;; # no 'trace' equivalent
|
1568
|
+
${__LOG4SH_LEVEL_DEBUG_STR}) _la_tag='debug' ;;
|
1569
|
+
${__LOG4SH_LEVEL_INFO_STR}) _la_tag='info' ;;
|
1570
|
+
${__LOG4SH_LEVEL_WARN_STR}) _la_tag='warning' ;; # 'warn' is deprecated
|
1571
|
+
${__LOG4SH_LEVEL_ERROR_STR}) _la_tag='err' ;; # 'error' is deprecated
|
1572
|
+
${__LOG4SH_LEVEL_FATAL_STR}) _la_tag='alert' ;;
|
1573
|
+
esac
|
1574
|
+
EOF
|
1575
|
+
|
1576
|
+
_aa_facilityName=`appender_syslog_getFacility ${_aa_appender}`
|
1577
|
+
_aa_syslogHost=`appender_syslog_getHost ${_aa_appender}`
|
1578
|
+
_aa_hostname=`hostname |sed 's/^\([^.]*\)\..*/\1/'`
|
1579
|
+
|
1580
|
+
# are we logging to a remote host?
|
1581
|
+
if [ -z "${_aa_syslogHost}" ]; then
|
1582
|
+
# no -- use logger
|
1583
|
+
cat <<EOF
|
1584
|
+
( exec logger -p "${_aa_facilityName}.\${_la_tag}" \
|
1585
|
+
-t "${__log4sh_filename}[$$]" "\${_la_layout}" 2>/dev/null )
|
1586
|
+
unset _la_tag
|
1587
|
+
EOF
|
1588
|
+
else
|
1589
|
+
# yes -- use netcat
|
1590
|
+
if [ -n "${__log4sh_alternative_nc:-}" ]; then
|
1591
|
+
case ${_aa_facilityName} in
|
1592
|
+
kern) _aa_facilityCode=0 ;; # 0<<3
|
1593
|
+
user) _aa_facilityCode=8 ;; # 1<<3
|
1594
|
+
mail) _aa_facilityCode=16 ;; # 2<<3
|
1595
|
+
daemon) _aa_facilityCode=24 ;; # 3<<3
|
1596
|
+
auth|security) _aa_facilityCode=32 ;; # 4<<3
|
1597
|
+
syslog) _aa_facilityCode=40 ;; # 5<<3
|
1598
|
+
lpr) _aa_facilityCode=48 ;; # 6<<3
|
1599
|
+
news) _aa_facilityCode=56 ;; # 7<<3
|
1600
|
+
uucp) _aa_facilityCode=64 ;; # 8<<3
|
1601
|
+
cron) _aa_facilityCode=72 ;; # 9<<3
|
1602
|
+
authpriv) _aa_facilityCode=80 ;; # 10<<3
|
1603
|
+
ftp) _aa_facilityCode=88 ;; # 11<<3
|
1604
|
+
local0) _aa_facilityCode=128 ;; # 16<<3
|
1605
|
+
local1) _aa_facilityCode=136 ;; # 17<<3
|
1606
|
+
local2) _aa_facilityCode=144 ;; # 18<<3
|
1607
|
+
local3) _aa_facilityCode=152 ;; # 19<<3
|
1608
|
+
local4) _aa_facilityCode=160 ;; # 20<<3
|
1609
|
+
local5) _aa_facilityCode=168 ;; # 21<<3
|
1610
|
+
local6) _aa_facilityCode=176 ;; # 22<<3
|
1611
|
+
local7) _aa_facilityCode=184 ;; # 23<<3
|
1612
|
+
esac
|
1613
|
+
|
1614
|
+
cat <<EOF
|
1615
|
+
case \${_la_tag} in
|
1616
|
+
alert) _la_priority=1 ;;
|
1617
|
+
err|error) _la_priority=3 ;;
|
1618
|
+
warning|warn) _la_priority=4 ;;
|
1619
|
+
info) _la_priority=6 ;;
|
1620
|
+
debug) _la_priority=7 ;;
|
1621
|
+
esac
|
1622
|
+
_la_priority=\`expr ${_aa_facilityCode} + \${_la_priority}\`
|
1623
|
+
_la_date=\`date "+%b %d %H:%M:%S"\`
|
1624
|
+
_la_hostname='${_aa_hostname}'
|
1625
|
+
|
1626
|
+
_la_syslogMsg="<\${_la_priority}>\${_la_date} \${_la_hostname} \${_la_layout}"
|
1627
|
+
|
1628
|
+
# do RFC 3164 cleanups
|
1629
|
+
_la_date=\`echo \"\${_la_date}\" |sed 's/ 0\([0-9]\) / \1 /'\`
|
1630
|
+
_la_syslogMsg=\`echo "\${_la_syslogMsg}" |cut -b1-1024\`
|
1631
|
+
|
1632
|
+
( echo "\${_la_syslogMsg}" |\
|
1633
|
+
exec ${__log4sh_alternative_nc} ${__log4sh_alternative_nc_opts} -w 1 -u \
|
1634
|
+
${_aa_syslogHost} 514 )
|
1635
|
+
unset _la_tag _la_priority _la_date _la_hostname _la_syslogMsg
|
1636
|
+
EOF
|
1637
|
+
unset _aa_facilityCode _aa_syslogHost _aa_hostname
|
1638
|
+
else
|
1639
|
+
# no netcat alternative set; doing nothing
|
1640
|
+
:
|
1641
|
+
fi
|
1642
|
+
fi
|
1643
|
+
unset _aa_facilityName
|
1644
|
+
;;
|
1645
|
+
|
1646
|
+
*) _log4sh_error "unrecognized appender type (${_aa_type})" ;;
|
1647
|
+
esac
|
1648
|
+
|
1649
|
+
# footer
|
1650
|
+
cat <<EOF
|
1651
|
+
unset _la_level _la_message _la_layout
|
1652
|
+
}
|
1653
|
+
EOF
|
1654
|
+
|
1655
|
+
# override the activateOptions function as we don't need it anymore
|
1656
|
+
cat <<EOF
|
1657
|
+
${__LOG4SH_APPENDER_FUNC_PREFIX}${_aa_appender}_activateOptions() { :; }
|
1658
|
+
EOF
|
1659
|
+
|
1660
|
+
# restore STDOUT
|
1661
|
+
exec 1>&4 4>&-
|
1662
|
+
|
1663
|
+
# source the newly created function
|
1664
|
+
${__LOG4SH_TRACE} 're-sourcing the newly created function'
|
1665
|
+
. "${_aa_inc}"
|
1666
|
+
|
1667
|
+
unset _aa_appender _aa_inc _aa_layout _aa_pattern _aa_type
|
1668
|
+
}
|
1669
|
+
|
1670
|
+
#-----------------------------------------------------------------------------
|
1671
|
+
# FileAppender
|
1672
|
+
#
|
1673
|
+
|
1674
|
+
#/**
|
1675
|
+
# <s:function group="FileAppender" modifier="private">
|
1676
|
+
# <entry align="right">
|
1677
|
+
# <code>string</code>
|
1678
|
+
# </entry>
|
1679
|
+
# <entry>
|
1680
|
+
# <funcsynopsis>
|
1681
|
+
# <funcprototype>
|
1682
|
+
# <funcdef><function>_appender_file_getFileByIndex</function></funcdef>
|
1683
|
+
# <paramdef>integer <parameter>index</parameter></paramdef>
|
1684
|
+
# </funcprototype>
|
1685
|
+
# </funcsynopsis>
|
1686
|
+
# <para>Get the filename of a FileAppender at the given array index</para>
|
1687
|
+
# <funcsynopsis>
|
1688
|
+
# <funcsynopsisinfo>_appender_file_getFileByIndex 3</funcsynopsisinfo>
|
1689
|
+
# </funcsynopsis>
|
1690
|
+
# </entry>
|
1691
|
+
# </s:function>
|
1692
|
+
#*/
|
1693
|
+
_appender_file_getFileByIndex()
|
1694
|
+
{
|
1695
|
+
_log4sh_getArrayElement "${__log4shAppender_file_files}" $1
|
1696
|
+
}
|
1697
|
+
|
1698
|
+
#/**
|
1699
|
+
# <s:function group="FileAppender" modifier="public">
|
1700
|
+
# <entry align="right">
|
1701
|
+
# <code>string</code>
|
1702
|
+
# </entry>
|
1703
|
+
# <entry>
|
1704
|
+
# <funcsynopsis>
|
1705
|
+
# <funcprototype>
|
1706
|
+
# <funcdef><function>appender_file_getFile</function></funcdef>
|
1707
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
1708
|
+
# </funcprototype>
|
1709
|
+
# </funcsynopsis>
|
1710
|
+
# <para>Get the filename of a FileAppender</para>
|
1711
|
+
# <funcsynopsis>
|
1712
|
+
# <funcsynopsisinfo>appender_file_getFile myAppender</funcsynopsisinfo>
|
1713
|
+
# </funcsynopsis>
|
1714
|
+
# </entry>
|
1715
|
+
# </s:function>
|
1716
|
+
#*/
|
1717
|
+
appender_file_getFile()
|
1718
|
+
{
|
1719
|
+
_index=`_log4sh_findArrayElement "$__log4shAppenders" $1`
|
1720
|
+
_log4sh_getArrayElement "$__log4shAppender_file_files" $_index
|
1721
|
+
unset _index
|
1722
|
+
}
|
1723
|
+
|
1724
|
+
#/**
|
1725
|
+
# <s:function group="FileAppender" modifier="public">
|
1726
|
+
# <entry align="right">
|
1727
|
+
# <emphasis>void</emphasis>
|
1728
|
+
# </entry>
|
1729
|
+
# <entry>
|
1730
|
+
# <funcsynopsis>
|
1731
|
+
# <funcprototype>
|
1732
|
+
# <funcdef><function>appender_file_setFile</function></funcdef>
|
1733
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
1734
|
+
# <paramdef>string <parameter>filename</parameter></paramdef>
|
1735
|
+
# </funcprototype>
|
1736
|
+
# </funcsynopsis>
|
1737
|
+
# <para>
|
1738
|
+
# Set the filename for a FileAppender (e.g. <filename>STDERR</filename> or
|
1739
|
+
# <filename>/var/log/log4sh.log</filename>).
|
1740
|
+
# </para>
|
1741
|
+
# <funcsynopsis>
|
1742
|
+
# <funcsynopsisinfo>appender_file_setFile myAppender STDERR</funcsynopsisinfo>
|
1743
|
+
# </funcsynopsis>
|
1744
|
+
# </entry>
|
1745
|
+
# </s:function>
|
1746
|
+
#*/
|
1747
|
+
appender_file_setFile()
|
1748
|
+
{
|
1749
|
+
afsf_appender=$1
|
1750
|
+
afsf_file=$2
|
1751
|
+
${__LOG4SH_TRACE} "afsf_appender='${afsf_appender}' afsf_file='${afsf_file}'"
|
1752
|
+
|
1753
|
+
if [ -n "${afsf_appender}" -a -n "${afsf_file}" ]; then
|
1754
|
+
# set the file
|
1755
|
+
_index=`_log4sh_findArrayElement "${__log4shAppenders}" ${afsf_appender}`
|
1756
|
+
__log4shAppender_file_files=`_log4sh_setArrayElement \
|
1757
|
+
"${__log4shAppender_file_files}" ${_index} "${afsf_file}"`
|
1758
|
+
_return=$?
|
1759
|
+
|
1760
|
+
# create the file (if it isn't already)
|
1761
|
+
if [ ${_return} -eq ${__LOG4SH_TRUE} \
|
1762
|
+
-a ! "${afsf_file}" '=' "${__LOG4SH_NULL}" \
|
1763
|
+
-a ! "${afsf_file}" '=' 'STDERR' \
|
1764
|
+
-a ! -f "${afsf_file}" \
|
1765
|
+
]; then
|
1766
|
+
touch "${afsf_file}" 2>/dev/null
|
1767
|
+
_result=$?
|
1768
|
+
# determine success of touch command
|
1769
|
+
if [ ${_result} -eq 1 ]; then
|
1770
|
+
_log4sh_error "appender_file_setFile(): could not create file (${afsf_file}); closing appender"
|
1771
|
+
appender_setLevel ${afsf_appender} ${__LOG4SH_LEVEL_CLOSED_STR}
|
1772
|
+
fi
|
1773
|
+
unset _result
|
1774
|
+
fi
|
1775
|
+
else
|
1776
|
+
_log4sh_error 'appender_file_setFile(): missing appender and/or file'
|
1777
|
+
_return=${__LOG4SH_FALSE}
|
1778
|
+
fi
|
1779
|
+
|
1780
|
+
# resource the appender
|
1781
|
+
_appender_cache ${afsf_appender}
|
1782
|
+
|
1783
|
+
unset afsf_appender afsf_file _index
|
1784
|
+
return ${_return}
|
1785
|
+
}
|
1786
|
+
|
1787
|
+
#/**
|
1788
|
+
# <s:function group="FileAppender" modifier="public">
|
1789
|
+
# <entry align="right">
|
1790
|
+
# <emphasis>void</emphasis>
|
1791
|
+
# </entry>
|
1792
|
+
# <entry>
|
1793
|
+
# <funcsynopsis>
|
1794
|
+
# <funcprototype>
|
1795
|
+
# <funcdef><function>appender_setAppenderFile</function></funcdef>
|
1796
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
1797
|
+
# <paramdef>string <parameter>filename</parameter></paramdef>
|
1798
|
+
# </funcprototype>
|
1799
|
+
# </funcsynopsis>
|
1800
|
+
# <para><emphasis role="strong">Deprecated as of 1.3.2</emphasis></para>
|
1801
|
+
# <para>
|
1802
|
+
# Set the filename for a FileAppender (e.g. "STDERR" or
|
1803
|
+
# "/var/log/log4sh.log")
|
1804
|
+
# </para>
|
1805
|
+
# <funcsynopsis>
|
1806
|
+
# <funcsynopsisinfo>appender_setAppenderFile myAppender STDERR</funcsynopsisinfo>
|
1807
|
+
# </funcsynopsis>
|
1808
|
+
# </entry>
|
1809
|
+
# </s:function>
|
1810
|
+
#*/
|
1811
|
+
appender_setAppenderFile()
|
1812
|
+
{
|
1813
|
+
appender_file_setFile "$@"
|
1814
|
+
}
|
1815
|
+
|
1816
|
+
#/**
|
1817
|
+
# <s:function group="FileAppender" modifier="public">
|
1818
|
+
# <entry align="right">
|
1819
|
+
# <code>integer</code>/boolean
|
1820
|
+
# </entry>
|
1821
|
+
# <entry>
|
1822
|
+
# <funcsynopsis>
|
1823
|
+
# <funcprototype>
|
1824
|
+
# <funcdef><function>appender_file_getMaxBackupIndex</function></funcdef>
|
1825
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
1826
|
+
# </funcprototype>
|
1827
|
+
# </funcsynopsis>
|
1828
|
+
# <para>
|
1829
|
+
# Returns the value of the MaxBackupIndex option.
|
1830
|
+
# </para>
|
1831
|
+
# <para><emphasis role="strong">Since:</emphasis> 1.3.7</para>
|
1832
|
+
# <funcsynopsis>
|
1833
|
+
# <funcsynopsisinfo>appender_file_getMaxBackupIndex myAppender</funcsynopsisinfo>
|
1834
|
+
# </funcsynopsis>
|
1835
|
+
# </entry>
|
1836
|
+
# </s:function>
|
1837
|
+
#*/
|
1838
|
+
appender_file_getMaxBackupIndex()
|
1839
|
+
{
|
1840
|
+
if [ $# -ne 1 ]; then
|
1841
|
+
_log4sh_error 'appender_file_getMaxBackupIndex(): invalid number of parameters'
|
1842
|
+
return ${__LOG4SH_FALSE}
|
1843
|
+
fi
|
1844
|
+
|
1845
|
+
afgmbi_appender=$1
|
1846
|
+
|
1847
|
+
afgmbi_index=`_log4sh_findArrayElement \
|
1848
|
+
"${__log4shAppenders}" ${afgmbi_appender}`
|
1849
|
+
# TODO: put check for valid index here
|
1850
|
+
_log4sh_getArrayElement \
|
1851
|
+
"${__log4shAppender_rollingFile_maxBackupIndexes}" ${afgmbi_index}
|
1852
|
+
__log4sh_return=$?
|
1853
|
+
|
1854
|
+
unset afgmbi_appender afgmbi_index
|
1855
|
+
return ${__log4sh_return}
|
1856
|
+
}
|
1857
|
+
|
1858
|
+
#/**
|
1859
|
+
# <s:function group="FileAppender" modifier="public">
|
1860
|
+
# <entry align="right">
|
1861
|
+
# <emphasis>void</emphasis>
|
1862
|
+
# </entry>
|
1863
|
+
# <entry>
|
1864
|
+
# <funcsynopsis>
|
1865
|
+
# <funcprototype>
|
1866
|
+
# <funcdef><function>appender_file_setMaxBackupIndex</function></funcdef>
|
1867
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
1868
|
+
# <paramdef>integer <parameter>index</parameter></paramdef>
|
1869
|
+
# </funcprototype>
|
1870
|
+
# </funcsynopsis>
|
1871
|
+
# <para>Set the maximum number of backup files to keep around.</para>
|
1872
|
+
# <para>
|
1873
|
+
# The <emphasis role="strong">MaxBackupIndex</emphasis> option determines
|
1874
|
+
# how many backup files are kept before the oldest is erased. This option
|
1875
|
+
# takes a positive integer value. If set to zero, then there will be no
|
1876
|
+
# backup files and the log file will be truncated when it reaches
|
1877
|
+
# <option>MaxFileSize</option>.
|
1878
|
+
# </para>
|
1879
|
+
# <para><emphasis role="strong">Since:</emphasis> 1.3.7</para>
|
1880
|
+
# <funcsynopsis>
|
1881
|
+
# <funcsynopsisinfo>appender_file_setMaxBackupIndex myAppender 3</funcsynopsisinfo>
|
1882
|
+
# </funcsynopsis>
|
1883
|
+
# </entry>
|
1884
|
+
# </s:function>
|
1885
|
+
#*/
|
1886
|
+
appender_file_setMaxBackupIndex()
|
1887
|
+
{
|
1888
|
+
if [ $# -ne 2 ]; then
|
1889
|
+
_log4sh_error "appender_file_setMaxBackupIndex(): invalid number of parameters ($#)"
|
1890
|
+
return ${__LOG4SH_FALSE}
|
1891
|
+
fi
|
1892
|
+
|
1893
|
+
afsmbi_appender=$1
|
1894
|
+
afsmbi_maxIndex=$2
|
1895
|
+
|
1896
|
+
# TODO: put check for valid input
|
1897
|
+
|
1898
|
+
afsmbi_index=`_log4sh_findArrayElement \
|
1899
|
+
"${__log4shAppenders}" ${afsmbi_appender}`
|
1900
|
+
# TODO: put check for valid index here
|
1901
|
+
__log4shAppender_rollingFile_maxBackupIndexes=`_log4sh_setArrayElement \
|
1902
|
+
"${__log4shAppender_rollingFile_maxBackupIndexes}" ${afsmbi_index} \
|
1903
|
+
"${afsmbi_maxIndex}"`
|
1904
|
+
__log4sh_return=$?
|
1905
|
+
|
1906
|
+
# re-source the appender
|
1907
|
+
_appender_cache ${afsmbi_appender}
|
1908
|
+
|
1909
|
+
unset afsmbi_appender afsmbi_maxIndex afsmbi_index
|
1910
|
+
return ${__log4sh_return}
|
1911
|
+
}
|
1912
|
+
|
1913
|
+
#/**
|
1914
|
+
# <s:function group="FileAppender" modifier="public">
|
1915
|
+
# <entry align="right">
|
1916
|
+
# <code>integer</code>/boolean
|
1917
|
+
# </entry>
|
1918
|
+
# <entry>
|
1919
|
+
# <funcsynopsis>
|
1920
|
+
# <funcprototype>
|
1921
|
+
# <funcdef><function>appender_file_getMaxFileSize</function></funcdef>
|
1922
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
1923
|
+
# </funcprototype>
|
1924
|
+
# </funcsynopsis>
|
1925
|
+
# <para>
|
1926
|
+
# Get the maximum size that the output file is allowed to reach before
|
1927
|
+
# being rolled over to backup files.
|
1928
|
+
# </para>
|
1929
|
+
# <para><emphasis role="strong">Since:</emphasis> 1.3.7</para>
|
1930
|
+
# <funcsynopsis>
|
1931
|
+
# <funcsynopsisinfo>maxSize=`appender_file_getMaxBackupSize myAppender`</funcsynopsisinfo>
|
1932
|
+
# </funcsynopsis>
|
1933
|
+
# </entry>
|
1934
|
+
# </s:function>
|
1935
|
+
#*/
|
1936
|
+
appender_file_getMaxFileSize()
|
1937
|
+
{
|
1938
|
+
if [ $# -ne 1 ]; then
|
1939
|
+
_log4sh_error "appender_file_getMaxFileSize(): invalid number of parameters ($#)"
|
1940
|
+
return ${__LOG4SH_FALSE}
|
1941
|
+
fi
|
1942
|
+
|
1943
|
+
afgmfs_appender=$1
|
1944
|
+
|
1945
|
+
afgmfs_index=`_log4sh_findArrayElement \
|
1946
|
+
"${__log4shAppenders}" ${afgmfs_appender}`
|
1947
|
+
# TODO: put check for valid index here
|
1948
|
+
_log4sh_getArrayElement \
|
1949
|
+
"${__log4shAppender_rollingFile_maxFileSizes}" ${afgmfs_index}
|
1950
|
+
__log4sh_return=$?
|
1951
|
+
|
1952
|
+
unset afgmfs_appender afgmfs_index
|
1953
|
+
return ${__log4sh_return}
|
1954
|
+
}
|
1955
|
+
|
1956
|
+
#/**
|
1957
|
+
# <s:function group="FileAppender" modifier="public">
|
1958
|
+
# <entry align="right">
|
1959
|
+
# <emphasis>void</emphasis>/boolean
|
1960
|
+
# </entry>
|
1961
|
+
# <entry>
|
1962
|
+
# <funcsynopsis>
|
1963
|
+
# <funcprototype>
|
1964
|
+
# <funcdef><function>appender_file_setMaxFileSize</function></funcdef>
|
1965
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
1966
|
+
# <paramdef>string <parameter>size</parameter></paramdef>
|
1967
|
+
# </funcprototype>
|
1968
|
+
# </funcsynopsis>
|
1969
|
+
# <para>
|
1970
|
+
# Set the maximum size that the output file is allowed to reach before
|
1971
|
+
# being rolled over to backup files.
|
1972
|
+
# </para>
|
1973
|
+
# <para>
|
1974
|
+
# In configuration files, the <option>MaxFileSize</option> option takes an
|
1975
|
+
# long integer in the range 0 - 2^40. You can specify the value with the
|
1976
|
+
# suffixes "KiB", "MiB" or "GiB" so that the integer is interpreted being
|
1977
|
+
# expressed respectively in kilobytes, megabytes or gigabytes. For example,
|
1978
|
+
# the value "10KiB" will be interpreted as 10240.
|
1979
|
+
# </para>
|
1980
|
+
# <para><emphasis role="strong">Since:</emphasis> 1.3.7</para>
|
1981
|
+
# <funcsynopsis>
|
1982
|
+
# <funcsynopsisinfo>appender_file_setMaxBackupSize myAppender 10KiB</funcsynopsisinfo>
|
1983
|
+
# </funcsynopsis>
|
1984
|
+
# </entry>
|
1985
|
+
# </s:function>
|
1986
|
+
#*/
|
1987
|
+
appender_file_setMaxFileSize()
|
1988
|
+
{
|
1989
|
+
if [ $# -ne 2 ]; then
|
1990
|
+
_log4sh_error \
|
1991
|
+
"appender_file_setMaxFileSize(): invalid number of parameters ($#)"
|
1992
|
+
return ${__LOG4SH_ERROR}
|
1993
|
+
fi
|
1994
|
+
|
1995
|
+
afsmfs_appender=$1
|
1996
|
+
afsmfs_size=$2
|
1997
|
+
afsmfs_return=${__LOG4SH_TRUE}
|
1998
|
+
|
1999
|
+
# split the file size into parts
|
2000
|
+
afsmfs_value=`expr ${afsmfs_size} : '\([0-9]*\)'`
|
2001
|
+
afsmfs_unit=`expr ${afsmfs_size} : '[0-9]* *\([A-Za-z]\{1,3\}\)'`
|
2002
|
+
|
2003
|
+
# determine multiplier
|
2004
|
+
if [ ${__log4sh_wa_strictBehavior} -eq ${__LOG4SH_TRUE} ]; then
|
2005
|
+
case "${afsmfs_unit}" in
|
2006
|
+
KB) afsmfs_unit='KiB' ;;
|
2007
|
+
MB) afsmfs_unit='MiB' ;;
|
2008
|
+
GB) afsmfs_unit='GiB' ;;
|
2009
|
+
TB) afsmfs_unit='TiB' ;;
|
2010
|
+
esac
|
2011
|
+
fi
|
2012
|
+
case "${afsmfs_unit}" in
|
2013
|
+
B) afsmfs_mul=1 ;;
|
2014
|
+
KB) afsmfs_mul=1000 ;;
|
2015
|
+
KiB) afsmfs_mul=1024 ;;
|
2016
|
+
MB) afsmfs_mul=1000000 ;;
|
2017
|
+
MiB) afsmfs_mul=1048576 ;;
|
2018
|
+
GB) afsmfs_mul=1000000000 ;;
|
2019
|
+
GiB) afsmfs_mul=1073741824 ;;
|
2020
|
+
TB) afsmfs_mul=1000000000000 ;;
|
2021
|
+
TiB) afsmfs_mul=1099511627776 ;;
|
2022
|
+
'')
|
2023
|
+
_log4sh_warn 'missing file size unit; assuming bytes'
|
2024
|
+
afsmfs_mul=1
|
2025
|
+
;;
|
2026
|
+
*)
|
2027
|
+
_log4sh_error "unrecognized file size unit '${afsmfs_unit}'"
|
2028
|
+
afsmfs_return=${__LOG4SH_ERROR}
|
2029
|
+
;;
|
2030
|
+
esac
|
2031
|
+
|
2032
|
+
# calculate maximum file size
|
2033
|
+
if [ ${afsmfs_return} -eq ${__LOG4SH_TRUE} ]; then
|
2034
|
+
afsmfs_maxFileSize=`(expr ${afsmfs_value} \* ${afsmfs_mul} 2>&1)`
|
2035
|
+
if [ $? -gt 0 ]; then
|
2036
|
+
_log4sh_error "problem calculating maximum file size: '${afsmfs_maxFileSize}'"
|
2037
|
+
afsmfs_return=${__LOG4SH_FALSE}
|
2038
|
+
fi
|
2039
|
+
fi
|
2040
|
+
|
2041
|
+
# store the maximum file size
|
2042
|
+
if [ ${afsmfs_return} -eq ${__LOG4SH_TRUE} ]; then
|
2043
|
+
afsmfs_index=`_log4sh_findArrayElement \
|
2044
|
+
"${__log4shAppenders}" ${afsmfs_appender}`
|
2045
|
+
# TODO: put check for valid index here
|
2046
|
+
__log4shAppender_rollingFile_maxFileSizes=`_log4sh_setArrayElement \
|
2047
|
+
"${__log4shAppender_rollingFile_maxFileSizes}" ${afsmfs_index} \
|
2048
|
+
"${afsmfs_maxFileSize}"`
|
2049
|
+
fi
|
2050
|
+
|
2051
|
+
# re-source the appender
|
2052
|
+
[ ${afsmfs_return} -eq ${__LOG4SH_TRUE} ] \
|
2053
|
+
&& _appender_cache ${afsmfs_appender}
|
2054
|
+
|
2055
|
+
__log4sh_return=${afsmfs_return}
|
2056
|
+
unset afsmfs_appender afsmfs_size afsmfs_value afsmfs_unit afsmfs_mul \
|
2057
|
+
afsmfs_maxFileSize afsmfs_index afsmfs_return
|
2058
|
+
return ${__log4sh_return}
|
2059
|
+
}
|
2060
|
+
|
2061
|
+
#-----------------------------------------------------------------------------
|
2062
|
+
# SMTPAppender
|
2063
|
+
#
|
2064
|
+
|
2065
|
+
#/**
|
2066
|
+
# <s:function group="SMTPAppender" modifier="public">
|
2067
|
+
# <entry align="right">
|
2068
|
+
# <code>string</code>/boolean
|
2069
|
+
# </entry>
|
2070
|
+
# <entry>
|
2071
|
+
# <funcsynopsis>
|
2072
|
+
# <funcprototype>
|
2073
|
+
# <funcdef><function>appender_smtp_getTo</function></funcdef>
|
2074
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
2075
|
+
# </funcprototype>
|
2076
|
+
# </funcsynopsis>
|
2077
|
+
# <para>Get the to address for the given appender</para>
|
2078
|
+
# <funcsynopsis>
|
2079
|
+
# <funcsynopsisinfo>email=`appender_smtp_getTo myAppender`</funcsynopsisinfo>
|
2080
|
+
# </funcsynopsis>
|
2081
|
+
# </entry>
|
2082
|
+
# </s:function>
|
2083
|
+
#*/
|
2084
|
+
appender_smtp_getTo()
|
2085
|
+
{
|
2086
|
+
if [ $# -ne 1 ]; then
|
2087
|
+
_log4sh_error 'appender_smtp_getTo(): invalid number of parameters'
|
2088
|
+
return ${__LOG4SH_FALSE}
|
2089
|
+
fi
|
2090
|
+
|
2091
|
+
asgt_appender=$1
|
2092
|
+
|
2093
|
+
asgt_index=`_log4sh_findArrayElement "${__log4shAppenders}" ${asgt_appender}`
|
2094
|
+
# TODO: put check for valid index here
|
2095
|
+
asgt_to=`_log4sh_getArrayElement \
|
2096
|
+
"${__log4shAppender_smtp_tos}" ${asgt_index}`
|
2097
|
+
__log4sh_return=$?
|
2098
|
+
|
2099
|
+
[ "${asgt_to}" = "${__LOG4SH_NULL}" ] && asgt_to=''
|
2100
|
+
echo "${asgt_to}"
|
2101
|
+
|
2102
|
+
unset asgt_appender asgt_index asgt_to
|
2103
|
+
return ${__log4sh_return}
|
2104
|
+
}
|
2105
|
+
|
2106
|
+
#/**
|
2107
|
+
# <s:function group="SMTPAppender" modifier="public">
|
2108
|
+
# <entry align="right">
|
2109
|
+
# <emphasis>void</emphasis>/boolean
|
2110
|
+
# </entry>
|
2111
|
+
# <entry>
|
2112
|
+
# <funcsynopsis>
|
2113
|
+
# <funcprototype>
|
2114
|
+
# <funcdef><function>appender_smtp_setTo</function></funcdef>
|
2115
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
2116
|
+
# <paramdef>string <parameter>email</parameter></paramdef>
|
2117
|
+
# </funcprototype>
|
2118
|
+
# </funcsynopsis>
|
2119
|
+
# <para>Set the to address for the given appender</para>
|
2120
|
+
# <funcsynopsis>
|
2121
|
+
# <funcsynopsisinfo>appender_smtp_setTo myAppender user@example.com</funcsynopsisinfo>
|
2122
|
+
# </funcsynopsis>
|
2123
|
+
# </entry>
|
2124
|
+
# </s:function>
|
2125
|
+
#*/
|
2126
|
+
appender_smtp_setTo()
|
2127
|
+
{
|
2128
|
+
if [ $# -ne 2 ]; then
|
2129
|
+
_log4sh_error 'appender_smtp_setTo(): invalid number of parameters'
|
2130
|
+
return ${__LOG4SH_FALSE}
|
2131
|
+
fi
|
2132
|
+
|
2133
|
+
asst_appender=$1
|
2134
|
+
asst_email=$2
|
2135
|
+
|
2136
|
+
asst_index=`_log4sh_findArrayElement "${__log4shAppenders}" ${asst_appender}`
|
2137
|
+
# TODO: put check for valid index here
|
2138
|
+
__log4shAppender_smtp_tos=`_log4sh_setArrayElement \
|
2139
|
+
"${__log4shAppender_smtp_tos}" ${asst_index} "${asst_email}"`
|
2140
|
+
|
2141
|
+
# resource the appender
|
2142
|
+
_appender_cache ${asst_appender}
|
2143
|
+
|
2144
|
+
unset asst_appender asst_email asst_index
|
2145
|
+
}
|
2146
|
+
|
2147
|
+
#/**
|
2148
|
+
# <s:function group="SMTPAppender" modifier="public">
|
2149
|
+
# <entry align="right">
|
2150
|
+
# <emphasis>void</emphasis>
|
2151
|
+
# </entry>
|
2152
|
+
# <entry>
|
2153
|
+
# <funcsynopsis>
|
2154
|
+
# <funcprototype>
|
2155
|
+
# <funcdef><function>appender_setAppenderRecipient</function></funcdef>
|
2156
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
2157
|
+
# <paramdef>string <parameter>email</parameter></paramdef>
|
2158
|
+
# </funcprototype>
|
2159
|
+
# </funcsynopsis>
|
2160
|
+
# <para><emphasis role="strong">Deprecated as of 1.3.1</emphasis></para>
|
2161
|
+
# <para>
|
2162
|
+
# Set the to address for the given appender
|
2163
|
+
# </para>
|
2164
|
+
# <funcsynopsis>
|
2165
|
+
# <funcsynopsisinfo>appender_smtp_setTo myAppender user@example.com</funcsynopsisinfo>
|
2166
|
+
# </funcsynopsis>
|
2167
|
+
# </entry>
|
2168
|
+
# </s:function>
|
2169
|
+
#*/
|
2170
|
+
appender_setAppenderRecipient()
|
2171
|
+
{
|
2172
|
+
appender_smtp_setTo "$@"
|
2173
|
+
}
|
2174
|
+
|
2175
|
+
#/**
|
2176
|
+
# <s:function group="SMTPAppender" modifier="public">
|
2177
|
+
# <entry align="right">
|
2178
|
+
# <code>string</code>/boolean
|
2179
|
+
# </entry>
|
2180
|
+
# <entry>
|
2181
|
+
# <funcsynopsis>
|
2182
|
+
# <funcprototype>
|
2183
|
+
# <funcdef><function>appender_smtp_getSubject</function></funcdef>
|
2184
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
2185
|
+
# </funcprototype>
|
2186
|
+
# </funcsynopsis>
|
2187
|
+
# <para>Get the email subject for the given appender</para>
|
2188
|
+
# <funcsynopsis>
|
2189
|
+
# <funcsynopsisinfo>subject=`appender_smtp_getSubject myAppender`</funcsynopsisinfo>
|
2190
|
+
# </funcsynopsis>
|
2191
|
+
# </entry>
|
2192
|
+
# </s:function>
|
2193
|
+
#*/
|
2194
|
+
appender_smtp_getSubject()
|
2195
|
+
{
|
2196
|
+
if [ $# -ne 1 ]; then
|
2197
|
+
_log4sh_error 'appender_smtp_getSubject(): invalid number of parameters'
|
2198
|
+
return ${__LOG4SH_FALSE}
|
2199
|
+
fi
|
2200
|
+
|
2201
|
+
asgs_appender=$1
|
2202
|
+
|
2203
|
+
asgs_index=`_log4sh_findArrayElement "${__log4shAppenders}" ${asgs_appender}`
|
2204
|
+
# TODO: put check for valid index here
|
2205
|
+
asgs_subject=`_log4sh_getArrayElement \
|
2206
|
+
"${__log4shAppender_smtp_subjects}" ${asgs_index}`
|
2207
|
+
__log4sh_return=$?
|
2208
|
+
|
2209
|
+
[ "${asgs_subject}" = "${__LOG4SH_NULL}" ] && asgs_subject=''
|
2210
|
+
echo "${asgs_subject}"
|
2211
|
+
|
2212
|
+
unset asgs_appender asgs_index asgs_subject
|
2213
|
+
return ${__log4sh_return}
|
2214
|
+
}
|
2215
|
+
|
2216
|
+
#/**
|
2217
|
+
# <s:function group="SMTPAppender" modifier="public">
|
2218
|
+
# <entry align="right">
|
2219
|
+
# <emphasis>void</emphasis>/boolean
|
2220
|
+
# </entry>
|
2221
|
+
# <entry>
|
2222
|
+
# <funcsynopsis>
|
2223
|
+
# <funcprototype>
|
2224
|
+
# <funcdef><function>appender_smtp_setSubject</function></funcdef>
|
2225
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
2226
|
+
# <paramdef>string <parameter>subject</parameter></paramdef>
|
2227
|
+
# </funcprototype>
|
2228
|
+
# </funcsynopsis>
|
2229
|
+
# <para>Sets the email subject for an SMTP appender</para>
|
2230
|
+
# <funcsynopsis>
|
2231
|
+
# <funcsynopsisinfo>appender_smtp_setSubject myAppender "This is a test"</funcsynopsisinfo>
|
2232
|
+
# </funcsynopsis>
|
2233
|
+
# </entry>
|
2234
|
+
# </s:function>
|
2235
|
+
#*/
|
2236
|
+
appender_smtp_setSubject()
|
2237
|
+
{
|
2238
|
+
if [ $# -ne 2 ]; then
|
2239
|
+
_log4sh_error 'appender_smtp_setSubject(): invalid number of parameters'
|
2240
|
+
return ${__LOG4SH_FALSE}
|
2241
|
+
fi
|
2242
|
+
|
2243
|
+
asss_appender=$1
|
2244
|
+
asss_subject=$2
|
2245
|
+
|
2246
|
+
# set the Subject
|
2247
|
+
asss_index=`_log4sh_findArrayElement "${__log4shAppenders}" ${asss_appender}`
|
2248
|
+
if [ ${asss_index} -gt 0 ]; then
|
2249
|
+
__log4shAppender_smtp_subjects=`_log4sh_setArrayElement \
|
2250
|
+
"${__log4shAppender_smtp_subjects}" ${asss_index} "${asss_subject}"`
|
2251
|
+
__log4sh_return=${__LOG4SH_TRUE}
|
2252
|
+
else
|
2253
|
+
_log4sh_error "could not set Subject for appender (${asss_appender})"
|
2254
|
+
__log4sh_return=${__LOG4SH_FALSE}
|
2255
|
+
fi
|
2256
|
+
|
2257
|
+
# re-source the appender
|
2258
|
+
_appender_cache ${asss_appender}
|
2259
|
+
|
2260
|
+
unset asss_appender asss_subject asss_index
|
2261
|
+
return ${__log4sh_return}
|
2262
|
+
}
|
2263
|
+
|
2264
|
+
#/**
|
2265
|
+
# <s:function group="SMTPAppender" modifier="public">
|
2266
|
+
# <entry align="right">
|
2267
|
+
# <emphasis>void</emphasis>
|
2268
|
+
# </entry>
|
2269
|
+
# <entry>
|
2270
|
+
# <funcsynopsis>
|
2271
|
+
# <funcprototype>
|
2272
|
+
# <funcdef><function>appender_setAppenderSubject</function></funcdef>
|
2273
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
2274
|
+
# <paramdef>string <parameter>subject</parameter></paramdef>
|
2275
|
+
# </funcprototype>
|
2276
|
+
# </funcsynopsis>
|
2277
|
+
# <para><emphasis role="strong">Deprecated as of 1.3.1</emphasis></para>
|
2278
|
+
# <para>
|
2279
|
+
# Sets the email subject for an SMTP appender
|
2280
|
+
# </para>
|
2281
|
+
# <funcsynopsis>
|
2282
|
+
# <funcsynopsisinfo>appender_setAppenderSubject myAppender "This is a test"</funcsynopsisinfo>
|
2283
|
+
# </funcsynopsis>
|
2284
|
+
# </entry>
|
2285
|
+
# </s:function>
|
2286
|
+
#*/
|
2287
|
+
appender_setAppenderSubject()
|
2288
|
+
{
|
2289
|
+
appender_smtp_setSubject "$@"
|
2290
|
+
}
|
2291
|
+
|
2292
|
+
#-----------------------------------------------------------------------------
|
2293
|
+
# SyslogAppender
|
2294
|
+
#
|
2295
|
+
|
2296
|
+
#/**
|
2297
|
+
# <s:function group="SyslogAppender" modifier="private">
|
2298
|
+
# <entry align="right">
|
2299
|
+
# <code>string</code>
|
2300
|
+
# </entry>
|
2301
|
+
# <entry>
|
2302
|
+
# <funcsynopsis>
|
2303
|
+
# <funcprototype>
|
2304
|
+
# <funcdef>
|
2305
|
+
# <function>_appender_syslog_getFacilityByIndex</function>
|
2306
|
+
# </funcdef>
|
2307
|
+
# <paramdef>integer <parameter>index</parameter></paramdef>
|
2308
|
+
# </funcprototype>
|
2309
|
+
# </funcsynopsis>
|
2310
|
+
# <para>Get the syslog facility of the specified appender by index</para>
|
2311
|
+
# <funcsynopsis>
|
2312
|
+
# <funcsynopsisinfo>
|
2313
|
+
# facility=`_appender_syslog_getFacilityByIndex 3`
|
2314
|
+
# </funcsynopsisinfo>
|
2315
|
+
# </funcsynopsis>
|
2316
|
+
# </entry>
|
2317
|
+
# </s:function>
|
2318
|
+
#*/
|
2319
|
+
_appender_syslog_getFacilityByIndex()
|
2320
|
+
{
|
2321
|
+
_log4sh_getArrayElement "$__log4shAppender_syslog_facilities" $1
|
2322
|
+
}
|
2323
|
+
|
2324
|
+
#/**
|
2325
|
+
# <s:function group="SyslogAppender" modifier="public">
|
2326
|
+
# <entry align="right">
|
2327
|
+
# <code>string</code>
|
2328
|
+
# </entry>
|
2329
|
+
# <entry>
|
2330
|
+
# <funcsynopsis>
|
2331
|
+
# <funcprototype>
|
2332
|
+
# <funcdef><function>appender_getSyslogFacility</function></funcdef>
|
2333
|
+
# <paramdef>integer <parameter>index</parameter></paramdef>
|
2334
|
+
# </funcprototype>
|
2335
|
+
# </funcsynopsis>
|
2336
|
+
# <para><emphasis role="strong">Deprecated as of 1.3.1</emphasis></para>
|
2337
|
+
# <para>
|
2338
|
+
# Get the syslog facility of the specified appender by index
|
2339
|
+
# </para>
|
2340
|
+
# <funcsynopsis>
|
2341
|
+
# <funcsynopsisinfo>facility=`appender_getSyslogFacility 3`</funcsynopsisinfo>
|
2342
|
+
# </funcsynopsis>
|
2343
|
+
# </entry>
|
2344
|
+
# </s:function>
|
2345
|
+
#*/
|
2346
|
+
appender_getSyslogFacility()
|
2347
|
+
{
|
2348
|
+
_appender_syslog_getFacilityByIndex "$@"
|
2349
|
+
}
|
2350
|
+
|
2351
|
+
#/**
|
2352
|
+
# <s:function group="SyslogAppender" modifier="public">
|
2353
|
+
# <entry align="right">
|
2354
|
+
# <emphasis>void</emphasis>
|
2355
|
+
# </entry>
|
2356
|
+
# <entry>
|
2357
|
+
# <funcsynopsis>
|
2358
|
+
# <funcprototype>
|
2359
|
+
# <funcdef><function>appender_syslog_getFacility</function></funcdef>
|
2360
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
2361
|
+
# </funcprototype>
|
2362
|
+
# </funcsynopsis>
|
2363
|
+
# <para>
|
2364
|
+
# Get the syslog facility for the given appender.
|
2365
|
+
# </para>
|
2366
|
+
# <funcsynopsis>
|
2367
|
+
# <funcsynopsisinfo>facility=`appender_syslog_getFacility myAppender`</funcsynopsisinfo>
|
2368
|
+
# </funcsynopsis>
|
2369
|
+
# </entry>
|
2370
|
+
# </s:function>
|
2371
|
+
#*/
|
2372
|
+
appender_syslog_getFacility()
|
2373
|
+
{
|
2374
|
+
if [ $# -ne 1 ]; then
|
2375
|
+
_log4sh_error 'appender_syslog_getFacility(): invalid number of parameters'
|
2376
|
+
return ${__LOG4SH_FALSE}
|
2377
|
+
fi
|
2378
|
+
|
2379
|
+
asgf_appender=$1
|
2380
|
+
|
2381
|
+
asgf_index=`_log4sh_findArrayElement "$__log4shAppenders" ${asgf_appender}`
|
2382
|
+
_log4sh_getArrayElement "${__log4shAppender_syslog_facilities}" ${asgf_index}
|
2383
|
+
|
2384
|
+
unset asgf_appender asgf_index
|
2385
|
+
}
|
2386
|
+
|
2387
|
+
#/**
|
2388
|
+
# <s:function group="SyslogAppender" modifier="public">
|
2389
|
+
# <entry align="right">
|
2390
|
+
# <emphasis>void</emphasis>
|
2391
|
+
# </entry>
|
2392
|
+
# <entry>
|
2393
|
+
# <funcsynopsis>
|
2394
|
+
# <funcprototype>
|
2395
|
+
# <funcdef><function>appender_syslog_setFacility</function></funcdef>
|
2396
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
2397
|
+
# <paramdef>string <parameter>facility</parameter></paramdef>
|
2398
|
+
# </funcprototype>
|
2399
|
+
# </funcsynopsis>
|
2400
|
+
# <para>Set the syslog facility for the given appender</para>
|
2401
|
+
# <funcsynopsis>
|
2402
|
+
# <funcsynopsisinfo>appender_syslog_setFacility myAppender local4`</funcsynopsisinfo>
|
2403
|
+
# </funcsynopsis>
|
2404
|
+
# </entry>
|
2405
|
+
# </s:function>
|
2406
|
+
#*/
|
2407
|
+
appender_syslog_setFacility()
|
2408
|
+
{
|
2409
|
+
if [ $# -ne 2 ]; then
|
2410
|
+
_log4sh_error 'appender_syslog_setFacility(): invalid number of parameters'
|
2411
|
+
return ${__LOG4SH_FALSE}
|
2412
|
+
fi
|
2413
|
+
assf_appender=$1
|
2414
|
+
assf_facility=$2
|
2415
|
+
|
2416
|
+
# check for valid facility
|
2417
|
+
echo "${__LOG4SH_TYPE_SYSLOG_FACILITY_NAMES}" |grep " ${assf_facility} " >/dev/null
|
2418
|
+
if [ $? -ne 0 ]; then
|
2419
|
+
# the facility is not valid
|
2420
|
+
_log4sh_error "[${assf_facility}] is an unknown syslog facility. Defaulting to [user]."
|
2421
|
+
assf_facility='user'
|
2422
|
+
fi
|
2423
|
+
|
2424
|
+
# set appender facility
|
2425
|
+
assf_index=`_log4sh_findArrayElement "${__log4shAppenders}" ${assf_appender}`
|
2426
|
+
# TODO: put check for valid index here
|
2427
|
+
__log4shAppender_syslog_facilities=`_log4sh_setArrayElement \
|
2428
|
+
"${__log4shAppender_syslog_facilities}" ${assf_index} "${assf_facility}"`
|
2429
|
+
|
2430
|
+
# re-source the appender
|
2431
|
+
_appender_cache ${assf_appender}
|
2432
|
+
|
2433
|
+
unset assf_appender assf_facility assf_index
|
2434
|
+
return ${__LOG4SH_TRUE}
|
2435
|
+
}
|
2436
|
+
|
2437
|
+
#/**
|
2438
|
+
# <s:function group="SyslogAppender" modifier="public">
|
2439
|
+
# <entry align="right">
|
2440
|
+
# <emphasis>void</emphasis>
|
2441
|
+
# </entry>
|
2442
|
+
# <entry>
|
2443
|
+
# <funcsynopsis>
|
2444
|
+
# <funcprototype>
|
2445
|
+
# <funcdef><function>appender_setSyslogFacility</function></funcdef>
|
2446
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
2447
|
+
# <paramdef>string <parameter>facility</parameter></paramdef>
|
2448
|
+
# </funcprototype>
|
2449
|
+
# </funcsynopsis>
|
2450
|
+
# <para><emphasis role="strong">Deprecated as of 1.3.2</emphasis></para>
|
2451
|
+
# <para>
|
2452
|
+
# Set the syslog facility for the given appender
|
2453
|
+
# </para>
|
2454
|
+
# <funcsynopsis>
|
2455
|
+
# <funcsynopsisinfo>appender_setSyslogFacility myAppender local4`</funcsynopsisinfo>
|
2456
|
+
# </funcsynopsis>
|
2457
|
+
# </entry>
|
2458
|
+
# </s:function>
|
2459
|
+
#*/
|
2460
|
+
appender_setSyslogFacility()
|
2461
|
+
{
|
2462
|
+
appender_syslog_setFacility "$@"
|
2463
|
+
}
|
2464
|
+
|
2465
|
+
#/**
|
2466
|
+
# <s:function group="SyslogAppender" modifier="public">
|
2467
|
+
# <entry align="right">
|
2468
|
+
# <code>string</code>/boolean
|
2469
|
+
# </entry>
|
2470
|
+
# <entry>
|
2471
|
+
# <funcsynopsis>
|
2472
|
+
# <funcprototype>
|
2473
|
+
# <funcdef><function>appender_syslog_getHost</function></funcdef>
|
2474
|
+
# <paramdef>integer <parameter>index</parameter></paramdef>
|
2475
|
+
# </funcprototype>
|
2476
|
+
# </funcsynopsis>
|
2477
|
+
# <para>
|
2478
|
+
# Get the syslog host of the specified appender.
|
2479
|
+
# </para>
|
2480
|
+
# <para><emphasis role="strong">Since:</emphasis> 1.3.7</para>
|
2481
|
+
# <funcsynopsis>
|
2482
|
+
# <funcsynopsisinfo>host=`appender_syslog_getHost myAppender`</funcsynopsisinfo>
|
2483
|
+
# </funcsynopsis>
|
2484
|
+
# </entry>
|
2485
|
+
# </s:function>
|
2486
|
+
#*/
|
2487
|
+
appender_syslog_getHost()
|
2488
|
+
{
|
2489
|
+
if [ $# -ne 1 ]; then
|
2490
|
+
_log4sh_error 'appender_syslog_getHost(): invalid number of parameters'
|
2491
|
+
return ${__LOG4SH_FALSE}
|
2492
|
+
fi
|
2493
|
+
|
2494
|
+
asgh_appender=$1
|
2495
|
+
|
2496
|
+
asgh_index=`_log4sh_findArrayElement "${__log4shAppenders}" ${asgh_appender}`
|
2497
|
+
# TODO: put check for valid index here
|
2498
|
+
asgh_host=`_log4sh_getArrayElement \
|
2499
|
+
"${__log4shAppender_syslog_hosts}" ${asgh_index}`
|
2500
|
+
__log4sh_return=$?
|
2501
|
+
|
2502
|
+
[ "${asgh_host}" = "${__LOG4SH_NULL}" ] && asgh_host=''
|
2503
|
+
echo "${asgh_host}"
|
2504
|
+
|
2505
|
+
unset asgh_appender asgh_index asgh_host
|
2506
|
+
return ${__log4sh_return}
|
2507
|
+
}
|
2508
|
+
|
2509
|
+
#/**
|
2510
|
+
# <s:function group="SyslogAppender" modifier="public">
|
2511
|
+
# <entry align="right">
|
2512
|
+
# <emphasis>void</emphasis>/boolean
|
2513
|
+
# </entry>
|
2514
|
+
# <entry>
|
2515
|
+
# <funcsynopsis>
|
2516
|
+
# <funcprototype>
|
2517
|
+
# <funcdef><function>appender_syslog_setHost</function></funcdef>
|
2518
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
2519
|
+
# <paramdef>string <parameter>host</parameter></paramdef>
|
2520
|
+
# </funcprototype>
|
2521
|
+
# </funcsynopsis>
|
2522
|
+
# <para>
|
2523
|
+
# Set the syslog host for the given appender. Requires that the 'nc'
|
2524
|
+
# command alternative has been previously set with the
|
2525
|
+
# log4sh_setAlternative() function.
|
2526
|
+
# </para>
|
2527
|
+
# <para><emphasis role="strong">Since:</emphasis> 1.3.7</para>
|
2528
|
+
# <funcsynopsis>
|
2529
|
+
# <funcsynopsisinfo>appender_syslog_setHost myAppender localhost</funcsynopsisinfo>
|
2530
|
+
# </funcsynopsis>
|
2531
|
+
# </entry>
|
2532
|
+
# </s:function>
|
2533
|
+
#*/
|
2534
|
+
#
|
2535
|
+
# The BSD syslog Protocol
|
2536
|
+
# http://www.ietf.org/rfc/rfc3164.txt
|
2537
|
+
#
|
2538
|
+
appender_syslog_setHost()
|
2539
|
+
{
|
2540
|
+
if [ $# -ne 2 ]; then
|
2541
|
+
_log4sh_error 'appender_syslog_setHost(): invalid number of parameters'
|
2542
|
+
return ${__LOG4SH_FALSE}
|
2543
|
+
fi
|
2544
|
+
|
2545
|
+
assh_appender=$1
|
2546
|
+
assh_host=$2
|
2547
|
+
|
2548
|
+
[ -z "${__log4sh_alternative_nc:-}" ] \
|
2549
|
+
&& _log4sh_warn 'the nc (netcat) command alternative is required for remote syslog logging. see log4sh_setAlternative().'
|
2550
|
+
|
2551
|
+
assh_index=`_log4sh_findArrayElement "${__log4shAppenders}" ${assh_appender}`
|
2552
|
+
# TODO: put check for valid index here
|
2553
|
+
__log4shAppender_syslog_hosts=`_log4sh_setArrayElement \
|
2554
|
+
"${__log4shAppender_syslog_hosts}" ${assh_index} "${assh_host}"`
|
2555
|
+
|
2556
|
+
# re-source the appender
|
2557
|
+
_appender_cache ${assh_appender}
|
2558
|
+
|
2559
|
+
unset assh_appender assh_host assh_index
|
2560
|
+
return ${__LOG4SH_TRUE}
|
2561
|
+
}
|
2562
|
+
|
2563
|
+
#=============================================================================
|
2564
|
+
# Level
|
2565
|
+
#
|
2566
|
+
|
2567
|
+
#/**
|
2568
|
+
# <s:function group="Level" modifier="public">
|
2569
|
+
# <entry align="right">
|
2570
|
+
# <code>string</code>
|
2571
|
+
# </entry>
|
2572
|
+
# <entry>
|
2573
|
+
# <funcsynopsis>
|
2574
|
+
# <funcprototype>
|
2575
|
+
# <funcdef><function>logger_level_toLevel</function></funcdef>
|
2576
|
+
# <paramdef>integer <parameter>val</parameter></paramdef>
|
2577
|
+
# </funcprototype>
|
2578
|
+
# </funcsynopsis>
|
2579
|
+
# <para>Converts an internally used level integer into its external level
|
2580
|
+
# equivalent</para>
|
2581
|
+
# <funcsynopsis>
|
2582
|
+
# <funcsynopsisinfo>level=`logger_level_toLevel 3`</funcsynopsisinfo>
|
2583
|
+
# </funcsynopsis>
|
2584
|
+
# </entry>
|
2585
|
+
# </s:function>
|
2586
|
+
#*/
|
2587
|
+
# TODO use arrays instead of case statement ??
|
2588
|
+
logger_level_toLevel()
|
2589
|
+
{
|
2590
|
+
_ltl__val=$1
|
2591
|
+
|
2592
|
+
_ltl__return=${__LOG4SH_TRUE}
|
2593
|
+
_ltl__level=''
|
2594
|
+
|
2595
|
+
case ${_ltl__val} in
|
2596
|
+
${__LOG4SH_LEVEL_TRACE}) _ltl__level=${__LOG4SH_LEVEL_TRACE_STR} ;;
|
2597
|
+
${__LOG4SH_LEVEL_DEBUG}) _ltl__level=${__LOG4SH_LEVEL_DEBUG_STR} ;;
|
2598
|
+
${__LOG4SH_LEVEL_INFO}) _ltl__level=${__LOG4SH_LEVEL_INFO_STR} ;;
|
2599
|
+
${__LOG4SH_LEVEL_WARN}) _ltl__level=${__LOG4SH_LEVEL_WARN_STR} ;;
|
2600
|
+
${__LOG4SH_LEVEL_ERROR}) _ltl__level=${__LOG4SH_LEVEL_ERROR_STR} ;;
|
2601
|
+
${__LOG4SH_LEVEL_FATAL}) _ltl__level=${__LOG4SH_LEVEL_FATAL_STR} ;;
|
2602
|
+
${__LOG4SH_LEVEL_OFF}) _ltl__level=${__LOG4SH_LEVEL_OFF_STR} ;;
|
2603
|
+
${__LOG4SH_LEVEL_CLOSED}) _ltl__level=${__LOG4SH_LEVEL_CLOSED_STR} ;;
|
2604
|
+
*) _ltl__return=${__LOG4SH_FALSE} ;;
|
2605
|
+
esac
|
2606
|
+
|
2607
|
+
echo ${_ltl__level}
|
2608
|
+
unset _ltl__val _ltl__level
|
2609
|
+
return ${_ltl__return}
|
2610
|
+
}
|
2611
|
+
|
2612
|
+
#/**
|
2613
|
+
# <s:function group="Level" modifier="public">
|
2614
|
+
# <entry align="right">
|
2615
|
+
# <code>integer</code>
|
2616
|
+
# </entry>
|
2617
|
+
# <entry>
|
2618
|
+
# <funcsynopsis>
|
2619
|
+
# <funcprototype>
|
2620
|
+
# <funcdef><function>logger_level_toInt</function></funcdef>
|
2621
|
+
# <paramdef>string <parameter>level</parameter></paramdef>
|
2622
|
+
# </funcprototype>
|
2623
|
+
# </funcsynopsis>
|
2624
|
+
# <para>Converts an externally used level tag into its integer
|
2625
|
+
# equivalent</para>
|
2626
|
+
# <funcsynopsis>
|
2627
|
+
# <funcsynopsisinfo>levelInt=`logger_level_toInt WARN`</funcsynopsisinfo>
|
2628
|
+
# </funcsynopsis>
|
2629
|
+
# </entry>
|
2630
|
+
# </s:function>
|
2631
|
+
#*/
|
2632
|
+
logger_level_toInt()
|
2633
|
+
{
|
2634
|
+
_lti__level=$1
|
2635
|
+
|
2636
|
+
_lti__int=0
|
2637
|
+
_lti__return=${__LOG4SH_TRUE}
|
2638
|
+
|
2639
|
+
case ${_lti__level} in
|
2640
|
+
${__LOG4SH_LEVEL_TRACE_STR}) _lti__int=${__LOG4SH_LEVEL_TRACE} ;;
|
2641
|
+
${__LOG4SH_LEVEL_DEBUG_STR}) _lti__int=${__LOG4SH_LEVEL_DEBUG} ;;
|
2642
|
+
${__LOG4SH_LEVEL_INFO_STR}) _lti__int=${__LOG4SH_LEVEL_INFO} ;;
|
2643
|
+
${__LOG4SH_LEVEL_WARN_STR}) _lti__int=${__LOG4SH_LEVEL_WARN} ;;
|
2644
|
+
${__LOG4SH_LEVEL_ERROR_STR}) _lti__int=${__LOG4SH_LEVEL_ERROR} ;;
|
2645
|
+
${__LOG4SH_LEVEL_FATAL_STR}) _lti__int=${__LOG4SH_LEVEL_FATAL} ;;
|
2646
|
+
${__LOG4SH_LEVEL_OFF_STR}) _lti__int=${__LOG4SH_LEVEL_OFF} ;;
|
2647
|
+
${__LOG4SH_LEVEL_CLOSED_STR}) _lti__int=${__LOG4SH_LEVEL_CLOSED} ;;
|
2648
|
+
*) _lti__return=${__LOG4SH_FALSE} ;;
|
2649
|
+
esac
|
2650
|
+
|
2651
|
+
echo ${_lti__int}
|
2652
|
+
unset _lti__int _lti__level
|
2653
|
+
return ${_lti__return}
|
2654
|
+
}
|
2655
|
+
|
2656
|
+
#=============================================================================
|
2657
|
+
# Logger
|
2658
|
+
#
|
2659
|
+
|
2660
|
+
#/**
|
2661
|
+
# <s:function group="Logger" modifier="public">
|
2662
|
+
# <entry align="right">
|
2663
|
+
# <emphasis>void</emphasis>/<code>boolean</code>
|
2664
|
+
# </entry>
|
2665
|
+
# <entry>
|
2666
|
+
# <funcsynopsis>
|
2667
|
+
# <funcprototype>
|
2668
|
+
# <funcdef><function>logger_addAppender</function></funcdef>
|
2669
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
2670
|
+
# </funcprototype>
|
2671
|
+
# </funcsynopsis>
|
2672
|
+
# <para>Add and initialize a new appender</para>
|
2673
|
+
# <funcsynopsis>
|
2674
|
+
# <funcsynopsisinfo>logger_addAppender $appender</funcsynopsisinfo>
|
2675
|
+
# </funcsynopsis>
|
2676
|
+
# </entry>
|
2677
|
+
# </s:function>
|
2678
|
+
#*/
|
2679
|
+
logger_addAppender()
|
2680
|
+
{
|
2681
|
+
laa_appender=$1
|
2682
|
+
|
2683
|
+
# FAQ should we be using setter functions here?? for performance, no.
|
2684
|
+
__log4shAppenders=`_log4sh_pushStack "${__log4shAppenders}" ${laa_appender}`
|
2685
|
+
__log4shAppenderCount=`expr ${__log4shAppenderCount} + 1`
|
2686
|
+
__log4shAppenderCounts="${__log4shAppenderCounts} ${__log4shAppenderCount}"
|
2687
|
+
__log4shAppenderLayouts=`_log4sh_pushStack \
|
2688
|
+
"$__log4shAppenderLayouts" "${__LOG4SH_LAYOUT_SIMPLE}"`
|
2689
|
+
__log4shAppenderLevels=`_log4sh_pushStack \
|
2690
|
+
"${__log4shAppenderLevels}" "${__LOG4SH_NULL}"`
|
2691
|
+
__log4shAppenderPatterns=`_log4sh_pushStack \
|
2692
|
+
"${__log4shAppenderPatterns}" "${__LOG4SH_PATTERN_DEFAULT}"`
|
2693
|
+
__log4shAppenderTypes=`_log4sh_pushStack \
|
2694
|
+
"${__log4shAppenderTypes}" ${__LOG4SH_TYPE_CONSOLE}`
|
2695
|
+
__log4shAppender_file_files=`_log4sh_pushStack \
|
2696
|
+
"${__log4shAppender_file_files}" ${__LOG4SH_NULL}`
|
2697
|
+
__log4shAppender_rollingFile_maxBackupIndexes=`_log4sh_pushStack \
|
2698
|
+
"${__log4shAppender_rollingFile_maxBackupIndexes}" \
|
2699
|
+
${__LOG4SH_TYPE_ROLLING_FILE_MAX_BACKUP_INDEX}`
|
2700
|
+
__log4shAppender_rollingFile_maxFileSizes=`_log4sh_pushStack \
|
2701
|
+
"${__log4shAppender_rollingFile_maxFileSizes}" \
|
2702
|
+
${__LOG4SH_TYPE_ROLLING_FILE_MAX_FILE_SIZE}`
|
2703
|
+
__log4shAppender_smtp_tos=`_log4sh_pushStack \
|
2704
|
+
"${__log4shAppender_smtp_tos}" ${__LOG4SH_NULL}`
|
2705
|
+
__log4shAppender_smtp_subjects=`_log4sh_pushStack \
|
2706
|
+
"${__log4shAppender_smtp_subjects}" ${__LOG4SH_NULL}`
|
2707
|
+
__log4shAppender_syslog_facilities=`_log4sh_pushStack \
|
2708
|
+
"${__log4shAppender_syslog_facilities}" ${__LOG4SH_TYPE_SYSLOG_FACILITY}`
|
2709
|
+
__log4shAppender_syslog_hosts=`_log4sh_pushStack \
|
2710
|
+
"${__log4shAppender_syslog_hosts}" "${__LOG4SH_NULL}"`
|
2711
|
+
|
2712
|
+
_appender_cache ${laa_appender}
|
2713
|
+
|
2714
|
+
unset laa_appender
|
2715
|
+
return ${__LOG4SH_TRUE}
|
2716
|
+
}
|
2717
|
+
|
2718
|
+
#/**
|
2719
|
+
# <s:function group="Logger" modifier="public">
|
2720
|
+
# <entry align="right">
|
2721
|
+
# <emphasis>void</emphasis>
|
2722
|
+
# </entry>
|
2723
|
+
# <entry>
|
2724
|
+
# <funcsynopsis>
|
2725
|
+
# <funcprototype>
|
2726
|
+
# <funcdef><function>logger_addAppenderWithPattern</function></funcdef>
|
2727
|
+
# <paramdef>string <parameter>appender</parameter></paramdef>
|
2728
|
+
# <paramdef>string <parameter>pattern</parameter></paramdef>
|
2729
|
+
# </funcprototype>
|
2730
|
+
# </funcsynopsis>
|
2731
|
+
# <para><emphasis role="strong">Deprecated as of 1.3.6</emphasis></para>
|
2732
|
+
# <para>
|
2733
|
+
# Add and initialize a new appender with a specific PatternLayout
|
2734
|
+
# </para>
|
2735
|
+
# <funcsynopsis>
|
2736
|
+
# <funcsynopsisinfo>logger_addAppenderWithPattern $appender '%d %p - %m%n'</funcsynopsisinfo>
|
2737
|
+
# </funcsynopsis>
|
2738
|
+
# </entry>
|
2739
|
+
# </s:function>
|
2740
|
+
#*/
|
2741
|
+
logger_addAppenderWithPattern()
|
2742
|
+
{
|
2743
|
+
_myAppender=$1
|
2744
|
+
_myPattern=$2
|
2745
|
+
|
2746
|
+
logger_addAppender ${_myAppender}
|
2747
|
+
appender_setLayout ${_myAppender} ${__LOG4SH_LAYOUT_PATTERN}
|
2748
|
+
appender_setPattern ${_myAppender} "${_myPattern}"
|
2749
|
+
|
2750
|
+
unset _myAppender _myPattern
|
2751
|
+
}
|
2752
|
+
|
2753
|
+
#/**
|
2754
|
+
# <s:function group="Logger" modifier="public">
|
2755
|
+
# <entry align="right">
|
2756
|
+
# <code>string</code>
|
2757
|
+
# </entry>
|
2758
|
+
# <entry>
|
2759
|
+
# <funcsynopsis>
|
2760
|
+
# <funcprototype>
|
2761
|
+
# <funcdef><function>logger_getFilename</function></funcdef>
|
2762
|
+
# <void />
|
2763
|
+
# </funcprototype>
|
2764
|
+
# </funcsynopsis>
|
2765
|
+
# <para>
|
2766
|
+
# Get the filename that would be shown when the '%F' conversion character
|
2767
|
+
# is used in a PatternLayout.
|
2768
|
+
# </para>
|
2769
|
+
# <funcsynopsis>
|
2770
|
+
# <funcsynopsisinfo>filename=`logger_getFilename`</funcsynopsisinfo>
|
2771
|
+
# </funcsynopsis>
|
2772
|
+
# </entry>
|
2773
|
+
# </s:function>
|
2774
|
+
#*/
|
2775
|
+
logger_getFilename()
|
2776
|
+
{
|
2777
|
+
echo "${__log4sh_filename}"
|
2778
|
+
}
|
2779
|
+
|
2780
|
+
#/**
|
2781
|
+
# <s:function group="Logger" modifier="public">
|
2782
|
+
# <entry align="right">
|
2783
|
+
# <emphasis>void</emphasis>
|
2784
|
+
# </entry>
|
2785
|
+
# <entry>
|
2786
|
+
# <funcsynopsis>
|
2787
|
+
# <funcprototype>
|
2788
|
+
# <funcdef><function>logger_setFilename</function></funcdef>
|
2789
|
+
# <paramdef>string <parameter>filename</parameter></paramdef>
|
2790
|
+
# </funcprototype>
|
2791
|
+
# </funcsynopsis>
|
2792
|
+
# <para>Set the filename to be shown when the '%F' conversion character is
|
2793
|
+
# used in a PatternLayout.</para>
|
2794
|
+
# <funcsynopsis>
|
2795
|
+
# <funcsynopsisinfo>logger_setFilename 'myScript.sh'</funcsynopsisinfo>
|
2796
|
+
# </funcsynopsis>
|
2797
|
+
# </entry>
|
2798
|
+
# </s:function>
|
2799
|
+
#*/
|
2800
|
+
logger_setFilename()
|
2801
|
+
{
|
2802
|
+
__log4sh_filename=$1
|
2803
|
+
}
|
2804
|
+
|
2805
|
+
#/**
|
2806
|
+
# <s:function group="Logger" modifier="public">
|
2807
|
+
# <entry align="right">
|
2808
|
+
# <code>string</code>
|
2809
|
+
# </entry>
|
2810
|
+
# <entry>
|
2811
|
+
# <funcsynopsis>
|
2812
|
+
# <funcprototype>
|
2813
|
+
# <funcdef><function>logger_getLevel</function></funcdef>
|
2814
|
+
# <void />
|
2815
|
+
# </funcprototype>
|
2816
|
+
# </funcsynopsis>
|
2817
|
+
# <para>Get the global default logging level (e.g. DEBUG).</para>
|
2818
|
+
# <funcsynopsis>
|
2819
|
+
# <funcsynopsisinfo>level=`logger_getLevel`</funcsynopsisinfo>
|
2820
|
+
# </funcsynopsis>
|
2821
|
+
# </entry>
|
2822
|
+
# </s:function>
|
2823
|
+
#*/
|
2824
|
+
logger_getLevel()
|
2825
|
+
{
|
2826
|
+
logger_level_toLevel ${__log4shLevel}
|
2827
|
+
}
|
2828
|
+
|
2829
|
+
#/**
|
2830
|
+
# <s:function group="Logger" modifier="public">
|
2831
|
+
# <entry align="right">
|
2832
|
+
# <emphasis>void</emphasis>
|
2833
|
+
# </entry>
|
2834
|
+
# <entry>
|
2835
|
+
# <funcsynopsis>
|
2836
|
+
# <funcprototype>
|
2837
|
+
# <funcdef><function>logger_setLevel</function></funcdef>
|
2838
|
+
# <paramdef>string <parameter>level</parameter></paramdef>
|
2839
|
+
# </funcprototype>
|
2840
|
+
# </funcsynopsis>
|
2841
|
+
# <para>Sets the global default logging level (e.g. DEBUG).</para>
|
2842
|
+
# <funcsynopsis>
|
2843
|
+
# <funcsynopsisinfo>logger_setLevel INFO</funcsynopsisinfo>
|
2844
|
+
# </funcsynopsis>
|
2845
|
+
# </entry>
|
2846
|
+
# </s:function>
|
2847
|
+
#*/
|
2848
|
+
logger_setLevel()
|
2849
|
+
{
|
2850
|
+
_l_level=$1
|
2851
|
+
|
2852
|
+
_l_int=`logger_level_toInt ${_l_level}`
|
2853
|
+
if [ $? -eq ${__LOG4SH_TRUE} ]; then
|
2854
|
+
__log4shLevel=${_l_int}
|
2855
|
+
else
|
2856
|
+
_log4sh_error "attempt to set invalid log level '${_l_level}'"
|
2857
|
+
fi
|
2858
|
+
|
2859
|
+
unset _l_int _l_level
|
2860
|
+
}
|
2861
|
+
|
2862
|
+
#/**
|
2863
|
+
# <s:function group="Logger" modifier="public">
|
2864
|
+
# <entry align="right">
|
2865
|
+
# <emphasis>void</emphasis>
|
2866
|
+
# </entry>
|
2867
|
+
# <entry>
|
2868
|
+
# <funcsynopsis>
|
2869
|
+
# <funcprototype>
|
2870
|
+
# <funcdef><function>log</function></funcdef>
|
2871
|
+
# <paramdef>string <parameter>level</parameter></paramdef>
|
2872
|
+
# <paramdef>string[] <parameter>message(s)</parameter></paramdef>
|
2873
|
+
# </funcprototype>
|
2874
|
+
# </funcsynopsis>
|
2875
|
+
# <para>The base logging command that logs a message to all defined
|
2876
|
+
# appenders</para>
|
2877
|
+
# <funcsynopsis>
|
2878
|
+
# <funcsynopsisinfo>log DEBUG 'This is a test message'</funcsynopsisinfo>
|
2879
|
+
# </funcsynopsis>
|
2880
|
+
# </entry>
|
2881
|
+
# </s:function>
|
2882
|
+
#*/
|
2883
|
+
log()
|
2884
|
+
{
|
2885
|
+
_l_level=$1
|
2886
|
+
shift
|
2887
|
+
# if no message was passed, read it from STDIN
|
2888
|
+
[ $# -ne 0 ] && _l_msg="$@" || _l_msg=`cat`
|
2889
|
+
|
2890
|
+
__log4sh_return=${__LOG4SH_TRUE}
|
2891
|
+
_l_levelInt=`logger_level_toInt ${_l_level}`
|
2892
|
+
if [ $? -eq ${__LOG4SH_TRUE} ]; then
|
2893
|
+
# update seconds elapsed
|
2894
|
+
_log4sh_updateSeconds
|
2895
|
+
|
2896
|
+
_l_oldIFS=${IFS} IFS=${__LOG4SH_IFS_DEFAULT}
|
2897
|
+
for _l_appenderIndex in ${__log4shAppenderCounts}; do
|
2898
|
+
${__LOG4SH_TRACE} "_l_appenderIndex='${_l_appenderIndex}'"
|
2899
|
+
# determine appender level
|
2900
|
+
_l_appenderLevel=`_appender_getLevelByIndex ${_l_appenderIndex}`
|
2901
|
+
if [ "${_l_appenderLevel}" = "${__LOG4SH_NULL}" ]; then
|
2902
|
+
# continue if requested is level less than general level
|
2903
|
+
[ ! ${__log4shLevel} -le ${_l_levelInt} ] && continue
|
2904
|
+
else
|
2905
|
+
_l_appenderLevelInt=`logger_level_toInt ${_l_appenderLevel}`
|
2906
|
+
# continue if requested level is less than specific appender level
|
2907
|
+
${__LOG4SH_TRACE} "_l_levelInt='${_l_levelInt}' _l_appenderLevelInt='${_l_appenderLevelInt}'"
|
2908
|
+
[ ! ${_l_appenderLevelInt} -le ${_l_levelInt} ] && continue
|
2909
|
+
fi
|
2910
|
+
|
2911
|
+
# execute dynamic appender function
|
2912
|
+
_l_appenderName=`_log4sh_getArrayElement \
|
2913
|
+
"${__log4shAppenders}" ${_l_appenderIndex}`
|
2914
|
+
${__LOG4SH_APPENDER_FUNC_PREFIX}${_l_appenderName}_append ${_l_level} "${_l_msg}"
|
2915
|
+
done
|
2916
|
+
IFS=${_l_oldIFS}
|
2917
|
+
else
|
2918
|
+
_log4sh_error "invalid logging level requested (${_l_level})"
|
2919
|
+
__log4sh_return=${__LOG4SH_ERROR}
|
2920
|
+
fi
|
2921
|
+
|
2922
|
+
unset _l_msg _l_oldIFS _l_level _l_levelInt
|
2923
|
+
unset _l_appenderIndex _l_appenderLevel _l_appenderLevelInt _l_appenderName
|
2924
|
+
return ${__log4sh_return}
|
2925
|
+
}
|
2926
|
+
|
2927
|
+
#/**
|
2928
|
+
# <s:function group="Logger" modifier="public">
|
2929
|
+
# <entry align="right">
|
2930
|
+
# <emphasis>void</emphasis>
|
2931
|
+
# </entry>
|
2932
|
+
# <entry>
|
2933
|
+
# <funcsynopsis>
|
2934
|
+
# <funcprototype>
|
2935
|
+
# <funcdef><function>logger_trace</function></funcdef>
|
2936
|
+
# <paramdef>string[] <parameter>message</parameter></paramdef>
|
2937
|
+
# </funcprototype>
|
2938
|
+
# </funcsynopsis>
|
2939
|
+
# <para>This is a helper function for logging a message at the TRACE
|
2940
|
+
# priority</para>
|
2941
|
+
# <funcsynopsis>
|
2942
|
+
# <funcsynopsisinfo>logger_trace 'This is a trace message'</funcsynopsisinfo>
|
2943
|
+
# </funcsynopsis>
|
2944
|
+
# </entry>
|
2945
|
+
# </s:function>
|
2946
|
+
#*/
|
2947
|
+
logger_trace()
|
2948
|
+
{
|
2949
|
+
log ${__LOG4SH_LEVEL_TRACE_STR} "$@"
|
2950
|
+
}
|
2951
|
+
|
2952
|
+
#/**
|
2953
|
+
# <s:function group="Logger" modifier="public">
|
2954
|
+
# <entry align="right">
|
2955
|
+
# <emphasis>void</emphasis>
|
2956
|
+
# </entry>
|
2957
|
+
# <entry>
|
2958
|
+
# <funcsynopsis>
|
2959
|
+
# <funcprototype>
|
2960
|
+
# <funcdef><function>logger_debug</function></funcdef>
|
2961
|
+
# <paramdef>string[] <parameter>message</parameter></paramdef>
|
2962
|
+
# </funcprototype>
|
2963
|
+
# </funcsynopsis>
|
2964
|
+
# <para>This is a helper function for logging a message at the DEBUG
|
2965
|
+
# priority</para>
|
2966
|
+
# <funcsynopsis>
|
2967
|
+
# <funcsynopsisinfo>logger_debug 'This is a debug message'</funcsynopsisinfo>
|
2968
|
+
# </funcsynopsis>
|
2969
|
+
# </entry>
|
2970
|
+
# </s:function>
|
2971
|
+
#*/
|
2972
|
+
logger_debug()
|
2973
|
+
{
|
2974
|
+
log ${__LOG4SH_LEVEL_DEBUG_STR} "$@"
|
2975
|
+
}
|
2976
|
+
|
2977
|
+
#/**
|
2978
|
+
# <s:function group="Logger" modifier="public">
|
2979
|
+
# <entry align="right">
|
2980
|
+
# <emphasis>void</emphasis>
|
2981
|
+
# </entry>
|
2982
|
+
# <entry>
|
2983
|
+
# <funcsynopsis>
|
2984
|
+
# <funcprototype>
|
2985
|
+
# <funcdef><function>logger_info</function></funcdef>
|
2986
|
+
# <paramdef>string[] <parameter>message</parameter></paramdef>
|
2987
|
+
# </funcprototype>
|
2988
|
+
# </funcsynopsis>
|
2989
|
+
# <para>This is a helper function for logging a message at the INFO
|
2990
|
+
# priority</para>
|
2991
|
+
# <funcsynopsis>
|
2992
|
+
# <funcsynopsisinfo>logger_info 'This is a info message'</funcsynopsisinfo>
|
2993
|
+
# </funcsynopsis>
|
2994
|
+
# </entry>
|
2995
|
+
# </s:function>
|
2996
|
+
#*/
|
2997
|
+
logger_info()
|
2998
|
+
{
|
2999
|
+
log ${__LOG4SH_LEVEL_INFO_STR} "$@"
|
3000
|
+
}
|
3001
|
+
|
3002
|
+
#/**
|
3003
|
+
# <s:function group="Logger" modifier="public">
|
3004
|
+
# <entry align="right">
|
3005
|
+
# <emphasis>void</emphasis>
|
3006
|
+
# </entry>
|
3007
|
+
# <entry>
|
3008
|
+
# <funcsynopsis>
|
3009
|
+
# <funcprototype>
|
3010
|
+
# <funcdef><function>logger_warn</function></funcdef>
|
3011
|
+
# <paramdef>string[] <parameter>message</parameter></paramdef>
|
3012
|
+
# </funcprototype>
|
3013
|
+
# </funcsynopsis>
|
3014
|
+
# <para>
|
3015
|
+
# This is a helper function for logging a message at the WARN priority
|
3016
|
+
# </para>
|
3017
|
+
# <funcsynopsis>
|
3018
|
+
# <funcsynopsisinfo>logger_warn 'This is a warn message'</funcsynopsisinfo>
|
3019
|
+
# </funcsynopsis>
|
3020
|
+
# </entry>
|
3021
|
+
# </s:function>
|
3022
|
+
#*/
|
3023
|
+
logger_warn()
|
3024
|
+
{
|
3025
|
+
log ${__LOG4SH_LEVEL_WARN_STR} "$@"
|
3026
|
+
}
|
3027
|
+
|
3028
|
+
#/**
|
3029
|
+
# <s:function group="Logger" modifier="public">
|
3030
|
+
# <entry align="right">
|
3031
|
+
# <emphasis>void</emphasis>
|
3032
|
+
# </entry>
|
3033
|
+
# <entry>
|
3034
|
+
# <funcsynopsis>
|
3035
|
+
# <funcprototype>
|
3036
|
+
# <funcdef><function>logger_error</function></funcdef>
|
3037
|
+
# <paramdef>string[] <parameter>message</parameter></paramdef>
|
3038
|
+
# </funcprototype>
|
3039
|
+
# </funcsynopsis>
|
3040
|
+
# <para>
|
3041
|
+
# This is a helper function for logging a message at the ERROR priority
|
3042
|
+
# </para>
|
3043
|
+
# <funcsynopsis>
|
3044
|
+
# <funcsynopsisinfo>logger_error 'This is a error message'</funcsynopsisinfo>
|
3045
|
+
# </funcsynopsis>
|
3046
|
+
# </entry>
|
3047
|
+
# </s:function>
|
3048
|
+
#*/
|
3049
|
+
logger_error()
|
3050
|
+
{
|
3051
|
+
log ${__LOG4SH_LEVEL_ERROR_STR} "$@"
|
3052
|
+
}
|
3053
|
+
|
3054
|
+
#/**
|
3055
|
+
# <s:function group="Logger" modifier="public">
|
3056
|
+
# <entry align="right">
|
3057
|
+
# <emphasis>void</emphasis>
|
3058
|
+
# </entry>
|
3059
|
+
# <entry>
|
3060
|
+
# <funcsynopsis>
|
3061
|
+
# <funcprototype>
|
3062
|
+
# <funcdef><function>logger_fatal</function></funcdef>
|
3063
|
+
# <paramdef>string[] <parameter>message</parameter></paramdef>
|
3064
|
+
# </funcprototype>
|
3065
|
+
# </funcsynopsis>
|
3066
|
+
# <para>This is a helper function for logging a message at the FATAL
|
3067
|
+
# priority</para>
|
3068
|
+
# <funcsynopsis>
|
3069
|
+
# <funcsynopsisinfo>logger_fatal 'This is a fatal message'</funcsynopsisinfo>
|
3070
|
+
# </funcsynopsis>
|
3071
|
+
# </entry>
|
3072
|
+
# </s:function>
|
3073
|
+
#*/
|
3074
|
+
logger_fatal()
|
3075
|
+
{
|
3076
|
+
log ${__LOG4SH_LEVEL_FATAL_STR} "$@"
|
3077
|
+
}
|
3078
|
+
|
3079
|
+
#==============================================================================
|
3080
|
+
# Property
|
3081
|
+
#
|
3082
|
+
|
3083
|
+
#/**
|
3084
|
+
# <s:function group="Property" modifier="private">
|
3085
|
+
# <entry align="right">
|
3086
|
+
# <code>string</code>
|
3087
|
+
# </entry>
|
3088
|
+
# <entry>
|
3089
|
+
# <funcsynopsis>
|
3090
|
+
# <funcprototype>
|
3091
|
+
# <funcdef><function>_log4sh_getPropPrefix</function></funcdef>
|
3092
|
+
# <paramdef>string <parameter>property</parameter></paramdef>
|
3093
|
+
# </funcprototype>
|
3094
|
+
# </funcsynopsis>
|
3095
|
+
# <para>Takes a string (eg. "log4sh.appender.stderr.File") and returns the
|
3096
|
+
# prefix of it (everything before the first '.' char). Normally used in
|
3097
|
+
# parsing the log4sh configuration file.</para>
|
3098
|
+
# <funcsynopsis>
|
3099
|
+
# <funcsynopsisinfo>prefix=`_log4sh_getPropPrefix $property"`</funcsynopsisinfo>
|
3100
|
+
# </funcsynopsis>
|
3101
|
+
# </entry>
|
3102
|
+
# </s:function>
|
3103
|
+
#*/
|
3104
|
+
_log4sh_getPropPrefix()
|
3105
|
+
{
|
3106
|
+
_oldIFS=${IFS} IFS='.'
|
3107
|
+
set -- $1
|
3108
|
+
IFS=${_oldIFS} unset _oldIFS
|
3109
|
+
echo $1
|
3110
|
+
}
|
3111
|
+
|
3112
|
+
#/**
|
3113
|
+
# <s:function group="Property" modifier="private">
|
3114
|
+
# <entry align="right">
|
3115
|
+
# <code>string</code>
|
3116
|
+
# </entry>
|
3117
|
+
# <entry>
|
3118
|
+
# <funcsynopsis>
|
3119
|
+
# <funcprototype>
|
3120
|
+
# <funcdef><function>_log4sh_stripPropPrefix</function></funcdef>
|
3121
|
+
# <paramdef>string <parameter>property</parameter></paramdef>
|
3122
|
+
# </funcprototype>
|
3123
|
+
# </funcsynopsis>
|
3124
|
+
# <para>Strips the prefix off a property configuration command and returns
|
3125
|
+
# the string. E.g. "log4sh.appender.stderr.File" becomes
|
3126
|
+
# "appender.stderr.File".</para>
|
3127
|
+
# <funcsynopsis>
|
3128
|
+
# <funcsynopsisinfo>newProperty=`_log4sh_stripPropPrefix $property`</funcsynopsisinfo>
|
3129
|
+
# </funcsynopsis>
|
3130
|
+
# </entry>
|
3131
|
+
# </s:function>
|
3132
|
+
#*/
|
3133
|
+
_log4sh_stripPropPrefix()
|
3134
|
+
{
|
3135
|
+
expr "$1" : '[^.]*\.\(.*\)'
|
3136
|
+
}
|
3137
|
+
|
3138
|
+
#/**
|
3139
|
+
# <s:function group="Property" modifier="private">
|
3140
|
+
# <entry align="right">
|
3141
|
+
# <emphasis>void</emphasis>
|
3142
|
+
# </entry>
|
3143
|
+
# <entry>
|
3144
|
+
# <funcsynopsis>
|
3145
|
+
# <funcprototype>
|
3146
|
+
# <funcdef><function>_log4sh_propAlternative</function></funcdef>
|
3147
|
+
# <paramdef>string <parameter>property</parameter></paramdef>
|
3148
|
+
# <paramdef>string <parameter>value</parameter></paramdef>
|
3149
|
+
# </funcprototype>
|
3150
|
+
# </funcsynopsis>
|
3151
|
+
# <para>
|
3152
|
+
# Configures log4sh to use an alternative command.
|
3153
|
+
# </para>
|
3154
|
+
# <funcsynopsis>
|
3155
|
+
# <funcsynopsisinfo>_log4sh_propAlternative property value</funcsynopsisinfo>
|
3156
|
+
# </funcsynopsis>
|
3157
|
+
# </entry>
|
3158
|
+
# </s:function>
|
3159
|
+
#*/
|
3160
|
+
_log4sh_propAlternative()
|
3161
|
+
{
|
3162
|
+
_lpa_key=$1
|
3163
|
+
_lpa_value=$2
|
3164
|
+
|
3165
|
+
# strip the leading 'alternative.'
|
3166
|
+
_lpa_alternative=`_log4sh_stripPropPrefix ${_lpa_key}`
|
3167
|
+
|
3168
|
+
# set the alternative
|
3169
|
+
log4sh_setAlternative ${_lpa_alternative} "${_lpa_value}"
|
3170
|
+
|
3171
|
+
unset _lpa_key _lpa_value _lpa_alternative
|
3172
|
+
}
|
3173
|
+
|
3174
|
+
#/**
|
3175
|
+
# <s:function group="Property" modifier="private">
|
3176
|
+
# <entry align="right">
|
3177
|
+
# <emphasis>void</emphasis>/boolean
|
3178
|
+
# </entry>
|
3179
|
+
# <entry>
|
3180
|
+
# <funcsynopsis>
|
3181
|
+
# <funcprototype>
|
3182
|
+
# <funcdef><function>_log4sh_propAppender</function></funcdef>
|
3183
|
+
# <paramdef>string <parameter>property</parameter></paramdef>
|
3184
|
+
# <paramdef>string <parameter>value</parameter></paramdef>
|
3185
|
+
# </funcprototype>
|
3186
|
+
# </funcsynopsis>
|
3187
|
+
# <para>Configures log4sh using an appender property configuration statement</para>
|
3188
|
+
# <funcsynopsis>
|
3189
|
+
# <funcsynopsisinfo>_log4sh_propAppender $property $value</funcsynopsisinfo>
|
3190
|
+
# </funcsynopsis>
|
3191
|
+
# </entry>
|
3192
|
+
# </s:function>
|
3193
|
+
#*/
|
3194
|
+
_log4sh_propAppender()
|
3195
|
+
{
|
3196
|
+
_lpa_key=$1
|
3197
|
+
_lpa_value=$2
|
3198
|
+
|
3199
|
+
_lpa_appender=''
|
3200
|
+
_lpa_rtrn=${__LOG4SH_TRUE}
|
3201
|
+
|
3202
|
+
# strip the leading 'appender' keyword prefix
|
3203
|
+
_lpa_key=`_log4sh_stripPropPrefix ${_lpa_key}`
|
3204
|
+
|
3205
|
+
# handle appender definitions
|
3206
|
+
if [ "${_lpa_key}" '=' "`expr \"${_lpa_key}\" : '\([^.]*\)'`" ]; then
|
3207
|
+
_lpa_appender="${_lpa_key}"
|
3208
|
+
else
|
3209
|
+
_lpa_appender=`_log4sh_getPropPrefix ${_lpa_key}`
|
3210
|
+
fi
|
3211
|
+
|
3212
|
+
# does the appender exist?
|
3213
|
+
appender_exists ${_lpa_appender}
|
3214
|
+
if [ $? -eq ${__LOG4SH_FALSE} ]; then
|
3215
|
+
_log4sh_error "attempt to configure the non-existant appender (${_lpa_appender})"
|
3216
|
+
unset _lpa_appender _lpa_key _lpa_value
|
3217
|
+
return ${__LOG4SH_ERROR}
|
3218
|
+
fi
|
3219
|
+
|
3220
|
+
# handle the appender type
|
3221
|
+
if [ "${_lpa_appender}" = "${_lpa_key}" ]; then
|
3222
|
+
case ${_lpa_value} in
|
3223
|
+
${__LOG4SH_TYPE_CONSOLE}|\
|
3224
|
+
${__LOG4SH_CONFIG_LOG4J_CP}.${__LOG4SH_TYPE_CONSOLE})
|
3225
|
+
appender_setType ${_lpa_appender} ${__LOG4SH_TYPE_CONSOLE} ;;
|
3226
|
+
${__LOG4SH_TYPE_FILE}|\
|
3227
|
+
${__LOG4SH_CONFIG_LOG4J_CP}.${__LOG4SH_TYPE_FILE})
|
3228
|
+
appender_setType ${_lpa_appender} ${__LOG4SH_TYPE_FILE} ;;
|
3229
|
+
$__LOG4SH_TYPE_DAILY_ROLLING_FILE|\
|
3230
|
+
${__LOG4SH_CONFIG_LOG4J_CP}.${__LOG4SH_TYPE_DAILY_ROLLING_FILE})
|
3231
|
+
appender_setType ${_lpa_appender} ${__LOG4SH_TYPE_DAILY_ROLLING_FILE} ;;
|
3232
|
+
${__LOG4SH_TYPE_ROLLING_FILE}|\
|
3233
|
+
${__LOG4SH_CONFIG_LOG4J_CP}.${__LOG4SH_TYPE_ROLLING_FILE})
|
3234
|
+
appender_setType ${_lpa_appender} ${__LOG4SH_TYPE_ROLLING_FILE} ;;
|
3235
|
+
${__LOG4SH_TYPE_SMTP}|\
|
3236
|
+
${__LOG4SH_CONFIG_LOG4J_CP}.${__LOG4SH_TYPE_SMTP})
|
3237
|
+
appender_setType $_lpa_appender ${__LOG4SH_TYPE_SMTP} ;;
|
3238
|
+
${__LOG4SH_TYPE_SYSLOG}|\
|
3239
|
+
${__LOG4SH_CONFIG_LOG4J_CP}.${__LOG4SH_TYPE_SYSLOG})
|
3240
|
+
appender_setType $_lpa_appender ${__LOG4SH_TYPE_SYSLOG} ;;
|
3241
|
+
*)
|
3242
|
+
_log4sh_error "appender type (${_lpa_value}) unrecognized"
|
3243
|
+
false
|
3244
|
+
;;
|
3245
|
+
esac
|
3246
|
+
[ $? -ne ${__LOG4SH_TRUE} ] && _lpa_rtrn=${__LOG4SH_ERROR}
|
3247
|
+
__log4sh_return=${_lpa_rtrn}
|
3248
|
+
unset _lpa_appender _lpa_key _lpa_rtrn _lpa_value
|
3249
|
+
return ${__log4sh_return}
|
3250
|
+
fi
|
3251
|
+
|
3252
|
+
# handle appender values and methods
|
3253
|
+
_lpa_key=`_log4sh_stripPropPrefix ${_lpa_key}`
|
3254
|
+
if [ "${_lpa_key}" '=' "`expr \"${_lpa_key}\" : '\([^.]*\)'`" ]; then
|
3255
|
+
case ${_lpa_key} in
|
3256
|
+
# General
|
3257
|
+
Threshold) appender_setLevel ${_lpa_appender} "${_lpa_value}" ;;
|
3258
|
+
layout) appender_setLayout ${_lpa_appender} "${_lpa_value}" ;;
|
3259
|
+
|
3260
|
+
# FileAppender
|
3261
|
+
DatePattern) ;; # unsupported
|
3262
|
+
File)
|
3263
|
+
_lpa_value=`eval echo "${_lpa_value}"`
|
3264
|
+
appender_file_setFile ${_lpa_appender} "${_lpa_value}"
|
3265
|
+
;;
|
3266
|
+
MaxBackupIndex)
|
3267
|
+
appender_file_setMaxBackupIndex ${_lpa_appender} "${_lpa_value}" ;;
|
3268
|
+
MaxFileSize)
|
3269
|
+
appender_file_setMaxFileSize ${_lpa_appender} "${_lpa_value}" ;;
|
3270
|
+
|
3271
|
+
# SMTPAppender
|
3272
|
+
To) appender_smtp_setTo ${_lpa_appender} "${_lpa_value}" ;;
|
3273
|
+
Subject) appender_smtp_setSubject ${_lpa_appender} "${_lpa_value}" ;;
|
3274
|
+
|
3275
|
+
# SyslogAppender
|
3276
|
+
SyslogHost) appender_syslog_setHost ${_lpa_appender} "${_lpa_value}" ;;
|
3277
|
+
Facility) appender_syslog_setFacility ${_lpa_appender} "${_lpa_value}" ;;
|
3278
|
+
|
3279
|
+
# catch unrecognized
|
3280
|
+
*)
|
3281
|
+
_log4sh_error "appender value/method (${_lpa_key}) unrecognized"
|
3282
|
+
false
|
3283
|
+
;;
|
3284
|
+
esac
|
3285
|
+
[ $? -ne ${__LOG4SH_TRUE} ] && _lpa_rtrn=${__LOG4SH_ERROR}
|
3286
|
+
__log4sh_return=${_lpa_rtrn}
|
3287
|
+
unset _lpa_appender _lpa_key _lpa_rtrn _lpa_value
|
3288
|
+
return ${__log4sh_return}
|
3289
|
+
fi
|
3290
|
+
|
3291
|
+
# handle appender layout values and methods
|
3292
|
+
_lpa_key=`_log4sh_stripPropPrefix ${_lpa_key}`
|
3293
|
+
case ${_lpa_key} in
|
3294
|
+
ConversionPattern) appender_setPattern ${_lpa_appender} "${_lpa_value}" ;;
|
3295
|
+
*)
|
3296
|
+
_log4sh_error "layout value/method (${_lpa_key}) unrecognized"
|
3297
|
+
false
|
3298
|
+
;;
|
3299
|
+
esac
|
3300
|
+
[ $? -ne ${__LOG4SH_TRUE} ] && _lpa_rtrn=${__LOG4SH_ERROR}
|
3301
|
+
__log4sh_return=${_lpa_rtrn}
|
3302
|
+
unset _lpa_appender _lpa_key _lpa_rtrn _lpa_value
|
3303
|
+
return ${__log4sh_return}
|
3304
|
+
}
|
3305
|
+
|
3306
|
+
#/**
|
3307
|
+
# <s:function group="Property" modifier="private">
|
3308
|
+
# <entry align="right">
|
3309
|
+
# <code>string</code>
|
3310
|
+
# </entry>
|
3311
|
+
# <entry>
|
3312
|
+
# <funcsynopsis>
|
3313
|
+
# <funcprototype>
|
3314
|
+
# <funcdef><function>_log4sh_propLogger</function></funcdef>
|
3315
|
+
# <paramdef>string <parameter>property</parameter></paramdef>
|
3316
|
+
# <paramdef>string <parameter>value</parameter></paramdef>
|
3317
|
+
# </funcprototype>
|
3318
|
+
# </funcsynopsis>
|
3319
|
+
# <para>(future) Configures log4sh with a <code>logger</code> configuration
|
3320
|
+
# statement. Sample output: "logger: property value".</para>
|
3321
|
+
# <funcsynopsis>
|
3322
|
+
# <funcsynopsisinfo>result=`_log4sh_propLogger $property $value`</funcsynopsisinfo>
|
3323
|
+
# </funcsynopsis>
|
3324
|
+
# </entry>
|
3325
|
+
# </s:function>
|
3326
|
+
#*/
|
3327
|
+
_log4sh_propLogger()
|
3328
|
+
{
|
3329
|
+
_prop=`_log4sh_stripPropPrefix $1`
|
3330
|
+
echo "logger: ${_prop} $2"
|
3331
|
+
unset _prop
|
3332
|
+
}
|
3333
|
+
|
3334
|
+
#
|
3335
|
+
# configure log4sh with a rootLogger configuration statement
|
3336
|
+
#
|
3337
|
+
# @param _key configuration command
|
3338
|
+
# @param _value configuration value
|
3339
|
+
#
|
3340
|
+
#/**
|
3341
|
+
# <s:function group="Property" modifier="private">
|
3342
|
+
# <entry align="right">
|
3343
|
+
# <emphasis>void</emphasis>
|
3344
|
+
# </entry>
|
3345
|
+
# <entry>
|
3346
|
+
# <funcsynopsis>
|
3347
|
+
# <funcprototype>
|
3348
|
+
# <funcdef><function>_log4sh_propRootLogger</function></funcdef>
|
3349
|
+
# <paramdef>string <parameter>rootLogger</parameter></paramdef>
|
3350
|
+
# </funcprototype>
|
3351
|
+
# </funcsynopsis>
|
3352
|
+
# <para>Configures log4sh with a <code>rootLogger</code> configuration
|
3353
|
+
# statement. It expects a comma separated string similar to the following:</para>
|
3354
|
+
# <para><code>log4sh.rootLogger=ERROR, stderr, R</code></para>
|
3355
|
+
# <para>The first option is the default logging level to set for all
|
3356
|
+
# of the following appenders that will be created, and all following options
|
3357
|
+
# are the names of appenders to create. The appender names must be
|
3358
|
+
# unique.</para>
|
3359
|
+
# <funcsynopsis>
|
3360
|
+
# <funcsynopsisinfo>_log4sh_propRootLogger $value</funcsynopsisinfo>
|
3361
|
+
# </funcsynopsis>
|
3362
|
+
# </entry>
|
3363
|
+
# </s:function>
|
3364
|
+
#*/
|
3365
|
+
_log4sh_propRootLogger()
|
3366
|
+
{
|
3367
|
+
__lprl_rootLogger=`echo "$@" |sed 's/ *, */,/g'`
|
3368
|
+
__lprl_count=`echo "${__lprl_rootLogger}" |sed 's/,/ /g' |wc -w`
|
3369
|
+
__lprl_index=1
|
3370
|
+
while [ ${__lprl_index} -le ${__lprl_count} ]; do
|
3371
|
+
__lprl_operand=`echo "${__lprl_rootLogger}" |cut -d, -f${__lprl_index}`
|
3372
|
+
if [ ${__lprl_index} -eq 1 ]; then
|
3373
|
+
logger_setLevel "${__lprl_operand}"
|
3374
|
+
else
|
3375
|
+
appender_exists "${__lprl_operand}"
|
3376
|
+
if [ $? -eq ${__LOG4SH_FALSE} ]; then
|
3377
|
+
logger_addAppender "${__lprl_operand}"
|
3378
|
+
else
|
3379
|
+
_log4sh_error "attempt to add already existing appender of name (${__lprl_operand})"
|
3380
|
+
fi
|
3381
|
+
fi
|
3382
|
+
__lprl_index=`expr ${__lprl_index} + 1`
|
3383
|
+
done
|
3384
|
+
|
3385
|
+
unset __lprl_count __lprl_index __lprl_operand __lprl_rootLogger
|
3386
|
+
}
|
3387
|
+
|
3388
|
+
#/**
|
3389
|
+
# <s:function group="Property" modifier="public">
|
3390
|
+
# <entry align="right">
|
3391
|
+
# <emphasis>void</emphasis>/boolean
|
3392
|
+
# </entry>
|
3393
|
+
# <entry>
|
3394
|
+
# <funcsynopsis>
|
3395
|
+
# <funcprototype>
|
3396
|
+
# <funcdef><function>log4sh_doConfigure</function></funcdef>
|
3397
|
+
# <paramdef>string <parameter>configFileName</parameter></paramdef>
|
3398
|
+
# </funcprototype>
|
3399
|
+
# </funcsynopsis>
|
3400
|
+
# <para>
|
3401
|
+
# Read configuration from a file. <emphasis role="strong">The existing
|
3402
|
+
# configuration is not cleared or reset.</emphasis> If you require a
|
3403
|
+
# different behavior, then call the <code>log4sh_resetConfiguration</code>
|
3404
|
+
# before calling <code>log4sh_doConfigure</code>.
|
3405
|
+
# </para>
|
3406
|
+
# <funcsynopsis>
|
3407
|
+
# <funcsynopsisinfo>log4sh_doConfigure myconfig.properties</funcsynopsisinfo>
|
3408
|
+
# </funcsynopsis>
|
3409
|
+
# </entry>
|
3410
|
+
# </s:function>
|
3411
|
+
#*/
|
3412
|
+
log4sh_doConfigure()
|
3413
|
+
{
|
3414
|
+
[ -n "${FUNCNAME:-}" ] \
|
3415
|
+
&& ${__LOG4SH_TRACE} "${FUNCNAME}()${BASH_LINENO:+'(called from ${BASH_LINENO})'}"
|
3416
|
+
|
3417
|
+
# prepare the environment for configuration
|
3418
|
+
log4sh_resetConfiguration
|
3419
|
+
|
3420
|
+
ldc_file=$1
|
3421
|
+
ldc_rtrn=${__LOG4SH_TRUE}
|
3422
|
+
|
3423
|
+
# strip the config prefix and dump output to a temporary file
|
3424
|
+
ldc_tmpFile="${__log4sh_tmpDir}/properties"
|
3425
|
+
${__LOG4SH_TRACE} "__LOG4SH_CONFIG_PREFIX='${__LOG4SH_CONFIG_PREFIX}'"
|
3426
|
+
grep "^${__LOG4SH_CONFIG_PREFIX}\." "${ldc_file}" >"${ldc_tmpFile}"
|
3427
|
+
|
3428
|
+
# read the file in. using a temporary file and a file descriptor here instead
|
3429
|
+
# of piping the file into the 'while read' because the pipe causes a fork
|
3430
|
+
# under some shells which makes it impossible to get the variables passed
|
3431
|
+
# back to the parent script.
|
3432
|
+
exec 3<&0 <"${ldc_tmpFile}"
|
3433
|
+
while read ldc_line; do
|
3434
|
+
ldc_key=`expr "${ldc_line}" : '\([^= ]*\) *=.*'`
|
3435
|
+
ldc_value=`expr "${ldc_line}" : '[^= ]* *= *\(.*\)'`
|
3436
|
+
|
3437
|
+
# strip the leading 'log4sh.'
|
3438
|
+
ldc_key=`_log4sh_stripPropPrefix ${ldc_key}`
|
3439
|
+
ldc_keyword=`_log4sh_getPropPrefix ${ldc_key}`
|
3440
|
+
case ${ldc_keyword} in
|
3441
|
+
alternative) _log4sh_propAlternative ${ldc_key} "${ldc_value}" ;;
|
3442
|
+
appender) _log4sh_propAppender ${ldc_key} "${ldc_value}" ;;
|
3443
|
+
logger) _log4sh_propLogger ${ldc_key} "${ldc_value}" ;;
|
3444
|
+
rootLogger) _log4sh_propRootLogger "${ldc_value}" ;;
|
3445
|
+
*)
|
3446
|
+
_log4sh_error "unrecognized properties keyword (${ldc_keyword})"
|
3447
|
+
false
|
3448
|
+
;;
|
3449
|
+
esac
|
3450
|
+
[ $? -ne ${__LOG4SH_TRUE} ] && ldc_rtrn=${__LOG4SH_ERROR}
|
3451
|
+
done
|
3452
|
+
exec 0<&3 3<&-
|
3453
|
+
|
3454
|
+
# remove the temporary file
|
3455
|
+
rm -f "${ldc_tmpFile}"
|
3456
|
+
|
3457
|
+
# activate all of the appenders
|
3458
|
+
for ldc_appender in ${__log4shAppenders}; do
|
3459
|
+
${__LOG4SH_APPENDER_FUNC_PREFIX}${ldc_appender}_activateOptions
|
3460
|
+
done
|
3461
|
+
|
3462
|
+
__log4sh_return=${ldc_rtrn}
|
3463
|
+
unset ldc_appender ldc_file ldc_tmpFile ldc_line ldc_key ldc_keyword
|
3464
|
+
unset ldc_value ldc_rtrn
|
3465
|
+
return ${__log4sh_return}
|
3466
|
+
}
|
3467
|
+
|
3468
|
+
#/**
|
3469
|
+
# <s:function group="Property" modifier="public">
|
3470
|
+
# <entry align="right">
|
3471
|
+
# <emphasis>void</emphasis>
|
3472
|
+
# </entry>
|
3473
|
+
# <entry>
|
3474
|
+
# <funcsynopsis>
|
3475
|
+
# <funcprototype>
|
3476
|
+
# <funcdef><function>log4sh_readProperties</function></funcdef>
|
3477
|
+
# <paramdef>string <parameter>configFileName</parameter></paramdef>
|
3478
|
+
# </funcprototype>
|
3479
|
+
# </funcsynopsis>
|
3480
|
+
# <para><emphasis role="strong">Deprecated as of 1.3.6</emphasis></para>
|
3481
|
+
# <para>
|
3482
|
+
# See <code>log4sh_doConfigure</code>.
|
3483
|
+
# </para>
|
3484
|
+
# <funcsynopsis>
|
3485
|
+
# <funcsynopsisinfo>log4sh_readProperties myconfig.properties</funcsynopsisinfo>
|
3486
|
+
# </funcsynopsis>
|
3487
|
+
# </entry>
|
3488
|
+
# </s:function>
|
3489
|
+
#*/
|
3490
|
+
log4sh_readProperties()
|
3491
|
+
{
|
3492
|
+
log4sh_doConfigure "$@"
|
3493
|
+
}
|
3494
|
+
|
3495
|
+
#/**
|
3496
|
+
# <s:function group="Property" modifier="public">
|
3497
|
+
# <entry align="right">
|
3498
|
+
# <emphasis>void</emphasis>
|
3499
|
+
# </entry>
|
3500
|
+
# <entry>
|
3501
|
+
# <funcsynopsis>
|
3502
|
+
# <funcprototype>
|
3503
|
+
# <funcdef><function>log4sh_resetConfiguration</function></funcdef>
|
3504
|
+
# <void />
|
3505
|
+
# </funcprototype>
|
3506
|
+
# </funcsynopsis>
|
3507
|
+
# <para>
|
3508
|
+
# This function completely resets the log4sh configuration to have no
|
3509
|
+
# appenders with a global logging level of ERROR.
|
3510
|
+
# </para>
|
3511
|
+
# <funcsynopsis>
|
3512
|
+
# <funcsynopsisinfo>log4sh_resetConfiguration</funcsynopsisinfo>
|
3513
|
+
# </funcsynopsis>
|
3514
|
+
# </entry>
|
3515
|
+
# </s:function>
|
3516
|
+
#*/
|
3517
|
+
# XXX if a configuration is *repeatedly* established via logger_addAppender and
|
3518
|
+
# reset using this command, there is a risk of running out of memory.
|
3519
|
+
log4sh_resetConfiguration()
|
3520
|
+
{
|
3521
|
+
__log4shAppenders=''
|
3522
|
+
__log4shAppenderCount=0
|
3523
|
+
__log4shAppenderCounts=''
|
3524
|
+
__log4shAppenderLayouts=''
|
3525
|
+
__log4shAppenderLevels=''
|
3526
|
+
__log4shAppenderPatterns=''
|
3527
|
+
__log4shAppenderTypes=''
|
3528
|
+
__log4shAppender_file_files=''
|
3529
|
+
__log4shAppender_rollingFile_maxBackupIndexes=''
|
3530
|
+
__log4shAppender_rollingFile_maxFileSizes=''
|
3531
|
+
__log4shAppender_smtp_tos=''
|
3532
|
+
__log4shAppender_smtp_subjects=''
|
3533
|
+
__log4shAppender_syslog_facilities=''
|
3534
|
+
__log4shAppender_syslog_hosts=''
|
3535
|
+
|
3536
|
+
logger_setLevel ERROR
|
3537
|
+
}
|
3538
|
+
|
3539
|
+
#==============================================================================
|
3540
|
+
# Thread
|
3541
|
+
#
|
3542
|
+
|
3543
|
+
#/**
|
3544
|
+
# <s:function group="Thread" modifier="public">
|
3545
|
+
# <entry align="right">
|
3546
|
+
# <code>string</code>
|
3547
|
+
# </entry>
|
3548
|
+
# <entry>
|
3549
|
+
# <funcsynopsis>
|
3550
|
+
# <funcprototype>
|
3551
|
+
# <funcdef><function>logger_getThreadName</function></funcdef>
|
3552
|
+
# <void />
|
3553
|
+
# </funcprototype>
|
3554
|
+
# </funcsynopsis>
|
3555
|
+
# <para>Gets the current thread name.</para>
|
3556
|
+
# <funcsynopsis>
|
3557
|
+
# <funcsynopsisinfo>threadName=`logger_getThreadName`</funcsynopsisinfo>
|
3558
|
+
# </funcsynopsis>
|
3559
|
+
# </entry>
|
3560
|
+
# </s:function>
|
3561
|
+
#*/
|
3562
|
+
logger_getThreadName()
|
3563
|
+
{
|
3564
|
+
echo ${__log4sh_threadName}
|
3565
|
+
}
|
3566
|
+
|
3567
|
+
#/**
|
3568
|
+
# <s:function group="Thread" modifier="public">
|
3569
|
+
# <entry align="right">
|
3570
|
+
# <emphasis>void</emphasis>
|
3571
|
+
# </entry>
|
3572
|
+
# <entry>
|
3573
|
+
# <funcsynopsis>
|
3574
|
+
# <funcprototype>
|
3575
|
+
# <funcdef><function>logger_setThreadName</function></funcdef>
|
3576
|
+
# <paramdef>string <parameter>threadName</parameter></paramdef>
|
3577
|
+
# </funcprototype>
|
3578
|
+
# </funcsynopsis>
|
3579
|
+
# <para>
|
3580
|
+
# Sets the thread name (e.g. the name of the script). This thread name can
|
3581
|
+
# be used with the '%t' conversion character within a
|
3582
|
+
# <option>PatternLayout</option>.
|
3583
|
+
# </para>
|
3584
|
+
# <funcsynopsis>
|
3585
|
+
# <funcsynopsisinfo>logger_setThreadName "myThread"</funcsynopsisinfo>
|
3586
|
+
# </funcsynopsis>
|
3587
|
+
# </entry>
|
3588
|
+
# </s:function>
|
3589
|
+
#*/
|
3590
|
+
logger_setThreadName()
|
3591
|
+
{
|
3592
|
+
_thread=$1
|
3593
|
+
|
3594
|
+
_length=`_log4sh_getArrayLength "$__log4sh_threadStack"`
|
3595
|
+
__log4sh_threadStack=`_log4sh_setArrayElement "$__log4sh_threadStack" $_length $_thread`
|
3596
|
+
__log4sh_threadName=$_thread
|
3597
|
+
|
3598
|
+
unset _length _thread
|
3599
|
+
}
|
3600
|
+
|
3601
|
+
#/**
|
3602
|
+
# <s:function group="Thread" modifier="public">
|
3603
|
+
# <entry align="right">
|
3604
|
+
# <emphasis>void</emphasis>
|
3605
|
+
# </entry>
|
3606
|
+
# <entry>
|
3607
|
+
# <funcsynopsis>
|
3608
|
+
# <funcprototype>
|
3609
|
+
# <funcdef><function>logger_pushThreadName</function></funcdef>
|
3610
|
+
# <paramdef>string <parameter>threadName</parameter></paramdef>
|
3611
|
+
# </funcprototype>
|
3612
|
+
# </funcsynopsis>
|
3613
|
+
# <para><emphasis role="strong">Deprecated as of 1.3.7</emphasis></para>
|
3614
|
+
# <para>
|
3615
|
+
# Sets the thread name (eg. the name of the script) and pushes the old on
|
3616
|
+
# to a stack for later use. This thread name can be used with the '%t'
|
3617
|
+
# conversion character within a <option>PatternLayout</option>.
|
3618
|
+
# </para>
|
3619
|
+
# <funcsynopsis>
|
3620
|
+
# <funcsynopsisinfo>logger_pushThreadName "myThread"</funcsynopsisinfo>
|
3621
|
+
# </funcsynopsis>
|
3622
|
+
# </entry>
|
3623
|
+
# </s:function>
|
3624
|
+
#*/
|
3625
|
+
logger_pushThreadName()
|
3626
|
+
{
|
3627
|
+
__log4sh_threadStack=`_log4sh_pushStack "$__log4sh_threadStack" $1`
|
3628
|
+
__log4sh_threadName=$1
|
3629
|
+
}
|
3630
|
+
|
3631
|
+
#/**
|
3632
|
+
# <s:function group="Thread" modifier="public">
|
3633
|
+
# <entry align="right">
|
3634
|
+
# <emphasis>void</emphasis>
|
3635
|
+
# </entry>
|
3636
|
+
# <entry>
|
3637
|
+
# <funcsynopsis>
|
3638
|
+
# <funcprototype>
|
3639
|
+
# <funcdef><function>logger_popThreadName</function></funcdef>
|
3640
|
+
# <void />
|
3641
|
+
# </funcprototype>
|
3642
|
+
# </funcsynopsis>
|
3643
|
+
# <para><emphasis role="strong">Deprecated as of 1.3.7</emphasis></para>
|
3644
|
+
# <para>
|
3645
|
+
# Removes the topmost thread name from the stack. The next thread name on
|
3646
|
+
# the stack is then placed in the <varname>__log4sh_threadName</varname>
|
3647
|
+
# variable. If the stack is empty, or has only one element left, then a
|
3648
|
+
# warning is given that no more thread names can be popped from the stack.
|
3649
|
+
# </para>
|
3650
|
+
# <funcsynopsis>
|
3651
|
+
# <funcsynopsisinfo>logger_popThreadName</funcsynopsisinfo>
|
3652
|
+
# </funcsynopsis>
|
3653
|
+
# </entry>
|
3654
|
+
# </s:function>
|
3655
|
+
#*/
|
3656
|
+
logger_popThreadName()
|
3657
|
+
{
|
3658
|
+
_length=`_log4sh_getArrayLength "$__log4sh_threadStack"`
|
3659
|
+
if [ $_length -gt 1 ]; then
|
3660
|
+
__log4sh_threadStack=`_log4sh_popStack "$__log4sh_threadStack"`
|
3661
|
+
__log4sh_threadName=`_log4sh_peekStack "$__log4sh_threadStack"`
|
3662
|
+
else
|
3663
|
+
echo 'log4sh:WARN no more thread names available on thread name stack.' >&2
|
3664
|
+
fi
|
3665
|
+
}
|
3666
|
+
|
3667
|
+
#==============================================================================
|
3668
|
+
# Trap
|
3669
|
+
#
|
3670
|
+
|
3671
|
+
#/**
|
3672
|
+
# <s:function group="Trap" modifier="public">
|
3673
|
+
# <entry align="right">
|
3674
|
+
# <emphasis>void</emphasis>
|
3675
|
+
# </entry>
|
3676
|
+
# <entry>
|
3677
|
+
# <funcsynopsis>
|
3678
|
+
# <funcprototype>
|
3679
|
+
# <funcdef><function>log4sh_cleanup</function></funcdef>
|
3680
|
+
# <void />
|
3681
|
+
# </funcprototype>
|
3682
|
+
# </funcsynopsis>
|
3683
|
+
# <para>This is a cleanup function to remove the temporary directory used by
|
3684
|
+
# log4sh. It is provided for scripts who want to do log4sh cleanup work
|
3685
|
+
# themselves rather than using the automated cleanup of log4sh that is
|
3686
|
+
# invoked upon a normal exit of the script.</para>
|
3687
|
+
# <funcsynopsis>
|
3688
|
+
# <funcsynopsisinfo>log4sh_cleanup</funcsynopsisinfo>
|
3689
|
+
# </funcsynopsis>
|
3690
|
+
# </entry>
|
3691
|
+
# </s:function>
|
3692
|
+
#*/
|
3693
|
+
log4sh_cleanup()
|
3694
|
+
{
|
3695
|
+
_log4sh_cleanup 'EXIT'
|
3696
|
+
}
|
3697
|
+
|
3698
|
+
#/**
|
3699
|
+
# <s:function group="Trap" modifier="private">
|
3700
|
+
# <entry align="right">
|
3701
|
+
# <emphasis>void</emphasis>
|
3702
|
+
# </entry>
|
3703
|
+
# <entry>
|
3704
|
+
# <funcsynopsis>
|
3705
|
+
# <funcprototype>
|
3706
|
+
# <funcdef><function>_log4sh_cleanup</function></funcdef>
|
3707
|
+
# <paramdef>string <parameter>signal</parameter></paramdef>
|
3708
|
+
# </funcprototype>
|
3709
|
+
# </funcsynopsis>
|
3710
|
+
# <para>This is a cleanup function to remove the temporary directory used by
|
3711
|
+
# log4sh. It should only be called by log4sh itself when it is taking
|
3712
|
+
# control of traps.</para>
|
3713
|
+
# <para>If there was a previously defined trap for the given signal, log4sh
|
3714
|
+
# will attempt to call the original trap handler as well so as not to break
|
3715
|
+
# the parent script.</para>
|
3716
|
+
# <funcsynopsis>
|
3717
|
+
# <funcsynopsisinfo>_log4sh_cleanup EXIT</funcsynopsisinfo>
|
3718
|
+
# </funcsynopsis>
|
3719
|
+
# </entry>
|
3720
|
+
# </s:function>
|
3721
|
+
#*/
|
3722
|
+
_log4sh_cleanup()
|
3723
|
+
{
|
3724
|
+
_lc__trap=$1
|
3725
|
+
${__LOG4SH_INFO} "_log4sh_cleanup(): the ${_lc__trap} signal was caught"
|
3726
|
+
|
3727
|
+
_lc__restoreTrap=${__LOG4SH_FALSE}
|
3728
|
+
_lc__oldTrap=''
|
3729
|
+
|
3730
|
+
# match trap to signal value
|
3731
|
+
case "${_lc__trap}" in
|
3732
|
+
EXIT) _lc__signal=0 ;;
|
3733
|
+
INT) _lc__signal=2 ;;
|
3734
|
+
TERM) _lc__signal=15 ;;
|
3735
|
+
esac
|
3736
|
+
|
3737
|
+
# do we possibly need to restore a previous trap?
|
3738
|
+
if [ -r "${__log4sh_trapsFile}" -a -s "${__log4sh_trapsFile}" ]; then
|
3739
|
+
# yes. figure out what we need to do
|
3740
|
+
if [ `grep "^trap -- " "${__log4sh_trapsFile}" >/dev/null; echo $?` -eq 0 ]
|
3741
|
+
then
|
3742
|
+
# newer trap command
|
3743
|
+
${__LOG4SH_DEBUG} 'newer POSIX trap command'
|
3744
|
+
_lc__restoreTrap=${__LOG4SH_TRUE}
|
3745
|
+
_lc__oldTrap=`egrep "(${_lc__trap}|${_lc__signal})$" "${__log4sh_trapsFile}" |\
|
3746
|
+
sed "s/^trap -- '\(.*\)' [A-Z]*$/\1/"`
|
3747
|
+
elif [ `grep "[0-9]*: " "${__log4sh_trapsFile}" >/dev/null; echo $?` -eq 0 ]
|
3748
|
+
then
|
3749
|
+
# older trap command
|
3750
|
+
${__LOG4SH_DEBUG} 'older style trap command'
|
3751
|
+
_lc__restoreTrap=${__LOG4SH_TRUE}
|
3752
|
+
_lc__oldTrap=`grep "^${_lc__signal}: " "${__log4sh_trapsFile}" |\
|
3753
|
+
sed 's/^[0-9]*: //'`
|
3754
|
+
else
|
3755
|
+
# unrecognized trap output
|
3756
|
+
_log4sh_error 'unable to restore old traps! unrecognized trap command output'
|
3757
|
+
fi
|
3758
|
+
fi
|
3759
|
+
|
3760
|
+
# do our work
|
3761
|
+
rm -fr "${__log4sh_tmpDir}"
|
3762
|
+
|
3763
|
+
# execute the old trap
|
3764
|
+
if [ ${_lc__restoreTrap} -eq ${__LOG4SH_TRUE} -a -n "${_lc__oldTrap}" ]; then
|
3765
|
+
${__LOG4SH_INFO} 'restoring previous trap of same type'
|
3766
|
+
eval "${_lc__oldTrap}"
|
3767
|
+
fi
|
3768
|
+
|
3769
|
+
# exit for all non-EXIT signals
|
3770
|
+
if [ "${_lc__trap}" != 'EXIT' ]; then
|
3771
|
+
# disable the EXIT trap
|
3772
|
+
trap 0
|
3773
|
+
|
3774
|
+
# add 127 to signal value and exit
|
3775
|
+
_lc__signal=`expr ${_lc__signal} + 127`
|
3776
|
+
exit ${_lc__signal}
|
3777
|
+
fi
|
3778
|
+
|
3779
|
+
unset _lc__oldTrap _lc__signal _lc__restoreTrap _lc__trap
|
3780
|
+
return
|
3781
|
+
}
|
3782
|
+
|
3783
|
+
|
3784
|
+
#==============================================================================
|
3785
|
+
# main
|
3786
|
+
#
|
3787
|
+
|
3788
|
+
# create a temporary directory
|
3789
|
+
__log4sh_tmpDir=`_log4sh_mktempDir`
|
3790
|
+
|
3791
|
+
# preserve old trap(s)
|
3792
|
+
__log4sh_trapsFile="${__log4sh_tmpDir}/traps"
|
3793
|
+
trap >"${__log4sh_trapsFile}"
|
3794
|
+
|
3795
|
+
# configure traps
|
3796
|
+
${__LOG4SH_INFO} 'setting traps'
|
3797
|
+
trap '_log4sh_cleanup EXIT' 0
|
3798
|
+
trap '_log4sh_cleanup INT' 2
|
3799
|
+
trap '_log4sh_cleanup TERM' 15
|
3800
|
+
|
3801
|
+
# alternative commands
|
3802
|
+
log4sh_setAlternative mail "${LOG4SH_ALTERNATIVE_MAIL:-mail}" ${__LOG4SH_TRUE}
|
3803
|
+
[ -n "${LOG4SH_ALTERNATIVE_NC:-}" ] \
|
3804
|
+
&& log4sh_setAlternative nc "${LOG4SH_ALTERNATIVE_NC}"
|
3805
|
+
|
3806
|
+
# load the properties file
|
3807
|
+
${__LOG4SH_TRACE} "__LOG4SH_CONFIGURATION='${__LOG4SH_CONFIGURATION}'"
|
3808
|
+
if [ "${__LOG4SH_CONFIGURATION}" != 'none' -a -r "${__LOG4SH_CONFIGURATION}" ]
|
3809
|
+
then
|
3810
|
+
${__LOG4SH_INFO} 'configuring via properties file'
|
3811
|
+
log4sh_doConfigure "${__LOG4SH_CONFIGURATION}"
|
3812
|
+
else
|
3813
|
+
if [ "${__LOG4SH_CONFIGURATION}" != 'none' ]; then
|
3814
|
+
_log4sh_warn 'No appenders could be found.'
|
3815
|
+
_log4sh_warn 'Please initalize the log4sh system properly.'
|
3816
|
+
fi
|
3817
|
+
${__LOG4SH_INFO} 'configuring at runtime'
|
3818
|
+
|
3819
|
+
# prepare the environment for configuration
|
3820
|
+
log4sh_resetConfiguration
|
3821
|
+
|
3822
|
+
# note: not using the constant variables here (e.g. for ConsoleAppender) so
|
3823
|
+
# that those perusing the code can have a working example
|
3824
|
+
logger_setLevel ${__LOG4SH_LEVEL_ERROR_STR}
|
3825
|
+
logger_addAppender stdout
|
3826
|
+
appender_setType stdout ConsoleAppender
|
3827
|
+
appender_setLayout stdout PatternLayout
|
3828
|
+
appender_setPattern stdout '%-4r [%t] %-5p %c %x - %m%n'
|
3829
|
+
fi
|
3830
|
+
|
3831
|
+
# restore the previous set of shell flags
|
3832
|
+
for _log4sh_shellFlag in ${__LOG4SH_SHELL_FLAGS}; do
|
3833
|
+
echo ${__log4sh_oldShellFlags} |grep ${_log4sh_shellFlag} >/dev/null \
|
3834
|
+
|| set +${_log4sh_shellFlag}
|
3835
|
+
done
|
3836
|
+
unset _log4sh_shellFlag
|
3837
|
+
|
3838
|
+
#/**
|
3839
|
+
# </s:shelldoc>
|
3840
|
+
#*/
|