M-Welsch / backup-server

Backup Server (BaSe)
Apache License 2.0
3 stars 1 forks source link

add sysloghandler to logging #39

Open M-Welsch opened 7 months ago

M-Welsch commented 7 months ago

Description

add something like this and make the logger send data to the NAS which is always on and therefore we can access the logs all the time. Or setup some dedicated logging server where we can collect all logs

import logging
from logging.handlers import SysLogHandler

# Configure the logging module
logger = logging.getLogger('remote_logger')
logger.setLevel(logging.DEBUG)

# Create a SysLogHandler to send logs to a remote machine
syslog_handler = SysLogHandler(address=('remote_machine_ip', 514))
syslog_handler.setLevel(logging.DEBUG)

# Define a formatter for the logs
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
syslog_handler.setFormatter(formatter)

# Add the SysLogHandler to the logger
logger.addHandler(syslog_handler)

# Log some sample messages
logger.debug('This is a debug message.')
logger.info('This is an info message.')
logger.warning('This is a warning message.')
logger.error('This is an error message.')
logger.critical('This is a critical message.')

modify /etc/rsyslog.conf or /etc/syslog.conf on the target

What happens if we don't do it (aka Why is it important)?

it's a bit more tedious to get to the logs

Definition of Ready

Key Tasks

Acceptance Criteria