Skip to content

Commit

Permalink
refactor: logging
Browse files Browse the repository at this point in the history
  • Loading branch information
StafLoker committed Dec 13, 2024
1 parent 5ec6134 commit d9b5674
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ Verify that the DNS records on Porkbun are updated to match your current public

---

## **Logging**
Check logs
```bash
journalctl -t ddns-porkbun
```

## **License**

This project is released under the MIT License. See the [LICENSE](LICENSE) file for more details.
12 changes: 9 additions & 3 deletions ddns-porkbun-script.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# Load keys
source ./data.env
source ./keys.env

# Load JSON
DATA_FILE="data.json"
Expand All @@ -16,11 +16,17 @@ RETRIEVE_RECORD_URL="$BASE_URL/dns/retrieveByNameType/$DOMAIN/A"
UPDATE_RECORD_URL="$BASE_URL/dns/editByNameType/$DOMAIN/A"

# Function to log messages with timestamp
LOG_FILE="/var/log/ddns-porkbun.log"
log() {
local level=$1
local message=$2
echo "$(date '+%Y-%m-%d %H:%M:%S') [$level] $message" >> "$LOG_FILE"
case "$level" in
DEBUG) syslog_level="debug" ;;
INFO) syslog_level="info" ;;
WARNING) syslog_level="warning" ;;
ERROR) syslog_level="err" ;;
*) syslog_level="notice" ;; # Nivel por defecto
esac
logger -p user.$syslog_level -t ddns-porkbun "$message"
}

# Function to get the public IP
Expand Down

0 comments on commit d9b5674

Please sign in to comment.