Last active
April 1, 2024 03:29
-
-
Save JaveedIshaq/1945685e6241cfea544c384d2a707c53 to your computer and use it in GitHub Desktop.
Log Extension
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 'dart:developer' as devtools show log; | |
import 'package:flutter/foundation.dart'; | |
// call log on string and pass StackTrace if want file Name --> "here is log message".log(); | |
/// Extension on Object to enable conditional logging in debug mode. | |
extension Log on Object { | |
void log() { | |
if (kDebugMode) { | |
String callerInfo = StackTrace.current.toString().split('\n')[1]; | |
String location = callerInfo.substring( | |
callerInfo.indexOf('package:'), callerInfo.length - 1); | |
// Define ANSI escape codes for text formatting | |
const String reset = '\x1B[0m'; // Reset all attributes | |
const String colorGreen = '\x1B[32m'; | |
const String colorMagenta = '\x1B[35m'; | |
const String colorLightCyan = '\x1B[94m'; | |
debugPrint( | |
'$colorGreen----------------🪄️🪄️🪄️LOG MESSAGE🪄️🪄️🪄️----------------$reset'); | |
print('🔑 $colorMagenta$location$reset'); | |
debugPrint('$colorLightCyan${toString()}$reset'); | |
debugPrint(''); | |
debugPrint( | |
'$colorGreen--------------------------🔧🔧🔧🔧🔧---------------------------$reset'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment