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
- OpenHAB installed and running on your system.
- Logdy binary installed
curl https://logdy.dev/install.sh | sh
https://logdy.dev/docs/quick-start - 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.
- Open a terminal and create the file:
sudo nano /etc/systemd/system/logdy.service
- 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
- Save the file and exit the editor.
- Reload the systemd daemon to recognize the new service:
sudo systemctl daemon-reload
- Enable the Logdy service to start at boot:
sudo systemctl enable logdy.service
- Start the service:
sudo systemctl start logdy.service
- 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:
-
Open or create the configuration file
-
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"
}
}
- Save the file
Step 3: Access the Logdy UI
- Open your browser and navigate to the Logdy UI at:
http://[yourip]:5000
- 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.