Line data Source code
1 : // ignore_for_file: public_member_api_docs 2 : 3 : import 'package:flutter/foundation.dart'; 4 : 5 : class Log { 6 : static int _logLevel = 0; 7 : 8 0 : static set logLevel(LogLevel value) => 9 0 : _logLevel = LogLevel.values.indexOf(value); 10 : 11 7 : static void d(Object tag, [String? message]) { 12 0 : if (kDebugMode || _logLevel == LogLevel.values.indexOf(LogLevel.d)) { 13 7 : _write(LogLevel.d, tag, message); 14 : } 15 : } 16 : 17 0 : static void e(Object tag, [String? message]) { 18 0 : if (_logLevel <= LogLevel.values.indexOf(LogLevel.e)) { 19 0 : _write(LogLevel.e, tag, message); 20 : } 21 : } 22 : 23 0 : static void w(Object tag, [String? message]) { 24 0 : if (_logLevel <= LogLevel.values.indexOf(LogLevel.w)) { 25 0 : _write(LogLevel.w, tag, message); 26 : } 27 : } 28 : 29 0 : static void i(Object tag, [String? message]) { 30 0 : if (_logLevel <= LogLevel.values.indexOf(LogLevel.i)) { 31 0 : _write(LogLevel.i, tag, message); 32 : } 33 : } 34 : 35 7 : static void _write(LogLevel type, Object tag, String? message) { 36 : // ignore: avoid_print 37 7 : print( 38 28 : '''${type.toStringFormatted()}, ${DateTime.now()}, ${_tagToString(tag)}: ${message ?? ""}'''); 39 : } 40 : 41 7 : static String _tagToString(Object tag) => 42 13 : tag is String ? tag : tag.toString(); 43 : } 44 : 45 17 : enum LogLevel { d, e, w, i } 46 : 47 : extension _LogTypeExtension on LogLevel { 48 42 : String toStringFormatted() => '[${toString().split('.').last.toUpperCase()}]'; 49 : }