Fledge prefix added to process_names and other code refactoring
@@ -65,6 +65,15 @@ def setup(logger_name: str = None,
.. _logging.getLogger: https://docs.python.org/3/library/logging.html#logging.getLogger
"""
+ def _get_process_name():
+ # Example: ps -eaf | grep 5175 | grep -v grep | awk -F '--name=' '{print $2}'
+ pid = os.getpid()
+ cmd = "ps -eaf | grep {} | grep -v grep | awk -F '--name=' '{{print $2}}'| tr -d '\n'".format(pid)
+ read_process_name = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout.readlines()
+ binary_to_string = [b.decode() for b in read_process_name]
+ pname = 'Fledge ' + binary_to_string[0] if binary_to_string else 'Fledge'
+ return pname
+
logger = logging.getLogger(logger_name)
if destination == SYSLOG:
@@ -75,12 +84,7 @@ def setup(logger_name: str = None,
raise ValueError("Invalid destination {}".format(destination))
# TODO: Consider using %r with message when using syslog .. \n looks better than #
- # Example: ps -eaf | grep 5175 | grep -v grep | awk -F '--name=' '{print $2}'
- pid = os.getpid()
- cmd = "ps -eaf | grep {} | grep -v grep | awk -F '--name=' '{{print $2}}'| tr -d '\n'".format(pid)
- read_process_name = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout.readlines()
- binary_to_string = [b.decode() for b in read_process_name]
- process_name = binary_to_string[0] if binary_to_string else 'Fledge'
+ process_name = _get_process_name()
fmt = '{}[%(process)d] %(levelname)s: %(module)s: %(name)s: %(message)s'.format(process_name)
formatter = logging.Formatter(fmt=fmt)
handler.setFormatter(formatter)
