sanic/examples/override_logging.py

24 lines
510 B
Python
Raw Permalink Normal View History

2016-12-23 05:00:57 +00:00
import logging
2021-03-10 09:19:38 +00:00
from sanic import Sanic, text
2016-12-23 05:00:57 +00:00
logging_format = "[%(asctime)s] %(process)d-%(levelname)s "
logging_format += "%(module)s::%(funcName)s():l%(lineno)d: "
logging_format += "%(message)s"
2021-03-10 09:19:38 +00:00
logging.basicConfig(format=logging_format, level=logging.DEBUG)
2016-12-23 05:00:57 +00:00
log = logging.getLogger()
# Set logger to override default basicConfig
2021-03-10 09:19:38 +00:00
app = Sanic("app")
2021-03-10 09:19:38 +00:00
@app.route("/")
2016-12-23 05:00:57 +00:00
def test(request):
log.info("received request; responding with 'hey'")
2021-03-10 09:19:38 +00:00
return text("hey")
2016-12-23 05:00:57 +00:00
2021-03-10 09:19:38 +00:00
app.run(host="0.0.0.0", port=8000)