code: def _record_to_event(self, record):
      # type: (LogRecord) -> events.TaskLogEvent
      timestamp = int(record.created * 1000)
      if timestamp == self._last_timestamp:
          timestamp += self.counter
          self.counter += 1
      else:
          self._last_timestamp = timestamp
          self.counter = 1
  
      # ignore backspaces (they are often used)
      full_msg = record.getMessage().replace("\x08", "")
  
      return_events = []
      while full_msg:
          msg = full_msg[: self.__max_event_size]
          full_msg = full_msg[self.__max_event_size :]
          # unite all records in a single second
          if (
              self._last_event
              and timestamp - self._last_event.timestamp < 1000
              and len(self._last_event.msg) + len(msg)
              < self.__max_event_size
              and record.levelname.lower()
              == str(self._last_event.level)
          ):
              # ignore backspaces (they are often used)
              self._last_event.msg += "\n" + msg
              continue
  
          # if we have a previous event and it timed out, return it.
          new_event = events.TaskLogEvent(
              task=self._task_id,
              timestamp=timestamp,
              level=record.levelname.lower(),
              worker=self._worker,
              msg=msg,
          )
          if self._last_event:
              return_events.append(self._last_event)
  
          self._last_event = new_event
  
      return return_events
  
imports: import json
  import sys
  from pathlib2 import Path
  from logging import LogRecord, getLogger, basicConfig, getLevelName, INFO, WARNING, Formatter, makeLogRecord, warning
  from logging.handlers import BufferingHandler
  from .development.worker import DevWorker
  from ...backend_api.services import events
  from ...backend_api.session.session import MaxRequestSizeError
  from ...config import config
  from ...utilities.process.mp import BackgroundMonitor, ForkEvent, ForkQueue
  from ...utilities.process.mp import SafeQueue, SafeEvent
label_desc: Use image node_id 9 for calling the BackgroundLogService obj's underlying member method code with example usage: obj._record_to_event(record) and returns: return_events