Last active
June 8, 2023 17:28
-
-
Save zty5678/3ad0ff99f7ce74a4de558b495d4f6ecb to your computer and use it in GitHub Desktop.
flutter LOGD 打印行号
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/foundation.dart'; | |
void LOGD(Object message, StackTrace trace) { | |
try { | |
if (kDebugMode) { | |
CustomTrace programInfo = CustomTrace(trace); | |
// print("[(${programInfo.fileName}:${programInfo.lineNumber})]$message"); | |
print("[(${programInfo.methodFullInfo})]$message"); | |
} | |
} catch (e) { | |
print(e); | |
} | |
} | |
class CustomTrace { | |
final StackTrace _trace; | |
String methodFullInfo = ""; | |
CustomTrace(this._trace) { | |
_parseTrace(); | |
} | |
void _parseTrace() { | |
var list = this._trace.toString().split("\n"); | |
var traceString = list.first; | |
// print("traceString=///$traceString///"); | |
var begin = traceString.lastIndexOf("(") + 1; | |
var end = traceString.lastIndexOf(")"); | |
methodFullInfo = traceString.substring(begin, end); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment