sanic/examples/override_logging.py

24 lines
540 B
Python
Raw 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
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000)