Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for byte arrrays #6

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion format.jq
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,38 @@ def fmt_unit($entry):
+"]"
;

# Convert a byte array into a string
# Source: https://stackoverflow.com/a/48431552

def btostring:
[foreach .[] as $item (
[0, 0]
;
if .[0] > 0 then [.[0] - 1, .[1] * 64 + ($item % 64)]
elif $item >= 240 then [3, $item % 8]
elif $item >= 224 then [2, $item % 16]
elif $item >= 192 then [1, $item % 32]
elif $item < 128 then [0, $item]
else error("Malformed UTF-8 bytes")
end
;
if .[0] == 0 then .[1] else empty end
)] | implode
;


def fmt_message($msg):
if $msg | type == "array" then
$msg | btostring
else
$msg
end
;

# Select fields from the journalctl output and tranform to
# a human readable format
def fmt_entry($entry):
[fmt_date($entry.__REALTIME_TIMESTAMP), fmt_unit($entry), .MESSAGE] | join(" ")
[fmt_date($entry.__REALTIME_TIMESTAMP), fmt_unit($entry), fmt_message(.MESSAGE)] | join(" ")
;

# Process the entry
Expand Down
1 change: 1 addition & 0 deletions repo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type: docker
Loading