PythonAnywhere上Flask的日志记录格式

时间:2018-08-07 04:58:12

标签: python logging flask wsgi pythonanywhere

我正在PythonAnywhere上运行Flask Web应用程序。访问日志import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; public class Thing { private String key; private int value; public Thing(String key, int value) { super(); this.key = key; this.value = value; } public String getKey() { return key; } public void setKey(String key) { this.key = key; } public int getValue() { return value; } public void setValue(int value) { this.value = value; } @Override public String toString() { return "Thing [key=" + key + ", value=" + value + "]"; } public static void main(String[] args) { List<Thing> source = Arrays.asList( new Thing("input1", 3), new Thing("input2", 1), new Thing("input2", 3000), new Thing("input1", 4), new Thing("input4", 200)); List<Thing> target = source.stream().collect(Collectors.groupingBy(thing -> thing.key)).entrySet().stream() .map(e -> e.getValue().stream().reduce((f1, f2) -> new Thing(f1.key, f1.value + f2.value))) .map(f -> f.get()).collect(Collectors.toList()); System.out.println(target); } } 的格式为:

xyz.pythonanywhere.com.access.log

我正试图摆脱IP。

所有修改或覆盖记录器的方法均无效。以下几行成功地影响了本地计算机上的日志记录:

12.34.167.189 - - [07/Aug/2018:04:33:46 +0000] "GET /foo/bar?id=abc HTTP/1.1" 200 117942 "-" "-" "12.34.167.189" response-time=0.041

但是,在PythonAnywhere上,Flask与import logging from werkzeug.serving import WSGIRequestHandler logger = logging.getLogger('werkzeug') WSGIRequestHandler.log = lambda self, type, msg, *args: getattr(logger, type)(msg % args) 的启动方式不同。日志记录格式没有改变。

那么,如何配置WSGI日志记录?

1 个答案:

答案 0 :(得分:3)

访问日志未通过Python运行。那直接来自nginx。无法更改它。