Created
November 12, 2020 14:16
-
-
Save DevKhalyd/87ae837f5620a3b3a775575aadffb3cc to your computer and use it in GitHub Desktop.
Log Console for Flutter
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
/* | |
In pubsbec yaml | |
Use that library | |
logger: ^0.9.4 | |
*/ | |
//File logger.dart | |
//More info: https://pub.dev/packages/logger | |
import 'package:logger/logger.dart'; | |
enum L { V, D, I, W, E, WTF } | |
class Log { | |
// ! output: null, Use the default LogOutput (-> send everything to console). Shake the phone to send the info to the phone | |
//Use for info,warning and WTF | |
static final _printerDefault = PrettyPrinter( | |
colors: true, // Colorful log messages | |
printEmojis: true, // Print an emoji for each log message | |
printTime: false, // Should each log print contain a timestamp | |
methodCount: 0); | |
static final _printer = PrettyPrinter( | |
colors: true, // Colorful log messages | |
printEmojis: true, // Print an emoji for each log message | |
printTime: true, | |
errorMethodCount: 6, | |
methodCount: 2); | |
static final _loggerDefault = Logger(printer: _printerDefault); | |
static final _logger = Logger(printer: _printer); | |
static void console(message, [L s = L.I, error, stackTrace]) { | |
switch (s) { | |
case L.I: | |
_loggerDefault.i(message, error, stackTrace); | |
break; | |
case L.W: | |
_loggerDefault.w(message, error, stackTrace); | |
break; | |
break; | |
case L.WTF: | |
_loggerDefault.wtf(message, error, stackTrace); | |
break; | |
case L.E: | |
_logger.e(message, error, stackTrace); | |
break; | |
case L.V: | |
_logger.v(message, error, stackTrace); | |
break; | |
case L.D: | |
_logger.d(message, error, stackTrace); | |
break; | |
default: | |
throw new UnimplementedError('Missing method'); | |
} | |
} | |
/* | |
Example stackTrace | |
Log.console( | |
L.E, 'Selected: ' + items[index], 'Error: ', StackTrace.current); | |
*/ | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment