Part 3: Redirecting Logs to Log Center

Time to tackle the logging topic. By default, openHAB logs to several logfiles in userdata/logs with alternating logging files. When you followed the first parts of this post series, you don’t expose log data to the outer world – but you somehow need to read the logs. Luckily, DSM includes the Log Center to gather all your logs in one place. In this post, you’ll learn how to redirect the logs.

First, some preparation. Create a directory in your preferred location. After this, open the Log Center from your applications and go the Archive Settings. Click Select Location and choose the directory you created before.

Setting the destination is a precondition for the receiving of logs. Go to Log Receiving and select the Create button in the top bar. Call this receiver openhab, select BSD format and use TCP protocol.

The Synology part is done, time for openHAB. In DSM, open File Station and navigate to userdata/etc. Download org.ops4j.pax.logging.cfg and open the file in the editor of your choice. Here you will find the loggers for openhab.log, events.log and audit.log. The appenders start with

log4j2.appender.out.type

or event or audit instead of out. Replace all three loggers with the following configuration.

# openhab.log
log4j2.appender.out.type = Socket
log4j2.appender.out.name = LOGFILE
log4j2.appender.out.host = 192.168.178.42
log4j2.appender.out.port = 514
log4j2.appender.out.protocol = TCP
log4j2.appender.out.immediateFlush = true
log4j2.appender.out.layout.type = PatternLayout
log4j2.appender.out.layout.pattern = <%level{TRACE=7, DEBUG=7, INFO=6, WARN=4, ERROR=3, Fatal=0}>%d{MMM dd HH:mm:ss} openHAB openhab.log %replace{%m}{\n}{\u2028}%n

# Event log appender
log4j2.appender.event.type = Socket
log4j2.appender.event.name = EVENT
log4j2.appender.event.host = 192.168.178.42
log4j2.appender.event.port = 514
log4j2.appender.event.protocol = TCP
log4j2.appender.event.immediateFlush = true
log4j2.appender.event.layout.type = PatternLayout
log4j2.appender.event.layout.pattern = <%level{TRACE=7, DEBUG=7, INFO=6, WARN=4, ERROR=3, Fatal=0}>%d{MMM dd HH:mm:ss} openHAB event.log %replace{%m}{\n}{\u2028}%n

# Audit file appender
log4j2.appender.audit.type = Socket
log4j2.appender.audit.name = AUDIT
log4j2.appender.audit.host = 192.168.178.42
log4j2.appender.audit.port = 514
log4j2.appender.audit.protocol = TCP
log4j2.appender.audit.immediateFlush = true
log4j2.appender.audit.layout.type = PatternLayout
log4j2.appender.audit.layout.pattern = <%level{TRACE=7, DEBUG=7, INFO=6, WARN=4, ERROR=3, Fatal=0}>%d{MMM dd HH:mm:ss} openHAB audit.log %replace{%m}{\n}{\u2028}%n

Sources:

Just wait a few seconds and you should see the log entries in your Log Center. Now your openHAB won’t write to the disk but to the center. Here you can decide what to do with your logs.

Now openHAB is redirecting all the logs to your Log Center where you can do further actions. Just one more post in this series and your openHAB will run including backups.

Part 1: Use openHAB with Synology DSM
Part 2: MySQL persistence for openHAB
Part 3: Redirect openHAB logs to Log Center
Part 4: Scheduled database backups with DSM

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert