Add centralized logging system for Ren Browser with detailed function documentation
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
"""Logging system for Ren Browser.
|
||||
|
||||
Provides centralized logging for application events, errors, and
|
||||
Reticulum network activities.
|
||||
"""
|
||||
import datetime
|
||||
|
||||
import RNS
|
||||
@@ -6,17 +11,46 @@ APP_LOGS: list[str] = []
|
||||
ERROR_LOGS: list[str] = []
|
||||
RET_LOGS: list[str] = []
|
||||
_original_rns_log = RNS.log
|
||||
|
||||
def log_ret(msg, *args, **kwargs):
|
||||
"""Log Reticulum messages with timestamp.
|
||||
|
||||
Args:
|
||||
msg: Log message.
|
||||
*args: Additional arguments passed to original RNS.log.
|
||||
**kwargs: Additional keyword arguments passed to original RNS.log.
|
||||
|
||||
"""
|
||||
timestamp = datetime.datetime.now().isoformat()
|
||||
RET_LOGS.append(f"[{timestamp}] {msg}")
|
||||
return _original_rns_log(msg, *args, **kwargs)
|
||||
RNS.log = log_ret
|
||||
|
||||
def setup_rns_logging():
|
||||
"""Set up RNS log replacement. Call this after RNS.Reticulum initialization."""
|
||||
global _original_rns_log
|
||||
_original_rns_log = RNS.log
|
||||
RNS.log = log_ret
|
||||
|
||||
# Initial setup
|
||||
setup_rns_logging()
|
||||
|
||||
def log_error(msg: str):
|
||||
"""Log error messages to both error and application logs.
|
||||
|
||||
Args:
|
||||
msg: Error message to log.
|
||||
|
||||
"""
|
||||
timestamp = datetime.datetime.now().isoformat()
|
||||
ERROR_LOGS.append(f"[{timestamp}] {msg}")
|
||||
APP_LOGS.append(f"[{timestamp}] ERROR: {msg}")
|
||||
|
||||
def log_app(msg: str):
|
||||
"""Log application messages.
|
||||
|
||||
Args:
|
||||
msg: Application message to log.
|
||||
|
||||
"""
|
||||
timestamp = datetime.datetime.now().isoformat()
|
||||
APP_LOGS.append(f"[{timestamp}] {msg}")
|
||||
|
||||
Reference in New Issue
Block a user