-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
54 lines (34 loc) · 1.08 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from flask import Flask, jsonify
import logging
app = Flask(__name__)
FORMAT = "%(asctime)s, %(funcName)s %(message)s"
ENDPOINT_REACHED = "endpoint was reached"
@app.get("/")
def hello():
app.logger.info(ENDPOINT_REACHED)
return "Hello World!"
@app.get("/status")
def status():
response = jsonify(user="admin", result="OK - healthy")
app.logger.debug(ENDPOINT_REACHED)
return response, 200
@app.get("/metrics")
def metrics():
response = jsonify(
status="success",
code=0,
data={"UserCount": 140, "UserCountActive": 23},
)
app.logger.debug(ENDPOINT_REACHED)
return response, 200
if __name__ == "__main__":
app.logger.setLevel(logging.DEBUG)
file_handler = logging.FileHandler("app.log")
file_handler.setLevel(logging.DEBUG)
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)
app.logger.addHandler(file_handler)
app.logger.addHandler(console_handler)
formatter = logging.Formatter(FORMAT)
file_handler.setFormatter(formatter)
app.run(host="0.0.0.0", debug=False)