hi-client/lib/app/utils/kr_log_util.dart
Rust 4c5763647d refactor: 优化日志输出,仅在调试模式下启用
- 为所有 print 语句添加 kDebugMode 检查
- 更新 KRLogUtil 工具类,Release 模式下禁用日志输出
- 优化 18 个文件中的 335+ 条日志语句
- 提升 Release 版本性能并增强安全性

(cherry picked from commit 301f1510ba81fe94fb08e013ca80b3ca708a2e15)
2025-11-01 23:31:11 -07:00

68 lines
1.7 KiB
Dart
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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);
}
}
}