mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
Compare commits
2 Commits
630e4f6327
...
c63f424c7d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c63f424c7d | ||
|
|
dd1580e536 |
@@ -71,4 +71,5 @@ services:
|
||||
- PORT=${PORT}
|
||||
# ❗ DANGER ZONE BELOW - Setting ALWAYS_FRESH_INSTALL=true will delete the content of the /db & /config folders
|
||||
- ALWAYS_FRESH_INSTALL=${ALWAYS_FRESH_INSTALL}
|
||||
# - LOADED_PLUGINS=["DHCPLSS","PIHOLE","ASUSWRT","FREEBOX"]
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ else
|
||||
echo "Config file saved to ${INSTALL_DIR}/config/app_conf_override.json"
|
||||
fi
|
||||
|
||||
# 🔻 FOR BACKWARD COMPATIBILITY - REMOVE AFTER 12/12/2024
|
||||
# 🔻 FOR BACKWARD COMPATIBILITY - REMOVE AFTER 12/12/2025
|
||||
|
||||
# Check if pialert.db exists, then create a symbolic link to app.db
|
||||
if [ -f "${INSTALL_DIR_OLD}/db/${OLD_APP_NAME}.db" ]; then
|
||||
@@ -66,7 +66,7 @@ fi
|
||||
if [ -f "${INSTALL_DIR_OLD}/config/${OLD_APP_NAME}.conf" ]; then
|
||||
ln -s "${INSTALL_DIR_OLD}/config/${OLD_APP_NAME}.conf" "${INSTALL_DIR}/config/${CONF_FILE}"
|
||||
fi
|
||||
# 🔺 FOR BACKWARD COMPATIBILITY - REMOVE AFTER 12/12/2024
|
||||
# 🔺 FOR BACKWARD COMPATIBILITY - REMOVE AFTER 12/12/2025
|
||||
|
||||
# Copy starter .db and .conf if they don't exist
|
||||
cp -na "${INSTALL_DIR}/back/${CONF_FILE}" "${INSTALL_DIR}/config/${CONF_FILE}"
|
||||
@@ -83,6 +83,13 @@ if [ -n "${TZ}" ]; then
|
||||
echo $TZ > /etc/timezone
|
||||
fi
|
||||
|
||||
# if custom variables not set we do not need to do anything
|
||||
if [ -n "${LOADED_PLUGINS}" ]; then
|
||||
FILECONF="${INSTALL_DIR}/config/${CONF_FILE}"
|
||||
echo "[INSTALL] Setup custom LOADED_PLUGINS variable"
|
||||
sed -i "\#^LOADED_PLUGINS=#c\LOADED_PLUGINS=${LOADED_PLUGINS}" "${FILECONF}"
|
||||
fi
|
||||
|
||||
echo "[INSTALL] Setup NGINX"
|
||||
echo "Setting webserver to address ($LISTEN_ADDR) and port ($PORT)"
|
||||
envsubst '$INSTALL_DIR $LISTEN_ADDR $PORT' < "${INSTALL_DIR}/install/netalertx.template.conf" > "${NGINX_CONFIG_FILE}"
|
||||
|
||||
@@ -92,5 +92,5 @@ dnsmasq.leases
|
||||
|
||||
## Other Info
|
||||
|
||||
Publishing date: 22.1.2025
|
||||
Author: [EinKantHolz - odin](https://github.com/EinKantHolz)
|
||||
- Publishing date: 22.1.2025
|
||||
- Author: [EinKantHolz - odin](https://github.com/EinKantHolz)
|
||||
@@ -312,8 +312,7 @@ def importConfigs (db, all_plugins):
|
||||
|
||||
# -----------------
|
||||
# HANDLE APP_CONF_OVERRIDE via app_conf_override.json
|
||||
|
||||
# Assuming fullConfFolder is defined elsewhere
|
||||
|
||||
app_conf_override_path = fullConfFolder + '/app_conf_override.json'
|
||||
|
||||
if os.path.exists(app_conf_override_path):
|
||||
|
||||
@@ -4,6 +4,10 @@ import datetime
|
||||
import threading
|
||||
import queue
|
||||
import time
|
||||
import logging
|
||||
|
||||
# NetAlertX imports
|
||||
|
||||
import conf
|
||||
from const import *
|
||||
|
||||
@@ -16,6 +20,16 @@ def timeNowTZ():
|
||||
else:
|
||||
return datetime.datetime.now().replace(microsecond=0)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Map custom debug levels to Python logging levels
|
||||
custom_to_logging_levels = {
|
||||
'none': logging.NOTSET,
|
||||
'minimal': logging.WARNING,
|
||||
'verbose': logging.INFO,
|
||||
'debug': logging.DEBUG,
|
||||
'trace': logging.DEBUG, # Can map to DEBUG or lower custom level if needed
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# More verbose as the numbers go up
|
||||
debugLevels = [
|
||||
@@ -25,6 +39,10 @@ debugLevels = [
|
||||
# use the LOG_LEVEL from the config, may be overridden
|
||||
currentLevel = conf.LOG_LEVEL
|
||||
|
||||
# tracking log levels
|
||||
setLvl = 0
|
||||
reqLvl = 0
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
class Logger:
|
||||
def __init__(self, LOG_LEVEL='verbose'):
|
||||
@@ -32,10 +50,36 @@ class Logger:
|
||||
|
||||
currentLevel = LOG_LEVEL
|
||||
|
||||
# Automatically set up custom logging handler
|
||||
self.setup_logging()
|
||||
|
||||
def setup_logging(self):
|
||||
root_logger = logging.getLogger()
|
||||
# Clear existing handlers to prevent duplicates
|
||||
if root_logger.hasHandlers():
|
||||
root_logger.handlers.clear()
|
||||
|
||||
# Create the custom handler
|
||||
my_log_handler = MyLogHandler()
|
||||
# my_log_handler.setLevel(custom_to_logging_levels.get(currentLevel, logging.NOTSET))
|
||||
|
||||
# Optional: Add a formatter for consistent log message format
|
||||
# formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
formatter = logging.Formatter('%(message)s', datefmt='%H:%M:%S')
|
||||
my_log_handler.setFormatter(formatter)
|
||||
|
||||
# Attach the handler to the root logger
|
||||
root_logger.addHandler(my_log_handler)
|
||||
root_logger.setLevel(custom_to_logging_levels.get(currentLevel, logging.NOTSET))
|
||||
|
||||
# for python logging
|
||||
class MyLogHandler(logging.Handler):
|
||||
def emit(self, record):
|
||||
log_entry = self.format(record)
|
||||
log_queue.put(log_entry)
|
||||
|
||||
def mylog(requestedDebugLevel, n):
|
||||
setLvl = 0
|
||||
reqLvl = 0
|
||||
global setLvl, reqLvl
|
||||
|
||||
# Get debug urgency/relative weight
|
||||
for lvl in debugLevels:
|
||||
@@ -86,23 +130,14 @@ def file_print(*args):
|
||||
result = timeNowTZ().strftime('%H:%M:%S') + ' '
|
||||
|
||||
for arg in args:
|
||||
result += str(arg)
|
||||
result += str(arg)
|
||||
|
||||
logging.log(custom_to_logging_levels.get(currentLevel, logging.NOTSET), result) # Forward to Python's logging system
|
||||
print(result)
|
||||
|
||||
# Ensure the log writer thread is running
|
||||
start_log_writer_thread()
|
||||
|
||||
# Queue the log entry for writing
|
||||
append_to_file_with_timeout( result, 5)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Function to append to the file with a timeout
|
||||
def append_to_file_with_timeout(data, timeout):
|
||||
try:
|
||||
log_queue.put_nowait(data)
|
||||
except queue.Full:
|
||||
print("Log queue is full, dropping log entry:" + data)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
def print_log(pText):
|
||||
# Check if logging is active
|
||||
|
||||
Reference in New Issue
Block a user