Skip to content

Instantly share code, notes, and snippets.

@JaveedIshaq
Last active April 1, 2024 03:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JaveedIshaq/1945685e6241cfea544c384d2a707c53 to your computer and use it in GitHub Desktop.
Save JaveedIshaq/1945685e6241cfea544c384d2a707c53 to your computer and use it in GitHub Desktop.
Log Extension
// 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