当前位置: 首页>>代码示例>>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;未经允许,请勿转载。