本文整理汇总了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
示例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
示例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")
示例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")
示例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")
示例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")
示例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")
示例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)
示例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
示例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'))
示例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")
示例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()
示例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)
示例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)
示例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)