text: """
  This module provides helper features for entry script.
  This file should be in Python search paths or in the same folder as the entry script.
  """
  import os
  import socket
  import logging
  import time
  from multiprocessing import current_process
  from azureml.core import Run
  
  
  class EntryScriptHelper:
      """ A helper to provide common features for entry script."""
  
      LOG_CONFIGED = False
  
      def get_logger(self, name="EntryScript"):
          """ Return a logger.
              The logger will write to the 'users' folder and show up in azure portal.
          """
          return logging.getLogger(name)
  
      def config(self, name="EntryScript", level="INFO"):
          """ Config a logger. This should be called in init() in score module.
              Config the logger one time if not configed.
              The logger will write to the 'users' folder and show up in azure portal.
          """
          logger = logging.getLogger(name)
  
          formatter = logging.Formatter(
              "%(asctime)s|%(name)s|%(levelname)s|%(process)d|%(thread)d|%(funcName)s()|%(message)s"
          )
          formatter.converter = time.gmtime
  
          logger.setLevel(level)
  
          handler = logging.FileHandler(self.get_log_file_path())
          handler.setLevel(level)
          handler.setFormatter(formatter)
          logger.addHandler(handler)
  
          return logger
  
      def get_log_file_path(self):
          """ Get the log file path for users.
              Each process has its own log file, so there is not race issue among multiple processes.
          """
          ip_address = socket.gethostbyname(socket.gethostname())
          log_dir = os.path.join(self.get_log_dir(), "user", ip_address)
          os.makedirs(log_dir, exist_ok=True)
          return os.path.join(log_dir, f"{current_process().name}.txt")
  
      def get_log_dir(self):
          """ Return the folder for logs.
              Files and folders in it will be uploaded and show up in run detail page in the azure portal.
          """
          log_dir = os.path.join(self.get_working_dir(), "logs")
          os.makedirs(log_dir, exist_ok=True)
          return log_dir
  
      def get_working_dir(self):
          """ Return the working directory."""
          return os.path.join(os.environ.get("AZ_BATCHAI_INPUT_AZUREML", ""), self.get_run().id)
  
      def get_temp_dir(self):
          """ Return local temp directory."""
          local_temp_dir = os.path.join(
              os.environ.get("AZ_BATCHAI_JOB_TEMP", ""), "azureml-bi", str(os.getpid())
          )
          os.makedirs(local_temp_dir, exist_ok=True)
          return local_temp_dir
  
      def get_run(self):
          """ Return the Run from the context."""
          return Run.get_context(allow_offline=False)
  