當前位置: 首頁>>代碼示例>>Python>>正文


Python logger.info方法代碼示例

本文整理匯總了Python中sanic.log.logger.info方法的典型用法代碼示例。如果您正苦於以下問題:Python logger.info方法的具體用法?Python logger.info怎麽用?Python logger.info使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sanic.log.logger的用法示例。


在下文中一共展示了logger.info方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_log

# 需要導入模塊: from sanic.log import logger [as 別名]
# 或者: from sanic.log.logger import info [as 別名]
def test_log(app):
    log_stream = StringIO()
    for handler in logging.root.handlers[:]:
        logging.root.removeHandler(handler)
    logging.basicConfig(
        format=logging_format, level=logging.DEBUG, stream=log_stream
    )
    log = logging.getLogger()
    rand_string = str(uuid.uuid4())

    @app.route("/")
    def handler(request):
        log.info(rand_string)
        return text("hello")

    request, response = app.test_client.get("/")
    log_text = log_stream.getvalue()
    assert rand_string in log_text 
開發者ID:huge-success,項目名稱:sanic,代碼行數:20,代碼來源:test_logging.py

示例2: fetch

# 需要導入模塊: from sanic.log import logger [as 別名]
# 或者: from sanic.log.logger import info [as 別名]
def fetch(url, pass_through=False):
    async with aiohttp.ClientSession() as session:
        async with session.get(url, headers={"accept": 'application/activity+json',
                                             "user-agent": f"PubGate v:{__version__}"}
                               ) as resp:
            status_code = resp.status
            logger.info(f"Fetch {url}, status: {resp.status}, {resp.reason}")

            try:
                result = await resp.json(encoding='utf-8')
                failed = False
            except aiohttp.ContentTypeError as e:
                result = {'fetch_error': await resp.text()}
                status_code = 500
                failed = e

            if pass_through:
                return status_code, result
            elif failed:
                raise failed
            return result 
開發者ID:autogestion,項目名稱:pubgate,代碼行數:23,代碼來源:networking.py

示例3: deliver_task

# 需要導入模塊: from sanic.log import logger [as 別名]
# 或者: from sanic.log.logger import info [as 別名]
def deliver_task(recipient, http_sig, activity, debug=False):
    logger.info(f"Delivering {make_label(activity)} ===>> {recipient}")

    profile = await fetch(recipient)
    url = profile["inbox"]
    body = json.dumps(activity)
    headers = http_sig.sign(url, body)

    async with aiohttp.ClientSession() as session:
        async with session.post(url,
                                data=body,
                                headers=headers) as resp:
            logger.info(f"Post to inbox {resp.real_url}, status: {resp.status}, {resp.reason}")
            if debug:
                from pprint import pprint
                pprint(activity)
                print(resp.request_info.headers)
            # print(resp.request_info.headers)
            print("\n") 
開發者ID:autogestion,項目名稱:pubgate,代碼行數:21,代碼來源:networking.py

示例4: before_start

# 需要導入模塊: from sanic.log import logger [as 別名]
# 或者: from sanic.log.logger import info [as 別名]
def before_start(app, loop):
    log.info("SERVER STARTING") 
開發者ID:huge-success,項目名稱:sanic,代碼行數:4,代碼來源:try_everything.py

示例5: after_start

# 需要導入模塊: from sanic.log import logger [as 別名]
# 或者: from sanic.log.logger import info [as 別名]
def after_start(app, loop):
    log.info("OH OH OH OH OHHHHHHHH") 
開發者ID:huge-success,項目名稱:sanic,代碼行數:4,代碼來源:try_everything.py

示例6: before_stop

# 需要導入模塊: from sanic.log import logger [as 別名]
# 或者: from sanic.log.logger import info [as 別名]
def before_stop(app, loop):
    log.info("SERVER STOPPING") 
開發者ID:huge-success,項目名稱:sanic,代碼行數:4,代碼來源:try_everything.py

示例7: after_stop

# 需要導入模塊: from sanic.log import logger [as 別名]
# 或者: from sanic.log.logger import info [as 別名]
def after_stop(app, loop):
    log.info("TRIED EVERYTHING") 
開發者ID:huge-success,項目名稱:sanic,代碼行數:4,代碼來源:try_everything.py

示例8: log_response

# 需要導入模塊: from sanic.log import logger [as 別名]
# 或者: from sanic.log.logger import info [as 別名]
def log_response(self, response):
        """
        Helper method provided to enable the logging of responses in case if
        the :attr:`HttpProtocol.access_log` is enabled.

        :param response: Response generated for the current request

        :type response: :class:`sanic.response.HTTPResponse` or
            :class:`sanic.response.StreamingHTTPResponse`

        :return: None
        """
        if self.access_log:
            extra = {"status": getattr(response, "status", 0)}

            if isinstance(response, HTTPResponse):
                extra["byte"] = len(response.body)
            else:
                extra["byte"] = -1

            extra["host"] = "UNKNOWN"
            if self.request is not None:
                if self.request.ip:
                    extra["host"] = f"{self.request.ip}:{self.request.port}"

                extra["request"] = f"{self.request.method} {self.request.url}"
            else:
                extra["request"] = "nil"

            access_logger.info("", extra=extra) 
開發者ID:huge-success,項目名稱:sanic,代碼行數:32,代碼來源:server.py

示例9: _local_request

# 需要導入模塊: from sanic.log import logger [as 別名]
# 或者: from sanic.log.logger import info [as 別名]
def _local_request(self, method, url, *args, **kwargs):
        logger.info(url)
        raw_cookies = kwargs.pop("raw_cookies", None)

        if method == "websocket":
            async with websockets.connect(url, *args, **kwargs) as websocket:
                websocket.opened = websocket.open
                return websocket
        else:
            async with self.get_new_session() as session:

                try:
                    response = await getattr(session, method.lower())(
                        url, *args, **kwargs
                    )
                except NameError:
                    raise Exception(response.status_code)

                response.body = await response.aread()
                response.status = response.status_code
                response.content_type = response.headers.get("content-type")

                # response can be decoded as json after response._content
                # is set by response.aread()
                try:
                    response.json = response.json()
                except (JSONDecodeError, UnicodeDecodeError):
                    response.json = None

                if raw_cookies:
                    response.raw_cookies = {}

                    for cookie in response.cookies.jar:
                        response.raw_cookies[cookie.name] = cookie

                return response 
開發者ID:huge-success,項目名稱:sanic,代碼行數:38,代碼來源:testing.py

示例10: checkTimes

# 需要導入模塊: from sanic.log import logger [as 別名]
# 或者: from sanic.log.logger import info [as 別名]
def checkTimes():
    startTime = time.time()
    yield
    logger.info(
        colored(f'cost times: [{str(round(round(time.time()-startTime,5)*1000,3)) }]ms', 'green')) 
開發者ID:aoii103,項目名稱:FakeUA,代碼行數:7,代碼來源:uaServer.py

示例11: setup_on_deploy_user

# 需要導入模塊: from sanic.log import logger [as 別名]
# 或者: from sanic.log.logger import info [as 別名]
def setup_on_deploy_user(app, loop):
    user_data = json.loads(app.config.USER_ON_DEPLOY)
    username = user_data["username"].lower()
    password = user_data["password"]
    if username and password:
        is_uniq = await User.is_unique(doc=dict(name=username))
        if is_uniq in (True, None):
            user = await User.create(user_data, app.base_url)
            logger.info(f"On-deploy user {username} created") 
開發者ID:autogestion,項目名稱:pubgate,代碼行數:11,代碼來源:startapp.py

示例12: fetch_text

# 需要導入模塊: from sanic.log import logger [as 別名]
# 或者: from sanic.log.logger import info [as 別名]
def fetch_text(url):
    async with aiohttp.ClientSession() as session:
        async with session.get(url, headers={"accept": 'application/activity+json',
                                             "user-agent": f"PubGate v:{__version__}"}
                               ) as resp:
            logger.info(f"Fetch {url}, status: {resp.status}, {resp.reason}")
            return await resp.text() 
開發者ID:autogestion,項目名稱:pubgate,代碼行數:9,代碼來源:networking.py

示例13: connect_and_consume_c2

# 需要導入模塊: from sanic.log import logger [as 別名]
# 或者: from sanic.log.logger import info [as 別名]
def connect_and_consume_c2():
    connection = None
    while connection is None:
        try:
            connection = await aio_pika.connect_robust(host="127.0.0.1",
                                                       login="apfell_user",
                                                       password="apfell_password",
                                                       virtualhost="apfell_vhost")
            channel = await connection.channel()
            # declare our exchange
            await channel.declare_exchange('apfell_traffic', aio_pika.ExchangeType.TOPIC)
            # get a random queue that only the apfell server will use to listen on to catch all heartbeats
            queue = await channel.declare_queue('', exclusive=True)
            # bind the queue to the exchange so we can actually catch messages
            await queue.bind(exchange='apfell_traffic', routing_key="c2.status.#")

            await channel.set_qos(prefetch_count=50)
            logger.info(' [*] Waiting for messages in connect_and_consume_c2.')
            try:
                task = queue.consume(rabbit_c2_callback)
                result = await asyncio.wait_for(task, None)
            except Exception as e:
                logger.exception("Exception in connect_and_consume .consume: {}".format(str(e)))
                # print("Exception in connect_and_consume .consume: {}".format(str(e)))

        except Exception as e:
            logger.exception("Exception in connect_and_consume connect: {}".format(str(e)))
            # print("Exception in connect_and_consume connect: {}".format(str(e)))
        await asyncio.sleep(2) 
開發者ID:its-a-feature,項目名稱:Apfell,代碼行數:31,代碼來源:rabbitmq_api.py

示例14: connect_and_consume_pt

# 需要導入模塊: from sanic.log import logger [as 別名]
# 或者: from sanic.log.logger import info [as 別名]
def connect_and_consume_pt():
    connection = None
    while connection is None:
        try:
            connection = await aio_pika.connect_robust(host="127.0.0.1",
                                                       login="apfell_user",
                                                       password="apfell_password",
                                                       virtualhost="apfell_vhost")
            channel = await connection.channel()
            # declare our exchange
            await channel.declare_exchange('apfell_traffic', aio_pika.ExchangeType.TOPIC)
            # get a random queue that only the apfell server will use to listen on to catch all heartbeats
            queue = await channel.declare_queue('', exclusive=True)
            # bind the queue to the exchange so we can actually catch messages
            await queue.bind(exchange='apfell_traffic', routing_key="pt.status.#")
            #await queue.bind(exchange='apfell_traffic', routing_key="pt.status.*.create_payload_with_code.#")
            #await queue.bind(exchange='apfell_traffic', routing_key="pt.status.*.create_external_payload.#")
            #await queue.bind(exchange='apfell_traffic', routing_key="pt.status.*.load_transform_code.#")
            #await queue.bind(exchange='apfell_traffic', routing_key="pt.status.*.command_transform.#")
            #await queue.bind(exchange='apfell_traffic', routing_key="pt.status.*.load_transform_with_code.#")
            await channel.set_qos(prefetch_count=50)
            logger.info(' [*] Waiting for messages in connect_and_consume_pt.')
            try:
                task = queue.consume(rabbit_pt_callback)
                result = await asyncio.wait_for(task, None)
            except Exception as e:
                logger.exception("Exception in connect_and_consume .consume: {}".format(str(e)))
                # print("Exception in connect_and_consume .consume: {}".format(str(e)))
        except Exception as e:
            logger.exception("Exception in connect_and_consume connect: {}".format(str(e)))
            # print("Exception in connect_and_consume connect: {}".format(str(e)))
        await asyncio.sleep(2) 
開發者ID:its-a-feature,項目名稱:Apfell,代碼行數:34,代碼來源:rabbitmq_api.py

示例15: connect_and_consume_heartbeats

# 需要導入模塊: from sanic.log import logger [as 別名]
# 或者: from sanic.log.logger import info [as 別名]
def connect_and_consume_heartbeats():
    connection = None
    while connection is None:
        try:
            connection = await aio_pika.connect_robust(host="127.0.0.1",
                                                       login="apfell_user",
                                                       password="apfell_password",
                                                       virtualhost="apfell_vhost")
            channel = await connection.channel()
            # declare our exchange
            await channel.declare_exchange('apfell_traffic', aio_pika.ExchangeType.TOPIC)
            # get a random queue that only the apfell server will use to listen on to catch all heartbeats
            queue = await channel.declare_queue('', exclusive=True)
            # bind the queue to the exchange so we can actually catch messages
            await queue.bind(exchange='apfell_traffic', routing_key="*.heartbeat.#")
            await channel.set_qos(prefetch_count=20)
            logger.info(' [*] Waiting for messages in connect_and_consume_heartbeats.')
            try:
                task = queue.consume(rabbit_heartbeat_callback)
                result = await asyncio.wait_for(task, None)
            except Exception as e:
                logger.exception("Exception in connect_and_consume .consume: {}".format(str(e)))
                # print("Exception in connect_and_consume .consume: {}".format(str(e)))
        except Exception as e:
            logger.exception("Exception in connect_and_consume connect: {}".format(str(e)))
            # print("Exception in connect_and_consume connect: {}".format(str(e)))
        await asyncio.sleep(2) 
開發者ID:its-a-feature,項目名稱:Apfell,代碼行數:29,代碼來源:rabbitmq_api.py


注:本文中的sanic.log.logger.info方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。