-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjlogs
More file actions
executable file
·79 lines (76 loc) · 2.69 KB
/
Copy pathjlogs
File metadata and controls
executable file
·79 lines (76 loc) · 2.69 KB
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
71
72
73
74
75
76
77
78
79
#!/bin/bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Parse service name and command
if [[ $# -eq 0 ]]; then
# No arguments - show help
echo "❗ Service name is required."
echo "Use 'jlogs help' to see usage."
exit 1
elif [[ $# -eq 1 ]]; then
case "$1" in
"help"|"h"|"--help")
# Show help without requiring service name
SERVICE_NAME=""
COMMAND="help"
;;
"follow"|"f"|"errors"|"e"|"today"|"t"|"table"|"table-follow")
echo "❗ Service name is required."
echo "Use 'jlogs help' to see usage."
exit 1
;;
*)
SERVICE_NAME="$1"
COMMAND=""
;;
esac
else
SERVICE_NAME="$1"
COMMAND="$2"
fi
case "${COMMAND:-}" in
"follow"|"f")
echo "🔄 Following $SERVICE_NAME logs (Ctrl+C to exit)..."
journalctl -u "$SERVICE_NAME" -f | ccze -A
;;
"errors"|"e")
echo "❌ Showing errors and warnings for $SERVICE_NAME..."
journalctl -u "$SERVICE_NAME" --since "1 hour ago" | grep -E "(ERROR|WARNING)" | ccze -A
;;
"today"|"t")
echo "📅 Showing today's logs for $SERVICE_NAME..."
journalctl -u "$SERVICE_NAME" --since today | ccze -A
;;
"table")
echo "📊 Table format (last hour) for $SERVICE_NAME..."
"$SCRIPT_DIR/jlogfmt" -h 1 -s "$SERVICE_NAME"
;;
"table-follow")
echo "📊 Table format (following) for $SERVICE_NAME..."
"$SCRIPT_DIR/jlogfmt" -f -s "$SERVICE_NAME"
;;
"help"|"h"|"--help")
echo "🔍 jlogs - JSON Log Viewer Commands:"
echo ""
echo "Usage: jlogs <service_name> [command]"
echo ""
echo "Commands:"
echo " follow Follow logs in real-time with colors"
echo " errors Show only errors and warnings"
echo " today Show today's logs"
echo " table Show last hour in table format (jlogfmt)"
echo " table-follow Follow logs in table format (jlogfmt)"
echo " help Show this help message"
echo ""
echo "Examples:"
echo " jlogs nginx # Show last hour of nginx logs"
echo " jlogs nginx follow # Follow nginx logs"
echo " jlogs nginx errors # Show nginx errors"
echo " jlogs nginx table # Beautiful table format with jlogfmt"
echo ""
echo "Advanced: Use ./jlogfmt for more options"
;;
*)
echo "📄 Showing last hour of logs for $SERVICE_NAME..."
journalctl -u "$SERVICE_NAME" --since "1 hour ago" | ccze -A
;;
esac