logger_flutter_fork 1.3.1 logger_flutter_fork: ^1.3.1 copied to clipboard
Flutter extension for logger. Please go there for documentation.
import 'package:flutter/material.dart';
import 'package:logger_fork/logger_fork.dart';
import 'package:logger_flutter_fork/logger_flutter_fork.dart';
void main() {
LogConsole.init();
log();
runApp(const MyApp());
}
var logger = Logger(
printer: PrettyPrinter(),
);
var loggerNoStack = Logger(
printer: PrettyPrinter(methodCount: 0),
);
void log() {
logger.d("Log message with 2 methods");
loggerNoStack.i("Info message");
loggerNoStack.w("Just a warning!");
logger.e("Error! Something bad happened", "Test Error");
loggerNoStack.v({"key": 5, "value": "something"});
loggerNoStack.wtf('What a terrible failure!');
Future.delayed(const Duration(seconds: 5), log);
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
LogConsoleOnShake(
child: const Text(
'Shake device to open the log console',
),
),
const Text(
'or tap on floating action button to see log console',
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () => LogConsole.open(context),
tooltip: 'info',
child: const Icon(Icons.info),
),
);
}
}