|
7 | 7 |
|
8 | 8 | app = flask.Flask(__name__) |
9 | 9 | json_logging.init_flask(enable_json=True) |
10 | | -json_logging.init_request_instrument(app, exclude_url_patterns=[r'/exclude_from_request_instrumentation']) |
| 10 | +json_logging.init_request_instrument( |
| 11 | + app, exclude_url_patterns=[r'/ready', r'/alive']) |
11 | 12 |
|
12 | | -# init the logger as usual |
13 | | -logger = logging.getLogger("test logger") |
14 | | -logger.setLevel(logging.DEBUG) |
15 | | -logger.addHandler(logging.StreamHandler(sys.stdout)) |
| 13 | +app.logger.setLevel(logging.getLevelName(env.get('LOGLEVEL', 'INFO').upper())) |
| 14 | +app.logger.addHandler(logging.StreamHandler(sys.stdout)) |
| 15 | +app.logger.removeHandler(default_handler) |
16 | 16 |
|
| 17 | +app.config["MONGO_URI"] = env.get("MONGO_DSN") |
17 | 18 |
|
18 | | -@app.route('/') |
19 | | -def home(): |
20 | | - logger.info("test log statement") |
21 | | - logger.info("test log statement with extra props", extra={'props': {"extra_property": 'extra_value'}}) |
22 | | - logger.info("test log statement with custom correlation id", extra={'props': {'correlation_id': 'custom_correlation_id'}}) |
23 | | - |
24 | | - correlation_id = json_logging.get_correlation_id() |
25 | | - return "hello world" \ |
26 | | - "\ncorrelation_id : " + correlation_id |
27 | | - |
28 | | - |
29 | | -@app.route('/exception') |
30 | | -def exception(): |
31 | | - try: |
32 | | - raise RuntimeError |
33 | | - except BaseException as e: |
34 | | - logger.error("Error occurred", exc_info=e) |
35 | | - logger.exception("Error occurred", exc_info=e) |
36 | | - return "Error occurred, check log for detail" |
37 | | - |
38 | | - |
39 | | -@app.route('/exclude_from_request_instrumentation') |
40 | | -def exclude_from_request_instrumentation(): |
41 | | - return "this request wont log request instrumentation information" |
42 | | - |
43 | | - |
44 | | -if __name__ == "__main__": |
45 | | - app.run(host='0.0.0.0', port=int(5000), use_reloader=False) |
| 19 | +client = MongoClient(app.config["MONGO_URI"]) |
| 20 | +app.logger.debug(client.server_info()) |
0 commit comments