improved logging feature of the app.
Changes to be committed: modified: camera-client/camera_monitor.py
This commit is contained in:
@@ -84,9 +84,29 @@ def load_config(config_path):
|
|||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
raise Exception(f"Invalid JSON format in config file: {config_path}")
|
raise Exception(f"Invalid JSON format in config file: {config_path}")
|
||||||
|
|
||||||
def setup_logging():
|
def setup_logging(log_file='logs/camera_monitor.log'):
|
||||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
# logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||||
return logging.getLogger('CameraMonitor')
|
# 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():
|
def main():
|
||||||
args = parse_command_line_args()
|
args = parse_command_line_args()
|
||||||
|
|||||||
Reference in New Issue
Block a user