Skip to content

Commit 371f705

Browse files
authored
Merge pull request #2939 from input-output-hk/feature/ddw-1062-showcase-jq
2 parents dcaba70 + 3c650dd commit 371f705

File tree

3 files changed

+169
-2
lines changed

3 files changed

+169
-2
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ installers/tls/client
4141
installers/tls/server
4242
installers/DLLs
4343
installers/libressl
44+
installers/cfg-files
45+
installers/config.yaml
46+
installers/icons/electron.icns
47+
installers/installer-config.json
48+
installers/topology.yaml
4449

4550
# temporary certs for daedalus dev
4651
tls/client

CHANGELOG.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
- Fixed phrasing of insufficient funds for tokens message ([PR 2966](https://github.com/input-output-hk/daedalus/pull/2966))
88

9-
## 4.10.0
10-
119
### Features
1210

1311
- Added support for Ledger Nano S Plus ([PR 2975](https://github.com/input-output-hk/daedalus/pull/2975))

scripts/filter-logs.sh

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o pipefail
5+
set -o nounset
6+
7+
myDir=$(dirname "$0")
8+
9+
# --- Where are we?
10+
11+
uname=$(uname)
12+
is_linux=
13+
is_darwin=
14+
if [ "$uname" = "Linux" ] ; then is_linux=1 ; fi
15+
if [ "$uname" = "Darwin" ] ; then is_darwin=1 ; fi
16+
17+
# --- Find `default_logfile`
18+
19+
default_logfile=
20+
if [ -n "$is_darwin" ] ; then
21+
default_logfile="$HOME/Library/Application Support/Daedalus Mainnet/Logs/pub/Daedalus.json"
22+
:
23+
if [ ! -e "$default_logfile" ] ; then
24+
candidate=$(find "$HOME/Library/Application Support" -maxdepth 1 -mindepth 1 -type d -name 'Daedalus*' | head -n 1)
25+
if [ -n "$candidate" ] ; then
26+
default_logfile="$candidate"/Logs/pub/Daedalus.json
27+
fi
28+
fi
29+
elif [ -n "$is_linux" ] ; then
30+
default_logfile="$HOME"/.local/share/Daedalus/mainnet/Logs/pub/Daedalus.json
31+
if [ ! -e "$default_logfile" ] ; then
32+
if [ -e "$HOME"/.local/share/Daedalus/ ] ; then
33+
candidate=$(find "$HOME"/.local/share/Daedalus/ -mindepth 1 -maxdepth 1 -type d | head -n 1)
34+
if [ -n "$candidate" ] ; then
35+
default_logfile="$candidate"/Logs/pub/Daedalus.json
36+
fi
37+
fi
38+
fi
39+
fi
40+
41+
# --- Print usage
42+
43+
print_usage() {
44+
echo "Usage: $0 [OPTION]..."
45+
echo
46+
echo " -h, --help Display help."
47+
echo " -f, --follow Continue processing as the log file grows."
48+
echo " -c, --compact Output compact instead of pretty-printed JSON."
49+
echo " -i, --input <file> Deadalus.json log location (default: $default_logfile)."
50+
echo " -m, --msg-contains <substring> Filter down to entries ‘.msg’ of which contains a <substring>."
51+
echo " --app-contains <string> Filter down to entries ‘.app’ of which contains a <string> element."
52+
echo " -d, --data-key <key> Filter down to entries ‘.data’ of which contains a <key> key."
53+
echo " --data-kv <key> <value> Filter down to entries ‘.data’ of which contains a <key> with value <value>."
54+
}
55+
56+
# --- Parse arguments
57+
58+
follow_mode=
59+
compact_mode=
60+
input="$default_logfile"
61+
filter_msg_contains=
62+
filter_app_contains=
63+
filter_data_key=
64+
filter_data_kv_key=
65+
filter_data_kv_value=
66+
67+
while [ $# -gt 0 ] ; do
68+
case "$1" in
69+
--help | -h ) print_usage ; exit 0 ;;
70+
--follow | -f ) follow_mode=1 ;;
71+
--compact | -c ) compact_mode=1 ;;
72+
--input | -i ) shift ; input="$1" ;;
73+
--msg-contains | -m ) shift ; filter_msg_contains="$1" ;;
74+
--app-contains ) shift ; filter_app_contains="$1" ;;
75+
--data-key | -d ) shift ; filter_data_key="$1" ;;
76+
--data-kv ) shift ; filter_data_kv_key="$1" ; shift ; filter_data_kv_value="$1" ;;
77+
* ) echo >&2 'fatal: unknown arguments:' "$@" ; print_usage ; exit 1 ;;
78+
esac
79+
shift
80+
done
81+
82+
if [ -n "${DEBUG:-}" ] ; then
83+
echo 2>&1 "; follow_mode = $follow_mode"
84+
echo 2>&1 "; compact_mode = $compact_mode"
85+
echo 2>&1 "; input = $input"
86+
echo 2>&1 "; filter_msg_contains = $filter_msg_contains"
87+
echo 2>&1 "; filter_app_contains = $filter_app_contains"
88+
echo 2>&1 "; filter_data_key = $filter_data_key"
89+
echo 2>&1 "; filter_data_kv_key = $filter_data_kv_key"
90+
echo 2>&1 "; filter_data_kv_value = $filter_data_kv_value"
91+
fi
92+
93+
# --- Find jq
94+
95+
if type jq >/dev/null 2>&1 ; then
96+
:
97+
else
98+
echo >&2 "warn: no ‘jq’ found, will use one from Nixpkgs"
99+
default_nix="$myDir"/../default.nix
100+
if [ -e "$default_nix" ] ; then
101+
jq_package=$(nix-build "$default_nix" -A pkgs.jq)
102+
else
103+
jq_package=$(nix-build '<nixpkgs>' -A pkgs.jq)
104+
fi
105+
export PATH="$jq_package/bin:$PATH"
106+
fi
107+
108+
# --- Filters
109+
110+
read_source() {
111+
if [ -n "$follow_mode" ] ; then
112+
# 10¹⁰ ≈ ∞
113+
tail -n 999999999 -F "$input"
114+
else
115+
cat "$input"
116+
fi
117+
}
118+
119+
filter_dev_log_tags() {
120+
sed -r 's/^\[.*\{/\{/'
121+
}
122+
123+
pretty_print() {
124+
if [ -n "$compact_mode" ] ; then
125+
jq --unbuffered -c .
126+
else
127+
# could be just `cat`, but we want colors!
128+
jq --unbuffered .
129+
fi
130+
}
131+
132+
f_msg_contains() {
133+
if [ -n "$filter_msg_contains" ] ; then
134+
jq --unbuffered --arg arg1 "$filter_msg_contains" -c 'select(.msg | contains($arg1))'
135+
else
136+
cat
137+
fi
138+
}
139+
140+
f_app_contains() {
141+
if [ -n "$filter_app_contains" ] ; then
142+
jq --unbuffered --arg arg1 "$filter_app_contains" -c 'select(.app[] | contains($arg1))'
143+
else
144+
cat
145+
fi
146+
}
147+
148+
f_data_key() {
149+
if [ -n "$filter_data_key" ] ; then
150+
jq --unbuffered --arg key1 "$filter_data_key" -c 'select(.data | .[$key1])'
151+
else
152+
cat
153+
fi
154+
}
155+
156+
f_data_kv() {
157+
if [ -n "$filter_data_kv_key" ] ; then
158+
jq --unbuffered --arg key1 "$filter_data_kv_key" --arg value1 "$filter_data_kv_value" -c 'select(.data | .[$key1] == $value1)'
159+
else
160+
cat
161+
fi
162+
}
163+
164+
read_source | filter_dev_log_tags | f_msg_contains | f_app_contains | f_data_key | f_data_kv | pretty_print

0 commit comments

Comments
 (0)