import 'package:flutter/foundation.dart'; import 'package:loggy/loggy.dart'; /// 日志工具类 /// 🔒 Release模式下所有日志都不会输出,确保生产环境的性能和安全 class KRLogUtil { static final KRLogUtil _instance = KRLogUtil._internal(); factory KRLogUtil() => _instance; KRLogUtil._internal(); /// 初始化日志 static void kr_init() { // 只在 Debug 模式下初始化日志 if (kDebugMode) { Loggy.initLoggy( logPrinter: PrettyPrinter(), ); } } /// 调试日志 /// 🔒 只在 Debug 模式下输出 static void kr_d(String message, {String? tag}) { if (kDebugMode) { Loggy('${tag ?? 'KRLogUtil'}').debug(message); } } /// 信息日志 /// 🔒 只在 Debug 模式下输出 static void kr_i(String message, {String? tag}) { if (kDebugMode) { Loggy('${tag ?? 'KRLogUtil'}').info(message); } } /// 警告日志 /// 🔒 只在 Debug 模式下输出 static void kr_w(String message, {String? tag}) { if (kDebugMode) { Loggy('${tag ?? 'KRLogUtil'}').warning(message); } } /// 错误日志 /// 🔒 只在 Debug 模式下输出 static void kr_e(String message, {String? tag, Object? error, StackTrace? stackTrace}) { if (kDebugMode) { Loggy('${tag ?? 'KRLogUtil'}').error(message, error, stackTrace); } } /// 网络日志 /// 🔒 只在 Debug 模式下输出 static void kr_network(String message, {String? tag}) { if (kDebugMode) { Loggy('${tag ?? 'Network'}').info(message); } } /// 性能日志 /// 🔒 只在 Debug 模式下输出 static void kr_performance(String message, {String? tag}) { if (kDebugMode) { Loggy('${tag ?? 'Performance'}').info(message); } } }