日志初始配置添加自定义标签
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:EasyDartModule/base/logger/Logger.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:shelf/shelf.dart' as sf;
|
||||
@@ -41,8 +43,11 @@ class TraceDio {
|
||||
options.headers['X-Span-ID'] = spanId;
|
||||
}
|
||||
// 记录请求日志
|
||||
_logger?.info('发送请求: ${options.method} ${options.uri}',
|
||||
tag: "DIO", traceId: traceId, spanId: spanId);
|
||||
_logger?.info(
|
||||
'发送请求: ${options.method} ${options.uri} ${options.data != null ? jsonEncode(options.data) : ""}',
|
||||
tag: "DIO",
|
||||
traceId: traceId,
|
||||
spanId: spanId);
|
||||
return handler.next(options); // 继续请求
|
||||
},
|
||||
onResponse: (response, handler) {
|
||||
|
||||
@@ -38,7 +38,11 @@ abstract class Logger {
|
||||
class LoggerConfig {
|
||||
String host;
|
||||
String serviceName;
|
||||
Map<String, String>? lables;
|
||||
bool print;
|
||||
LoggerConfig(
|
||||
{required this.host, required this.serviceName, this.print = false});
|
||||
{required this.host,
|
||||
required this.serviceName,
|
||||
this.print = false,
|
||||
this.lables});
|
||||
}
|
||||
|
||||
@@ -50,13 +50,13 @@ class LokiLogger implements Logger {
|
||||
var lable = data["lable"];
|
||||
var time = data["time"];
|
||||
//合并日志
|
||||
if (lable.length == 1) {
|
||||
// if (lable.length == 1) {
|
||||
//只有默认标签
|
||||
labels = lable;
|
||||
logs.add([time, log]);
|
||||
} else {
|
||||
// } else {
|
||||
//有多个标签按照不同标签进行合并
|
||||
}
|
||||
// }
|
||||
}
|
||||
if (labels != null) {
|
||||
var data = jsonEncode({
|
||||
@@ -162,7 +162,12 @@ class LokiLogger implements Logger {
|
||||
var now = DateTime.now();
|
||||
// 转换为纳秒
|
||||
int nanoseconds = now.microsecondsSinceEpoch * 1000;
|
||||
var lableMap = {"service_name": _config.serviceName};
|
||||
var lableMap = {
|
||||
"service_name": _config.serviceName,
|
||||
};
|
||||
if (_config.lables != null) {
|
||||
lableMap.addAll(_config.lables!);
|
||||
}
|
||||
if (lable != null) {
|
||||
lableMap.addAll(lable);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:redis/redis.dart';
|
||||
|
||||
class Redis {
|
||||
|
||||
Reference in New Issue
Block a user