How does logging in scripts differ between distributions?

Linux scripting, logging differences, Linux distributions, script logging, syslog, journald
This article explores how logging in scripts can vary between different Linux distributions, highlighting key differences and examples of implementation.

        #!/bin/bash

        # Function to log messages
        log_message() {
            local MESSAGE="$1"
            # Check if the distribution uses syslog or journald
            if [[ -f /var/log/syslog ]]; then
                echo "$(date '+%Y-%m-%d %H:%M:%S') - $MESSAGE" >> /var/log/syslog
            elif [[ -d /run/systemd/journal ]]; then
                echo "$MESSAGE" | systemd-cat
            else
                echo "Unsupported logging method"
            fi
        }

        # Example usage
        log_message "This is a log entry for the script."
    

Linux scripting logging differences Linux distributions script logging syslog journald