加入重连机制忽略日志记录错误

This commit is contained in:
2025-03-05 14:10:03 +08:00
parent a2155976f3
commit a15345adeb
5 changed files with 96 additions and 26 deletions

View File

@@ -25,7 +25,14 @@ class LokiLogger implements Logger {
BaseOptions(baseUrl: _config == null ? "" : _config.host, headers: {
"Content-Type": "application/json",
if (!identical(0, 0.0)) "Content-Encoding": "gzip"
}));
})) {
dio.interceptors.add(InterceptorsWrapper(
onError: (error, handler) => {
//忽略异常
print("logerr:###$error###")
},
));
}
@override
void debug(String msg,
{String? tag, String? traceId, String? spanId, String? parentSpanId}) {
@@ -106,12 +113,14 @@ class LokiLogger implements Logger {
]
});
//判断平台
if (identical(0, 0.0)) {
dio.post("/loki/api/v1/push", data: data);
} else {
var zip = gzip.encode(utf8.encode(data));
dio.post("/loki/api/v1/push", data: zip);
}
if (level == LoggerLevel.debug || _config.print) {
print(log);
}