Maybe interesting for all Shelly owners…especially those writing scripts on their devices 
During our intense debugging session around Blu Gateway Script OOM, I invested quite some time to set up a remote logging server on my OpenHABian RPi. I thought it might be worthwile sharing it with you 
I started with installing rsyslog and setting up the directories:
sudo apt install rsyslog
sudo mkdir /var/log/rsyslog
sudo mkdir /var/log/remote
sudo chown root:adm /var/log/remote
sudo chmod 0755 /var/log/remote
I put both the actual logging dir as well as the spool directory into /var/log/…, as this is placed in ZRAM and so our remote logger will be 100% SD card safe.
Then, I edited the config file (sudo nano /etc/rsyslog.conf) to use the dirs named above, to:
- fully disable local syslogging
- enable remote syslog via TCP and UDP
- create one file per client
- try to name it by its hostname, remove illegal characters
- if no hostname available, use the IP address
# /etc/rsyslog.conf configuration file for rsyslog
#
# For more information install rsyslog-doc and see
# /usr/share/doc/rsyslog-doc/html/configuration/index.html
#################
#### MODULES ####
#################
#module(load="imuxsock") # provides support for local system logging
#module(load="imklog") # provides kernel logging support
#module(load="immark") # provides --MARK-- message capability
# provides UDP syslog reception
module(load="imudp")
input(type="imudp" port="514")
# provides TCP syslog reception
module(load="imtcp")
input(type="imtcp" port="514")
###########################
#### GLOBAL DIRECTIVES ####
###########################
#
# Set the default permissions for all log files.
#
$FileOwner root
$FileGroup adm
$FileCreateMode 0644
$DirCreateMode 0755
$Umask 0022
#
# Where to place spool and state files
#
$WorkDirectory /var/log/rsyslog
#
# Include all config files in /etc/rsyslog.d/
#
$IncludeConfig /etc/rsyslog.d/*.conf
###############
#### RULES ####
###############
#
# Log anything besides private authentication messages to a single log file
#
#*.*;auth,authpriv.none -/var/log/syslog
#
# Log commonly used facilities to their own log file
#
#auth,authpriv.* /var/log/auth.log
#cron.* -/var/log/cron.log
#kern.* -/var/log/kern.log
#mail.* -/var/log/mail.log
#user.* -/var/log/user.log
#
# Emergencies are sent to everybody logged in.
#
#*.emerg :omusrmsg:*
# --- Template for hostname, sanitized ---
template(name="RemoteFileByHost" type="string"
string="/var/log/remote/%$!safehostname%.log"
)
# --- Ruleset: sanitize hostname or fallback to IP ---
# First, compute a safe hostname variable
if ($hostname != "") then {
# Copy hostname into a global variable and replace illegal chars
set $!safehostname = replace($hostname, '[^a-zA-Z0-9_-]', '_');
} else {
# Fallback to IP address
set $!safehostname = $fromhost-ip;
}
# --- Only accept remote messages ---
if ($fromhost != "localhost") then {
action(type="omfile" dynaFile="RemoteFileByHost")
}
Load the config and make the service persistent by:
sudo systemctl restart rsyslog
sudo systemctl enable rsyslog
As it immediately starts after installation via apt and logs local events, it might be necessary to remove unwanted logfiles it created:
sudo rm -rf /var/spool/rsyslog/
sudo rm /var/log/syslog /var/log/auth.log /var/log/cron.log /var/log/kern.log /var/log/user.log
sudo rm -rf /var/log/exim4/
As it’s only used for remote logging, there is no time pressure to get it started early in boot. Rather be safe and wait until systemd reached multi-user.target - ZRAM is surely mounted, networking is surely up at that time. Therefore, I created an overlay for systemd:
sudo systemctl edit rsyslog.service
and insert:
[Unit]
Description=Remote System Logging Service
After=multi-user.target
Wants=multi-user.target
Next, I set up logrotate to take care about the logfiles:
sudo nano /etc/logrotate.d/remote-syslog
and write there:
/var/log/remote/*.log {
size 10M
rotate 7
missingok
notifempty
compress
delaycompress
copytruncate
daily
}
This will keep 7 files per client, check once per day, and try to limit file size below 10M.
That’s already it! You can now go to:
[Settings] [Debug] [UDP Logging] in the config website of your Shelly and enter
<OH_Server_IP>:514
and press Save Settings.
Immediately after that, you should see the logs appearing in /var/log/remote.