支持flutter调用

This commit is contained in:
2025-01-15 09:55:42 +08:00
parent 234d8ea7ca
commit 0fee2d7f69
7 changed files with 88 additions and 17 deletions

View File

@@ -21,12 +21,11 @@ class LokiLogger implements Logger {
final Dio dio;
LoggerLevel level = LoggerLevel.info;
LokiLogger(this._config)
: dio = Dio(BaseOptions(
baseUrl: _config == null ? "" : _config.host,
headers: {
"Content-Type": "application/json",
"Content-Encoding": "gzip"
}));
: dio = Dio(
BaseOptions(baseUrl: _config == null ? "" : _config.host, headers: {
"Content-Type": "application/json",
if (!identical(0, 0.0)) "Content-Encoding": "gzip"
}));
@override
void debug(String msg,
{String? tag, String? traceId, String? spanId, String? parentSpanId}) {
@@ -91,7 +90,7 @@ class LokiLogger implements Logger {
var now = DateTime.now();
// 转换为纳秒
int nanoseconds = now.microsecondsSinceEpoch * 1000;
var zip = gzip.encode(utf8.encode(jsonEncode({
var data = jsonEncode({
"streams": [
{
"stream": {
@@ -105,9 +104,15 @@ class LokiLogger implements Logger {
]
}
]
})));
dio.post("/loki/api/v1/push", data: zip);
if (level == LoggerLevel.debug) {
});
//判断平台
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);
}
}