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
diff --git a/tools/edit_monitor/daemon_manager.py b/tools/edit_monitor/daemon_manager.py
index 970bd92..c0a57ab 100644
--- a/tools/edit_monitor/daemon_manager.py
+++ b/tools/edit_monitor/daemon_manager.py
@@ -154,7 +154,7 @@
   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 @@
         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 @@
     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 6af421b..49385f1 100644
--- a/tools/edit_monitor/main.py
+++ b/tools/edit_monitor/main.py
@@ -57,17 +57,27 @@
       ),
   )
 
+  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 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 @@
 
 if __name__ == '__main__':
   signal.signal(signal.SIGTERM, term_signal_handler)
-  configure_logging()
   main(sys.argv)