How to use the sanic.log.logger.info 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 huge-success / sanic / tests / test_logging.py View on Github external
def log_info(request):
        logger.info(rand_string)
        return text("hello")
github chainify / nolik / parser / api / v1 / parser.py View on Github external
def gentle_exit(app, loop):
    logger.info('Killing the process')
    os.kill(os.getpid(), signal.SIGKILL)
github chainify / nolik / parser / api / v1 / parser.py View on Github external
signature,
                        verified)
                    VALUES %s ON CONFLICT DO NOTHING"""
                    execute_values(cur, sql, self.sql_data_senders)

                    if cur.rowcount > 0:
                        self.transactions_inserted += cur.rowcount

                    conn.commit()
                    logger.info('Transactions in batch: {0}'.format(self.transactions_in_batch))
                    if self.transactions_in_batch > 0:
                        extra_text = colored('OK', 'green') if self.valid_transactions == self.transactions_in_batch else colored('ERR', 'red')
                        text = 'Valid ransactions: {0} '.format(self.valid_transactions)
                        logger.info(text + extra_text)
                    if self.transactions_inserted > 0 and self.transactions_inserted >= self.valid_transactions:
                        logger.info(colored('Saved {0} transaction(s)'.format(self.valid_transactions), 'green'))


        except psycopg2.IntegrityError as error:
            logger.info('Error', error)
            pass
        except asyncio.CancelledError:
            logger.info('Parser has been stopped')
            raise
        except Exception as error:
            logger.info('Height: {}'.format(self.height))
            logger.error('Batch insert error: {}'.format(error))
            await self.emergency_stop_loop('Batch insert error', error)
        finally:
            self.transactions_in_batch = 0
            self.transactions_inserted = 0
            self.valid_transactions = 0
github chainify / nolik / parser / api / v1 / parser.py View on Github external
def autostart(app, loop):
    loop.create_task(controls.start())
    logger.info('Autostart Success!')
    logger.info('CDM Version: {0}'.format(os.environ['CDM_VERSION']))
github autogestion / pubgate / pubgate / api / inbox.py View on Github external
async def inbox_post(request, user):
    # TODO implement shared inbox
    # TODO https://www.w3.org/TR/activitypub/#inbox-forwarding
    activity = request.json.copy()
    # TODO The receiver must verify the notification by fetching its source from the origin server.
    verified = await verify_request(request)
    if not verified:
        if getattr(request.app.config, 'DEBUG_INBOX', False):
            logger.info("signature incorrect")
        else:
            return response.json({"error": "signature incorrect"}, status=401)

    # TODO skip blocked
    # if Outbox.find_one(
    #     {
    #         "activity.type": "Block",
    #         "user_id": user_id,
    #         "meta.undo": False,
    #     }):
    #     return response.json({"zrada": "actor is blocked"}, status=403)

    if activity["type"] == "Follow":
        saved = await Inbox.save(user, activity)
        if saved:
            deliverance = {
github Sanic-Extensions / sanic-mongo / sanic_mongo / gridfs.py View on Github external
async def sub_close(app, loop):
            log.info("mongo connection {numbr}".format(numbr=len(self.GridFSs)))
            for bucket_name,bucket in self.GridFSs.items():
                bucket.client.close
                log.info("{bucket_name} connection closed".format(bucket_name=bucket_name))
github huge-success / sanic / sanic / app.py View on Github external
):
            logger.debug(
                self.config.LOGO
                if isinstance(self.config.LOGO, str)
                else BASE_LOGO
            )

        if run_async:
            server_settings["run_async"] = True

        # Serve
        if host and port and os.environ.get("SANIC_SERVER_RUNNING") != "true":
            proto = "http"
            if ssl is not None:
                proto = "https"
            logger.info("Goin' Fast @ {}://{}:{}".format(proto, host, port))

        return server_settings
github chainify / nolik / parser / api / v1 / parser.py View on Github external
async def emergency_stop_loop(self, title, error):
        logger.info('Emergency loop stop request')
        logger.info('Reason: {}'.format(error))
        logger.info('Closing tasks')
        for task in asyncio.Task.all_tasks():
            task.cancel()

        logger.info('Stopping loop')
        loop = asyncio.get_running_loop()
        loop.stop()
        return bad_request(error)
github Sanic-Extensions / sanic-mongo / sanic_mongo / mongo.py View on Github external
async def sub_close(app, loop):
            log.info("mongo connection {numbr}".format(numbr=len(self.mongodbs)))
            for dbname,db in self.mongodbs.items():
                db.client.close
                log.info("{dbname} connection closed".format(dbname=dbname))
github huge-success / sanic / sanic / server.py View on Github external
if register_sys_signals:
        _singals = (SIGTERM,) if run_multiple else (SIGINT, SIGTERM)
        for _signal in _singals:
            try:
                loop.add_signal_handler(_signal, loop.stop)
            except NotImplementedError:
                logger.warning(
                    "Sanic tried to use loop.add_signal_handler "
                    "but it is not implemented on this platform."
                )
    pid = os.getpid()
    try:
        logger.info("Starting worker [%s]", pid)
        loop.run_forever()
    finally:
        logger.info("Stopping worker [%s]", pid)

        # Run the on_stop function if provided
        trigger_events(before_stop, loop)

        # Wait for event loop to finish and all connections to drain
        http_server.close()
        loop.run_until_complete(http_server.wait_closed())

        # Complete all tasks on the loop
        signal.stopped = True
        for connection in connections:
            connection.close_if_idle()

        # Gracefully shutdown timeout.
        # We should provide graceful_shutdown_timeout,
        # instead of letting connection hangs forever.