How to use the sanic.log.logger.exception function in sanic

To help you get started, we’ve selected a few sanic examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gangtao / dataplay3 / server / dataplay / mlsvc / service.py View on Github external
async def create_job(request):
    logger.debug(f'get create ml job with payload={request.body}')
    try:
        request_body = json.loads(request.body)
        job = MLJobManager.create_job(request_body)
        return response.json(job, status=201)
    except Exception:
        logger.exception('faile to create ml job')
        return response.json({}, status=500)
github gangtao / dataplay3 / server / dataplay / mlsvc / manager.py View on Github external
for job_id in job_ids:
                try:
                    logger.debug(f'find one job with id={job_id}')
                    item = {}
                    item['id'] = job_id
                    status = MLJob.get_status_by_id(job_id)
                    item['status'] = status.name
                    meta = MLJob.get_meta(job_id)
                    for key in ['type', 'name']:
                        item[key] = meta[key]
                    results.append(item)
                except Exception:
                    logger.exception(f'failed to retrieve job id={job_id}')
            return results
        except Exception:
            logger.exception('failed to list job')
            return []
github gangtao / dataplay3 / server / dataplay / datasvc / registry.py View on Github external
def register(self, name, class_name, module):
        logger.debug(
            "DatasetTypeRegistry registered name=%s, class=%s, module=%s"
            % (name, class_name, module)
        )

        if not isinstance(module, str):
            logger.exception("Wrong module provided, %s is not a module." % (module))
            raise RuntimeError('Error while register dataset type "%s %s"' % (name, module))

        try:
            importlib.import_module(module)
        except Exception as e:
            logger.exception("Wrong module provided, failed to load %s as a module." % (module))
            raise RuntimeError(
                'Error while register dataset type "%s %s":%s' % (name, module, str(e))
            )

        item = {}
        item['class'] = class_name
        item['module'] = module
        DatasetTypeRegistry.instance[name] = item
github huge-success / sanic / sanic / handlers.py View on Github external
def default(self, request, exception):
        self.log(format_exc())
        try:
            url = repr(request.url)
        except AttributeError:
            url = "unknown"

        response_message = "Exception occurred while handling uri: %s"
        logger.exception(response_message, url)

        if issubclass(type(exception), SanicException):
            return text(
                "Error: {}".format(exception),
                status=getattr(exception, "status_code", 500),
                headers=getattr(exception, "headers", dict()),
            )
        elif self.debug:
            html_output = self._render_traceback_html(exception, request)

            return html(html_output, status=500)
        else:
            return html(INTERNAL_SERVER_ERROR_HTML, status=500)
github gangtao / dataplay3 / server / dataplay / usersvc / service.py View on Github external
async def routes(request):
    try:
        routes = get_routes()
        return response.json(routes, 200)
    except Exception:
        logger.exception('faile to get get routes')
        return response.json({}, status=500)
github gangtao / dataplay3 / server / dataplay / datasvc / service.py View on Github external
async def get_dataset(request, id):
    try:
        dataset = DatasetManager.get_dataset(id)
        payload = dataset.get_payload()
        return response.json(payload, status=200)
    except Exception:
        logger.exception('faile to get dataset')
        return response.json({}, status=500)
github gangtao / dataplay3 / server / dataplay / mlsvc / service.py View on Github external
async def get_job(request, id):
    try:
        job = MLJobManager.get_job(id)
        return response.json(job, status=200)
    except Exception:
        logger.exception('faile to get ml job')
        return response.json({}, status=500)
github gangtao / dataplay3 / server / dataplay / confsvc / service.py View on Github external
async def list_confs(request):
    try:
        config = ConfigurationManager.list_confs()
        return response.json(config, status=200)
    except Exception:
        logger.exception('failed to list configurations')
        return response.json({}, status=500)
github gangtao / dataplay3 / server / dataplay / datasvc / service.py View on Github external
async def delete_dataset(request, id):
    try:
        DatasetManager.delete_dataset(id)
        return response.json({}, status=204)
    except Exception:
        logger.exception('faile to delete dataset')
        return response.json({}, status=500)