forked from gchq/stroom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetLogLevels.sh
executable file
·70 lines (54 loc) · 1.92 KB
/
setLogLevels.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Script to change the log level of multiple class/packages
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
set -e
#Shell Colour constants for use in 'echo -e'
#e.g. echo -e "My message ${GREEN}with just this text in green${NC}"
RED='\033[1;31m'
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
BLUE='\033[1;34m'
NC='\033[0m' # No Colour
readonly URL="http://127.0.0.1:8081/stroomAdmin/tasks/log-level"
readonly CURL="curl"
readonly HTTPIE="http"
send_request() {
packageOrClass=$1
newLogLevel=$2
echo -e "Setting ${GREEN}${packageOrClass}${NC} to ${GREEN}${newLogLevel}${NC}"
echo
if [ "${binary}" = "${HTTPIE}" ]; then
${HTTPIE} --headers -f POST ${URL} logger="${packageOrClass}" level="${newLogLevel}"
else
${CURL} -X POST -d "logger=${packageOrClass}&level=${newLogLevel}" ${URL}
fi
}
main() {
if ! [ -x "$(command -v http > /dev/null)" ]; then
echo -e "${YELLOW}WARN${NC} - ${BLUE}httpie${NC} is not installed (see ${BLUE}https://httpie.org${NC}), falling back to ${BLUE}curl${NC}." >&2
echo
binary="${CURL}"
else
binary="${HTTPIE}"
fi
# should have an arg count that is a multiple of two
if [ $# -eq 0 ] || [ $(( $# % 2 )) -ne 0 ]; then
echo -e "${RED}ERROR${NC} - Invalid arguments" >&2
echo -e "Usage: ${BLUE}$0${GREEN} packageOrClass1 newLogLevel packageOrClassN newLogLevel ...${NC}" >&2
echo -e "e.g: ${BLUE}$0${GREEN} stroom.startup.App DEBUG stroom.startup.Config TRACE${NC}" >&2
exit 1
fi
echo -e "Using URL ${BLUE}${URL}${NC}"
echo
#loop through the pairs of args
while [ $# -gt 0 ]; do
packageOrClass="$1"
newLogLevel="$2"
send_request "${packageOrClass}" "${newLogLevel}"
#bin the two args we have just used
shift 2
done
echo -e "${GREEN}Done${NC}"
}
main "$@"