Tutorial: Installing and Configuring Logdy.dev as frontail replacement as a System Init for OpenHAB

This tutorial explains how to install and set up Logdy.dev as a system service integrated with OpenHAB. By following these steps, you’ll configure Logdy to monitor and process OpenHAB logs, presenting the information in a structured and interactive UI.


Prerequisites

  1. OpenHAB installed and running on your system.
  2. Logdy binary installed curl https://logdy.dev/install.sh | sh
    https://logdy.dev/docs/quick-start
  3. Basic familiarity with terminal commands and system configuration.

Step 1: Configure Logdy as a Systemd Service

Create a systemd service file for Logdy to ensure it runs alongside OpenHAB and processes its logs.

  1. Open a terminal and create the file:
sudo nano /etc/systemd/system/logdy.service
  1. Paste the following content into the file:
[Unit]
Description=Logdy Service
After=openhab.service
PartOf=openhab.service

[Service]
# User and group settings
User=root
Group=root

# Path to the Logdy binary and its configuration
ExecStart=/usr/local/bin/logdy --api-key="openhab" --port 5000 --ui-ip=[yourip] socket 49152 49153 49154

# Post-start commands to forward OpenHAB logs
ExecStartPost=/bin/bash -c 'tail -f /var/log/openhab/events.log | /usr/local/bin/logdy forward 49153 > /dev/null 2>&1 &'
ExecStartPost=/bin/bash -c 'tail -f /var/log/openhab/openhab.log | /usr/local/bin/logdy forward 49152 > /dev/null 2>&1 &'

# Restart policy
Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target
  1. Save the file and exit the editor.
  2. Reload the systemd daemon to recognize the new service:
sudo systemctl daemon-reload
  1. Enable the Logdy service to start at boot:
sudo systemctl enable logdy.service
  1. Start the service:
sudo systemctl start logdy.service
  1. Check the service status to ensure it’s running correctly:
sudo systemctl status logdy.service

Step 2: Configure config.json for Logdy

The config.json file defines how Logdy processes and displays the logs. Here’s a sample configuration tailored for OpenHAB:

  1. Open or create the configuration file

  2. Paste the following JSON content:

{
    "name": "main",
    "columns": [
        {
            "id": "187978",
            "name": "raw",
            "handlerTsCode": "(line: Message): CellHandler => { return { text: line.content || \"-\" }; }",
            "idx": 0,
            "width": 637,
            "faceted": false,
            "hidden": true
        },
        {
            "id": "860109",
            "name": "Time",
            "handlerTsCode": "(line: Message): CellHandler => { if (line.origin.port == \"49152\" || line.origin.port == \"49153\") { let match = line.content.match(/(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\\.\\d{3})/); let logTime = match ? match[1] : \"-\"; return { text: logTime }; } }",
            "faceted": false,
            "idx": 6,
            "width": 180
        },
        {
            "id": "421314",
            "name": "Log Level",
            "handlerTsCode": "(line: Message): CellHandler => { if (line.origin.port == \"49152\" || line.origin.port == \"49153\") { let match = line.content.match(/\\[(INFO|WARN|ERROR)\\s*\\]/); let logLevel = match ? match[1] : \"-\"; if (logLevel == \"INFO\") { return { text: logLevel, style: { backgroundColor: \"#B0F1B5\" } }; } else if (logLevel == \"WARN\") { return { text: logLevel, style: { backgroundColor: \"#FFD580\" } }; } else if (logLevel == \"ERROR\") { return { text: logLevel, style: { backgroundColor: \"#FF4C4C\" } }; } else { return { text: logLevel }; } } }",
            "faceted": false,
            "width": 79,
            "idx": 1
        },
        {
            "id": "331323",
            "name": "Source",
            "handlerTsCode": "(line: Message): CellHandler => { if (line.origin.port == \"49152\" || line.origin.port == \"49153\") { let match = line.content.match(/\\[(INFO|WARN|ERROR)\\s*\\]\\s\\[(.*?)\\]/); let logSource = match ? match[2] : \"-\"; return { text: logSource }; } }",
            "faceted": false,
            "idx": 5,
            "width": 307
        },
        {
            "id": "102306",
            "name": "Item Name",
            "handlerTsCode": "(line: Message): CellHandler => { if (line.origin.port == \"49152\" || line.origin.port == \"49153\") { let match = line.content.match(/Item [<'\"]([^']+)[>'\"]/); let itemName = match ? match[1] : \"-\"; return { text: itemName }; } }",
            "faceted": true,
            "idx": 2,
            "width": 344
        },
        {
            "id": "800419",
            "name": "old Value",
            "handlerTsCode": "(line: Message): CellHandler => { if (line.origin.port == \"49152\" || line.origin.port == \"49153\") { let match = line.content.match(/from (.+?) to (.+)/); let oldValue = match ? match[1] : \"-\"; return { text: oldValue }; } }",
            "faceted": false,
            "idx": 3,
            "width": 249
        },
        {
            "id": "467883",
            "name": "New Value",
            "handlerTsCode": "(line: Message): CellHandler => { if (line.origin.port == \"49152\" || line.origin.port == \"49153\") { let match = line.content.match(/from (.+?) to (.+)/); let newValue = match ? match[2] : \"-\"; if (newValue == \"-\") { match = line.content.match(/\\[(INFO|WARN|ERROR)\\s*\\] \\[(.*?)\\] - (.*)/); newValue = match ? match[3] : \"-\"; if (newValue.match(/changed\\sto\\s(.+)$/)) { match = newValue.match(/changed\\sto\\s(.+)$/); newValue = match ? match[1] : \"-\"; } } return { text: newValue }; } }",
            "faceted": false,
            "idx": 4,
            "width": 362
        }
    ],
    "settings": {
        "leftColWidth": 300,
        "drawerColWidth": 900,
        "maxMessages": 1000,
        "middlewares": [],
        "entriesOrder": "desc"
    }
}
  1. Save the file

Step 3: Access the Logdy UI

  1. Open your browser and navigate to the Logdy UI at:
http://[yourip]:5000
  1. Use the API key openhab to authenticate for rest api to send directly log entrys to logdy.

3.Load the config.json file into your UI


With these steps, Logdy will parse OpenHAB logs and display them in a user-friendly interface. For further customization, modify the config.json file as needed.

4 Likes

Thanks for the tutorial. I have several suggestions

Under prerequisites, users should place sudo after the pipe as below

  1. Logdy binary installed curl https://logdy.dev/install.sh | sudo sh
    https://logdy.dev/docs/quick-start

Under step 1, users should not simply copy the file. They must replace the tex [yourip] with an actual IP address

For step 2, suggest they create a directory such as logdy and then create a file in that directory. Or they can copy and paste it in the import dialog box.

1 Like