Closed VictorUvarov closed 4 years ago
On version
0.7.0+1
I have the following LogPrinter extension to simplify the logs.Logger getLogger() { return Logger(printer: SimpleLogPrinter()); } class SimpleLogPrinter extends LogPrinter { @override void log(LogEvent event) { final color = PrettyPrinter.levelColors[event.level]; final emoji = PrettyPrinter.levelEmojis[event.level]; println(color('$emoji - ${event.message}')); } }
which prints the following image
Is it possible to have this functionality in 0.8.0? If so any code example would be much appreciated.
Bet you came here after watching the FilledStacks video 🤣 Here, try this:
import 'package:logger/logger.dart';
Logger getLogger(String className) {
return Logger(printer: SimpleLogPrinter(className));
}
class SimpleLogPrinter extends LogPrinter {
final String className;
SimpleLogPrinter(this.className);
@override
List<String> log(LogEvent event) {
AnsiColor color = PrettyPrinter.levelColors[event.level];
String emoji = PrettyPrinter.levelEmojis[event.level];
return [color('$emoji [$className]: ${event.message}')];
}
}
Haha yeah thanks a lot.
logger: ^1.1.0 // add in your pubspec.yaml
Make common method for whole project import 'package:flutter/foundation.dart'; import 'package:logger/logger.dart';
printLog(String className, String message, String logType) { final log = Logger( printer: PrettyPrinter( methodCount: 0, errorMethodCount: 3, lineLength: 50, colors: true, printEmojis: true, printTime: false)); if (kDebugMode) { //if you want in debug mode only switch (logType) { case "v": return log.v("[$className]: ${message}"); case "d": return log.d("[$className]: ${message}"); case "i": return log.i("[$className]: ${message}"); case "w": return log.w("[$className]: ${message}"); case "e": return log.e("[$className]: ${message}"); } } }
call this as below
import 'package:../common_components/logger.dart';
printLog("Your class name or title of log", "Your message", "v"); //in last params you should pass log type like v, d, i, w, e
On version
0.7.0+1
I have the following LogPrinter extension to simplify the logs.which prints the following image
Is it possible to have this functionality in 0.8.0? If so any code example would be much appreciated.