Writing directly to stdout

This commit is contained in:
Felipe Martin 2020-04-27 15:46:57 +02:00
parent 86ffad86e5
commit 5419449c72
Signed by: fmartingr
GPG Key ID: 716BC147715E716F
1 changed files with 3 additions and 2 deletions

5
app.py
View File

@ -1,6 +1,7 @@
import json
import logging
import os
import sys
import requests
from flask import Flask, request, Response, render_template, jsonify
@ -94,12 +95,12 @@ def log_view():
"""
# JSON response
if request.is_json:
black_logger.warn(json.dumps(request.json))
sys.stdout.write(json.dumps(request.json) + "\n")
return jsonify(request.json)
# Plain text response
data = request.get_data().decode("utf-8")
black_logger.warn(data)
sys.stdout.write(f"{data}\n")
return Response(data, content_type="plain/text")