improved logging feature of the app.

Changes to be committed:
	modified:   camera-client/camera_monitor.py
This commit is contained in:
2023-09-21 22:17:38 +03:30
parent 91b1356e5a
commit 86ea984e7a

View File

@@ -84,9 +84,29 @@ def load_config(config_path):
except json.JSONDecodeError:
raise Exception(f"Invalid JSON format in config file: {config_path}")
def setup_logging():
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
return logging.getLogger('CameraMonitor')
def setup_logging(log_file='logs/camera_monitor.log'):
# logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# return logging.getLogger('CameraMonitor')
# Configure the logger
logger = logging.getLogger('CameraMonitor')
logger.setLevel(logging.INFO)
# Create a TimedRotatingFileHandler for log rotation
file_handler = logging.handlers.TimedRotatingFileHandler(
log_file, when='midnight', backupCount=7
) # Keeps logs for 7 days
file_handler.suffix = '%Y-%m-%d' # Append date to log file names
# Define the log message format
formatter = logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
file_handler.setFormatter(formatter)
# Add the file handler to the logger
logger.addHandler(file_handler)
return logger
def main():
args = parse_command_line_args()