mirror of
https://github.com/sileht/bird-lg.git
synced 2024-11-22 15:04:41 +01:00
Add access log
This commit is contained in:
parent
298b1459fa
commit
1d20093048
12
lg-proxy.py
12
lg-proxy.py
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from logging.handlers import TimedRotatingFileHandler
|
from logging.handlers import TimedRotatingFileHandler
|
||||||
|
from logging import FileHandler
|
||||||
import subprocess
|
import subprocess
|
||||||
from urllib import unquote
|
from urllib import unquote
|
||||||
|
|
||||||
|
@ -34,9 +35,17 @@ app.debug = app.config["DEBUG"]
|
||||||
app.config.from_pyfile('lg-proxy.cfg')
|
app.config.from_pyfile('lg-proxy.cfg')
|
||||||
|
|
||||||
file_handler = TimedRotatingFileHandler(filename=app.config["LOG_FILE"], when="midnight")
|
file_handler = TimedRotatingFileHandler(filename=app.config["LOG_FILE"], when="midnight")
|
||||||
file_handler.setLevel(getattr(logging, app.config["LOG_LEVEL"].upper()))
|
app.logger.setLevel(getattr(logging, app.config["LOG_LEVEL"].upper()))
|
||||||
app.logger.addHandler(file_handler)
|
app.logger.addHandler(file_handler)
|
||||||
|
|
||||||
|
@app.before_request
|
||||||
|
def access_log_before(*args, **kwargs):
|
||||||
|
app.logger.info("[%s] request %s, %s", request.remote_addr, request.url, "|".join(["%s:%s"%(k,v) for k,v in request.headers.items()]))
|
||||||
|
|
||||||
|
@app.after_request
|
||||||
|
def access_log_after(response, *args, **kwargs):
|
||||||
|
app.logger.info("[%s] reponse %s, %s", request.remote_addr, request.url, response.status_code)
|
||||||
|
return response
|
||||||
|
|
||||||
def check_accesslist():
|
def check_accesslist():
|
||||||
if app.config["ACCESS_LIST"] and request.remote_addr not in app.config["ACCESS_LIST"]:
|
if app.config["ACCESS_LIST"] and request.remote_addr not in app.config["ACCESS_LIST"]:
|
||||||
|
@ -87,5 +96,6 @@ def bird():
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
app.logger.info("lg-proxy start")
|
||||||
app.run("0.0.0.0")
|
app.run("0.0.0.0")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue