#!/bin/bash
#
# config: 134 1
# @brief: Collect user initialized PID specific journal log information.
#

# shellcheck source=tools/dreport.d/include.d/functions
. "$DREPORT_INCLUDE"/functions

# pid is set by dreport
declare pid

desc="Journal pid:$pid log"

if [ "$pid" -eq "$ZERO" ]; then
    log_warning "Missing PID, Collecting last 500 journal entries"
    file_name="journal.log"
    command="journalctl --namespace=* -o verbose -n $JOURNAL_LINE_LIMIT"
else
    file_name="journal-pid-$pid.log"
    command="journalctl --namespace=* -o verbose _PID=$pid"
fi

add_cmd_output "$command" "$file_name" "$desc"
