示例#1
0
def create():
    app = connexion.FlaskApp(__name__, port=9090, specification_dir='openapi/')
    json_logging.ENABLE_JSON_LOGGING = True
    json_logging.init(framework_name='connexion')
    json_logging.init_request_instrument(app)

    app.add_api('helloworld-api.yaml',
                arguments={'title': 'Hello World Example'})
    return app
示例#2
0
def init_logging():

    logging.basicConfig()
    json_logging.ENABLE_JSON_LOGGING = True
    json_logging.init(framework_name='connexion')

    if "gunicorn" in os.environ.get("SERVER_SOFTWARE", ""):
        logging.getLogger('gunicorn.access').handlers = []

    if "hypercorn" in os.environ.get("SERVER_SOFTWARE", ""):
        logging.getLogger('hypercorn.access').handlers = []
示例#3
0
def create_app():
    app = Flask(__name__)
    setup_metrics(app)

    json_logging.ENABLE_JSON_LOGGING = True
    json_logging.init(framework_name='flask')
    json_logging.init_request_instrument(app)
    logger = logging.getLogger("app-logger")
    logger.setLevel(logging.INFO)
    logger.addHandler(logging.StreamHandler(sys.stdout))

    cors = CORS(app, resources={r"/api/*": {"origins": "*"}})
    api = Api(app)

    @app.route('/ping')
    def ping():
        logger.info("pinged", extra={'tags': ['role:web', 'env:prod']})
        return jsonify(ping='pong')

    @app.route("/healthz", methods=["GET"])
    def healthz():
        logger.info("health-checked", extra={'tags': ['role:web', 'env:prod']})
        return jsonify({"status": "SUCCESS"})

    @app.route('/metrics')
    def metrics():
        return Response(prometheus_client.generate_latest(),
                        mimetype=CONTENT_TYPE_LATEST)

    api.add_resource(TaskList, "/tasks")
    api.add_resource(Task, "/tasks/<int:id>")

    def initialize_tracer():
        config = Config(config={
            'sampler': {
                'type': 'const',
                'param': 1
            },
            'local_agent': {
                'reporting_host': "cicdnode-0.vdigital.io",
                'reporting_port': 6831
            }
        },
                        service_name='task-service')
        return config.initialize_tracer()  # also sets opentracing.tracer

    flask_tracer = FlaskTracer(initialize_tracer, True, app)

    return app
示例#4
0
def logger_init():
    json_logging.init(custom_formatter=CustomJSONLog)

# You would normally import logger_init and setup the logger in your main module - e.g.
# main.py
#logger_init()

#logger = logging.getLogger("test-logger")
#logger.setLevel(logging.DEBUG)
#logger.addHandler(logging.StreamHandler(sys.stdout))

#logger.info("test logging statement")
# CRITICAL
# ERROR
# WARNING
# INFO
# DEBUG
示例#5
0
from classes.centinela import Centinela
from PydoNovosoft.utils import Utils
from threading import Thread
from time import sleep
import os
import json_logging
import logging
import sys

json_logging.ENABLE_JSON_LOGGING = True
json_logging.init()

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logger.addHandler(logging.StreamHandler(sys.stdout))

config = Utils.read_config("package.json")
env_cfg = config[os.environ["environment"]]

if env_cfg["secrets"]:
    mzone_user = Utils.get_secret("centinelaz_user")
    mzone_pass = Utils.get_secret("centinelaz_pass")
    mzone_secret = Utils.get_secret("mzone_secret")
    centinela_token = Utils.get_secret("centinela_token")
    pghost = Utils.get_secret("pg_host")
    pguser = Utils.get_secret("pg_user")
    pgpass = Utils.get_secret("pg_pass")
else:
    mzone_user = env_cfg["mzone_user"]
    mzone_pass = env_cfg["mzone_pass"]
    mzone_secret = env_cfg["mzone_secret"]
import logging
import sys

import flask

import json_logging

app = flask.Flask(__name__)
json_logging.ENABLE_JSON_LOGGING = True
# json_logging.CREATE_CORRELATION_ID_IF_NOT_EXISTS = False
json_logging.init(framework_name='flask')
json_logging.init_request_instrument(app)

# init the logger as usual
logger = logging.getLogger("test logger")
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler(sys.stdout))


@app.route('/')
def home():
    logger.info("test log statement")
    logger.info("test log statement",
                extra={'props': {
                    "extra_property": 'extra_value'
                }})
    return "Hello world"


@app.route('/exception')
def exception():
def logger_init():
    json_logging.init(custom_formatter=CustomJSONLog)
import asyncio
import logging
import sys

import quart

import json_logging

app = quart.Quart(__name__)
json_logging.ENABLE_JSON_LOGGING = True
json_logging.init(framework_name='quart')
json_logging.init_request_instrument(app)

# init the logger as usual
logger = logging.getLogger("test logger")
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler(sys.stdout))


@app.route('/')
async def home():
    logger.info("test log statement")
    logger.info("test log statement", extra={'props': {"extra_property": 'extra_value'}})
    return "Hello world"


if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    app.run(host='0.0.0.0', port=int(5000), use_reloader=False, loop=loop)
import json_logging
import logging
# noinspection PyPackageRequirements
import sanic
import sys

app = sanic.Sanic()
json_logging.ENABLE_JSON_LOGGING = True
json_logging.init(framework_name='sanic')
json_logging.init_request_instrument(app)

# init the logger as usual
logger = logging.getLogger("sanic-integration-test-app")
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler(sys.stdout))


# noinspection PyUnusedLocal
@app.route("/")
async def test(request):
    logger.info("test log statement")
    logger.info("test log statement",
                extra={'props': {
                    "extra_property": 'extra_value'
                }})
    # noinspection PyUnresolvedReferences
    return sanic.response.text("hello world")


if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8000)