{
  "version": "1.8.2",
  "title": "Override of Console logging functions",
  "script": "import builtins, logging\n\ndef _convert(msg, *args, **kwargs) -> str:\n    # Ensures that 'msg' is always a string\n    msg = str(msg)\n    \n    # Removes 'extra' from 'kwargs' and passes the value to the variable 'extra'\n    extra = kwargs.pop(\"extra\", None)\n    \n    # Checks if 'args' is not empty and '%' is in 'msg'\n    if args and (\"%\" in msg):\n        msg = msg % args # If true, apply the modulo operator to replace '%s, %d, ..'\n    if extra:\n        # If 'extra' is not empty, the values are prepended to 'msg'\n        extra_string = \" \".join(str(v) for _, v in extra.items())\n        msg = f\"{extra_string}  {msg}\"\n\n    return msg\n\ndef _print(*objects, sep=\" \", end=\"\\n\", file=None, flush=False):\n    msg = \" \".join(map(str, objects))\n    if file is sys.stderr:\n        js7Step.getLogger().error(msg)\n    else:\n        js7Step.getLogger().info(msg)\n\ndef _info(msg, *args, **kwargs):\n    js7Step.getLogger().info(_convert(msg, *args, **kwargs))\n\ndef _warning(msg, *args, **kwargs):\n    js7Step.getLogger().warn(_convert(msg, *args, **kwargs))\n\ndef _error(msg, *args, **kwargs):\n    js7Step.getLogger().error(_convert(msg, *args, **kwargs))\n\ndef _debug(msg, *args, **kwargs):\n    js7Step.getLogger().debug(_convert(msg, *args, **kwargs))\n\ndef _exception(msg, *args, **kwargs):\n    js7Step.getLogger().error(_convert(msg, *args, **kwargs))\n\ndef _log(level: int, msg, *args, **kwargs):\n    match level:\n        case 0:\n            _info(msg, *args, **kwargs)\n        case 10:\n            _debug(msg, *args, **kwargs)\n        case 20:\n            _info(msg, *args, **kwargs)\n        case 30:\n            _warning(msg, *args, **kwargs)\n        case 40:\n            _error(msg, *args, **kwargs)\n        case 50:\n            _error(msg, *args, **kwargs)\n        case _:\n            _error(f\"unknown log level: {level}\")\n\n# This patches the methods print and logging.\n# (i) Every job starts in a new context, therefore this only overrides the methods within the current job\nbuiltins.print    = _print\nlogging.log       = _log\nlogging.info      = _info\nlogging.warning   = _warning\nlogging.error     = _error\nlogging.critical  = _error\nlogging.exception = _exception\nlogging.debug     = _debug"
}