{"action":"created","issue":{"url":"https://api.github.com/repos/Kozea/WeasyPrint/issues/671","repository_url":"https://api.github.com/repos/Kozea/WeasyPrint","labels_url":"https://api.github.com/repos/Kozea/WeasyPrint/issues/671/labels{/name}","comments_url":"https://api.github.com/repos/Kozea/WeasyPrint/issues/671/comments","events_url":"https://api.github.com/repos/Kozea/WeasyPrint/issues/671/events","html_url":"https://github.com/Kozea/WeasyPrint/issues/671","id":351299717,"node_id":"MDU6SXNzdWUzNTEyOTk3MTc=","number":671,"title":"Weasyprint in combination with gunicorn produces empty response with no error log","user":{"login":"knyttl","id":401107,"node_id":"MDQ6VXNlcjQwMTEwNw==","avatar_url":"https://avatars3.githubusercontent.com/u/401107?v=4","gravatar_id":"","url":"https://api.github.com/users/knyttl","html_url":"https://github.com/knyttl","followers_url":"https://api.github.com/users/knyttl/followers","following_url":"https://api.github.com/users/knyttl/following{/other_user}","gists_url":"https://api.github.com/users/knyttl/gists{/gist_id}","starred_url":"https://api.github.com/users/knyttl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/knyttl/subscriptions","organizations_url":"https://api.github.com/users/knyttl/orgs","repos_url":"https://api.github.com/users/knyttl/repos","events_url":"https://api.github.com/users/knyttl/events{/privacy}","received_events_url":"https://api.github.com/users/knyttl/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2018-08-16T17:30:58Z","updated_at":"2018-08-16T20:08:56Z","closed_at":null,"author_association":"NONE","body":"This is probably something in combination with gunicorn, most probably not having to do anything with weasyprint, but I am stuck and have no idea which way to go.\r\n\r\n```\r\nimport logging\r\n\r\nfrom flask import Flask, request, make_response, jsonify\r\nfrom weasyprint import HTML\r\n\r\napp = Flask('pdf')\r\n\r\n\r\n@app.before_first_request\r\ndef setup_logging():\r\n    logging.addLevelName(logging.DEBUG, \"\\033[1;36m%s\\033[1;0m\" % logging.getLevelName(logging.DEBUG))\r\n    logging.addLevelName(logging.INFO, \"\\033[1;32m%s\\033[1;0m\" % logging.getLevelName(logging.INFO))\r\n    logging.addLevelName(logging.WARNING, \"\\033[1;33m%s\\033[1;0m\" % logging.getLevelName(logging.WARNING))\r\n    logging.addLevelName(logging.ERROR, \"\\033[1;31m%s\\033[1;0m\" % logging.getLevelName(logging.ERROR))\r\n\r\n    handler = logging.StreamHandler()\r\n    handler.setFormatter(logging.Formatter(\r\n        '%(asctime)s %(levelname)s: %(message)s '\r\n        '[in %(pathname)s:%(lineno)d]'\r\n    ))\r\n    app.logger.addHandler(handler)\r\n    app.logger.setLevel(logging.DEBUG)\r\n\r\n\r\n@app.route('/', methods=['POST'])\r\ndef generate():\r\n    name = request.args.get('filename', 'export.pdf')\r\n    app.logger.info('PDF %s' % \" \".join(request.data.decode('utf-8').split()).replace(\"> <\", \"><\")[0:100])\r\n    html = HTML(string=request.data)\r\n    pdf = html.write_pdf()\r\n    response = make_response(pdf)\r\n    response.headers['Content-Type'] = 'application/pdf'\r\n    response.headers['Content-Disposition'] = 'inline;filename=%s' % name\r\n    return response\r\n\r\nif __name__ == '__main__':\r\n    app.run()\r\n```\r\n\r\nI run this script in a docker image which runs mostly fine, but I suspect all the weasyprint logs are thrown away as i never see them logged. Especially in case of an error, I just get an empty result with no error. \r\n\r\nWhat kind of logging tool weasyprint uses? Is it somehow compatible with the way gunicorn logs stuff?"},"comment":{"url":"https://api.github.com/repos/Kozea/WeasyPrint/issues/comments/413669269","html_url":"https://github.com/Kozea/WeasyPrint/issues/671#issuecomment-413669269","issue_url":"https://api.github.com/repos/Kozea/WeasyPrint/issues/671","id":413669269,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMzY2OTI2OQ==","user":{"login":"liZe","id":952243,"node_id":"MDQ6VXNlcjk1MjI0Mw==","avatar_url":"https://avatars0.githubusercontent.com/u/952243?v=4","gravatar_id":"","url":"https://api.github.com/users/liZe","html_url":"https://github.com/liZe","followers_url":"https://api.github.com/users/liZe/followers","following_url":"https://api.github.com/users/liZe/following{/other_user}","gists_url":"https://api.github.com/users/liZe/gists{/gist_id}","starred_url":"https://api.github.com/users/liZe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liZe/subscriptions","organizations_url":"https://api.github.com/users/liZe/orgs","repos_url":"https://api.github.com/users/liZe/repos","events_url":"https://api.github.com/users/liZe/events{/privacy}","received_events_url":"https://api.github.com/users/liZe/received_events","type":"User","site_admin":false},"created_at":"2018-08-16T20:08:56Z","updated_at":"2018-08-16T20:08:56Z","author_association":"MEMBER","body":"> Would this be enough?\r\n\r\nNo, it wouldn't. You have to use these lines (from the documentation):\r\n```python\r\nimport logging\r\nlogger = logging.getLogger('weasyprint')\r\nlogger.addHandler(logging.FileHandler('/path/to/weasyprint.log'))\r\n```\r\n\r\nAnd if you want to get debug messages:\r\n```python\r\nlogger.setLevel(logging.DEBUG)\r\n```\r\n\r\n`app.logger` is not WeasyPrint's logger, it's your Flask app's logger. Please read carefully the documentation (for WeasyPrint and Python's `logging` module), it's a bit painful to understand how logging works in Python but everything's there."}}
{"actor":{"display_login":"liZe"}}