diff options
author | 2024-10-25 00:21:45 +0000 | |
---|---|---|
committer | 2024-10-25 17:45:42 +0000 | |
commit | 64ad75f20b5a649ea056792e9907e79363e13bc1 (patch) | |
tree | 13c887f9b28144fb2c036ffb8670ed9f45b7b385 | |
parent | 9a4c6a635564c9da61349800d00a040b6018d782 (diff) |
Support --verbose option in edit monitor
If --verbose option is set, logging in DEBUG level, otherwise logging
in INFO level, by default, user should run edit monitor without verbose
option to reduce the log size.
Test: make edit_monitor then run it and check the log file manually
Bug: 365617369
Change-Id: Ibdbd2bdd1ff373f7924c60f1b382b14678cf0a92
-rw-r--r-- | tools/edit_monitor/daemon_manager.py | 6 | ||||
-rw-r--r-- | tools/edit_monitor/main.py | 16 |
2 files changed, 16 insertions, 6 deletions
diff --git a/tools/edit_monitor/daemon_manager.py b/tools/edit_monitor/daemon_manager.py index 970bd929fc..c0a57abdaa 100644 --- a/tools/edit_monitor/daemon_manager.py +++ b/tools/edit_monitor/daemon_manager.py @@ -154,7 +154,7 @@ class DaemonManager: def stop(self): """Stops the daemon process and removes the pidfile.""" - logging.debug("in daemon manager cleanup.") + logging.info("in daemon manager cleanup.") try: if self.daemon_process: # The daemon process might already in termination process, @@ -163,7 +163,7 @@ class DaemonManager: if self.daemon_process.is_alive(): self._terminate_process(self.daemon_process.pid) self._remove_pidfile() - logging.debug("Successfully stopped daemon manager.") + logging.info("Successfully stopped daemon manager.") except Exception as e: logging.exception("Failed to stop daemon manager with error %s", e) self._send_error_event_to_clearcut( @@ -179,7 +179,7 @@ class DaemonManager: Stops the current daemon manager and reboots the entire process based on the binary file. Exits directly If the binary file no longer exists. """ - logging.debug("Rebooting process based on binary %s.", self.binary_path) + logging.info("Rebooting process based on binary %s.", self.binary_path) # Stop the current daemon manager first. self.stop() diff --git a/tools/edit_monitor/main.py b/tools/edit_monitor/main.py index 6af421b1f3..49385f1cc5 100644 --- a/tools/edit_monitor/main.py +++ b/tools/edit_monitor/main.py @@ -57,17 +57,27 @@ def create_arg_parser(): ), ) + parser.add_argument( + '--verbose', + action='store_true', + help=( + 'Log verbose info in the log file for debugging purpose.' + ), + ) + return parser -def configure_logging(): +def configure_logging(verbose=False): root_logging_dir = tempfile.mkdtemp(prefix='edit_monitor_') _, log_path = tempfile.mkstemp(dir=root_logging_dir, suffix='.log') log_fmt = '%(asctime)s %(filename)s:%(lineno)s:%(levelname)s: %(message)s' date_fmt = '%Y-%m-%d %H:%M:%S' + log_level = logging.DEBUG if verbose else logging.INFO + logging.basicConfig( - filename=log_path, level=logging.DEBUG, format=log_fmt, datefmt=date_fmt + filename=log_path, level=log_level, format=log_fmt, datefmt=date_fmt ) # Filter out logs from inotify_buff to prevent log pollution. logging.getLogger('watchdog.observers.inotify_buffer').addFilter( @@ -82,6 +92,7 @@ def term_signal_handler(_signal_number, _frame): def main(argv: list[str]): args = create_arg_parser().parse_args(argv[1:]) + configure_logging(args.verbose) if args.dry_run: logging.info('This is a dry run.') dm = daemon_manager.DaemonManager( @@ -104,5 +115,4 @@ def main(argv: list[str]): if __name__ == '__main__': signal.signal(signal.SIGTERM, term_signal_handler) - configure_logging() main(sys.argv) |