| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- import 'dart:convert';
- import 'package:logger/logger.dart';
- class Log {
- static final Logger _logger = Logger(
- printer: PrefixPrinter(PrettyPrinter()),
- );
- // verbose
- static void t(dynamic message) {
- _logger.t(message);
- }
- // debug
- static void d(dynamic message) {
- _logger.d(message);
- }
- // info
- static void i(dynamic message) {
- _logger.i(message);
- }
- // warning
- static void w(dynamic message) {
- _logger.w(message);
- }
- // error
- static void e(dynamic message) {
- _logger.e(message);
- }
- // wtf
- static void f(dynamic message) {
- _logger.f(message);
- }
- // json
- static void json(Map json, {String? title}) {
- if (title != null) {
- printFullText(title);
- }
- const encoder = JsonEncoder.withIndent(' '); // 2空格缩进
- final prettyString = encoder.convert(json);
- printFullText(prettyString);
- }
- static void printFullText(String text, {String? title}) {
- if (title != null) {
- print(title);
- }
- const int maxLineLength = 800;
- for (int i = 0; i < text.length; i += maxLineLength) {
- final end = (i + maxLineLength < text.length) ? i + maxLineLength : text.length;
- print(text.substring(i, end));
- }
- }
- }
|