Skip to content

Instantly share code, notes, and snippets.

@ammarnajjar
Last active May 27, 2024 14:37
Show Gist options
  • Save ammarnajjar/8203e242a5f1d772d1a0beb104225e27 to your computer and use it in GitHub Desktop.
Save ammarnajjar/8203e242a5f1d772d1a0beb104225e27 to your computer and use it in GitHub Desktop.
k9s plugin to pretty print json logs using jq
# $XDG_CONFIG_HOME/k9s/plugins.yaml
plugins:
jqlogs:
shortCut: Ctrl-J
confirm: false
description: "Logs (jq)"
scopes:
- pod
command: sh
background: false
args:
- -c
- "kubectl logs -f $NAME -n $NAMESPACE --context $CONTEXT |jq -SR '. as $line | try (fromjson) catch $line'"
jqlogsd:
shortCut: Ctrl-J
confirm: false
description: "Logs (jq)"
scopes:
- deployment
command: sh
background: false
args:
- -c
- "kubectl logs -f deployment/$NAME -n $NAMESPACE --context $CONTEXT |jq -SR '. as $line | try (fromjson) catch $line'"
jqlogss:
shortCut: Ctrl-J
confirm: false
description: "Logs (jq)"
scopes:
- service
command: sh
background: false
args:
- -c
- "kubectl logs -f service/$NAME -n $NAMESPACE --context $CONTEXT |jq -SR '. as $line | try (fromjson) catch $line'"
@rassie
Copy link

rassie commented Mar 28, 2024

This does not work for pods with multiple containers, but with added scope it does:

    jqlogsc:
        shortCut: Ctrl-J
        confirm: false
        description: "Logs (jq)"
        scopes:
            - container
        command: sh
        background: false
        args:
            - -c
            - "kubectl logs -f pod/$POD -c $NAME -n $NAMESPACE --context $CONTEXT |jq -SR '. as $line | try (fromjson) catch $line'"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment