├── art ├── base_image.png ├── base_image2.png └── base_image3.png ├── lib ├── src │ ├── i_ulog_format_strategy.dart │ ├── i_ulog_adapter.dart │ ├── i_ulog_printer.dart │ ├── ulog_console_adapter.dart │ ├── ansi_color.dart │ ├── ulog.dart │ ├── ulog_utils.dart │ ├── ulog_lib_printer.dart │ └── ulog_lib_console_format_strategy.dart └── flutter_ulog.dart ├── CHANGELOG.md ├── .metadata ├── LICENSE ├── .gitignore ├── pubspec.yaml ├── pubspec.lock ├── test └── flutter_ulog_test.dart ├── README-zh.md ├── README-jp.md └── README.md /art/base_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartbackme/ulog/HEAD/art/base_image.png -------------------------------------------------------------------------------- /art/base_image2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartbackme/ulog/HEAD/art/base_image2.png -------------------------------------------------------------------------------- /art/base_image3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smartbackme/ulog/HEAD/art/base_image3.png -------------------------------------------------------------------------------- /lib/src/i_ulog_format_strategy.dart: -------------------------------------------------------------------------------- 1 | 2 | import 'package:flutter_ulog/src/ulog.dart'; 3 | ///log格式处理 4 | abstract class ULogFormatStrategy{ 5 | ///log 打日志 6 | void log(ULogType type,String? tag,String? message); 7 | } -------------------------------------------------------------------------------- /lib/src/i_ulog_adapter.dart: -------------------------------------------------------------------------------- 1 | 2 | import 'ulog.dart'; 3 | 4 | abstract class ULogAdapter{ 5 | ///是否开启日志 6 | bool isLoggable(ULogType type,String? tag); 7 | ///log 打日志 8 | void log(ULogType type,String? tag,String? message); 9 | } -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.0.1 2 | 3 | - First version of the new ulog 4 | 5 | ## 0.0.2 6 | 7 | - add log stackTrace 8 | 9 | ## 0.0.3 10 | 11 | - remove ulog.o(),remove init json func 12 | 13 | ## 0.0.4 14 | 15 | - fixbug json tag 16 | 17 | ## 0.0.5 18 | 19 | - fixbug message utf-8 -------------------------------------------------------------------------------- /.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: f4abaa0735eba4dfd8f33f73363911d63931fe03 8 | channel: stable 9 | 10 | project_type: package 11 | -------------------------------------------------------------------------------- /lib/flutter_ulog.dart: -------------------------------------------------------------------------------- 1 | library flutter_ulog; 2 | 3 | export 'package:flutter_ulog/src/i_ulog_adapter.dart'; 4 | export 'package:flutter_ulog/src/i_ulog_format_strategy.dart'; 5 | export 'package:flutter_ulog/src/i_ulog_printer.dart'; 6 | export 'package:flutter_ulog/src/ulog.dart'; 7 | export 'package:flutter_ulog/src/ulog_console_adapter.dart'; 8 | export 'package:flutter_ulog/src/ulog_lib_printer.dart'; 9 | export 'package:flutter_ulog/src/ulog_lib_console_format_strategy.dart'; -------------------------------------------------------------------------------- /lib/src/i_ulog_printer.dart: -------------------------------------------------------------------------------- 1 | 2 | import 'i_ulog_adapter.dart'; 3 | import 'ulog.dart'; 4 | 5 | abstract class ULogPrinter{ 6 | 7 | 8 | void clearLogAdapters(); 9 | void addAdapter(ULogAdapter adapter); 10 | void removeLogAdapters(ULogAdapter adapter); 11 | // void xml(String xml,{String? tag}); 12 | // void o(dynamic obj,{String? tag}); 13 | void json(String json,{String? tag}); 14 | void log(ULogType type,dynamic message,{dynamic error, StackTrace? stackTrace, String? tag}); 15 | } -------------------------------------------------------------------------------- /lib/src/ulog_console_adapter.dart: -------------------------------------------------------------------------------- 1 | 2 | import 'package:flutter_ulog/src/ulog.dart'; 3 | import 'package:flutter_ulog/src/ulog_lib_console_format_strategy.dart'; 4 | 5 | import 'i_ulog_adapter.dart'; 6 | import 'i_ulog_format_strategy.dart'; 7 | 8 | abstract class ULogConsoleAdapter implements ULogAdapter { 9 | final ULogFormatStrategy _formatStrategy; 10 | ULogConsoleAdapter({ULogFormatStrategy? formatStrategy}):_formatStrategy = formatStrategy?? ULogLibConsoleFormatStrategy(); 11 | 12 | @override 13 | bool isLoggable(ULogType type, String? tag) => true; 14 | 15 | @override 16 | void log(ULogType type, String? tag, String? message) { 17 | _formatStrategy.log(type, tag, message); 18 | } 19 | 20 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 zhonghua 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /lib/src/ansi_color.dart: -------------------------------------------------------------------------------- 1 | /// This class handles colorizing of terminal output. 2 | class AnsiColor { 3 | /// ANSI Control Sequence Introducer, signals the terminal for new settings. 4 | static const ansiEsc = '\x1B['; 5 | 6 | /// Reset all colors and options for current SGRs to terminal defaults. 7 | static const ansiDefault = '${ansiEsc}0m'; 8 | 9 | final int? fg; 10 | final int? bg; 11 | final bool color; 12 | 13 | AnsiColor.none() 14 | : fg = null, 15 | bg = null, 16 | color = false; 17 | 18 | AnsiColor.fg(this.fg) 19 | : bg = null, 20 | color = true; 21 | 22 | AnsiColor.bg(this.bg) 23 | : fg = null, 24 | color = true; 25 | 26 | @override 27 | String toString() { 28 | if (fg != null) { 29 | return '${ansiEsc}38;5;${fg}m'; 30 | } else if (bg != null) { 31 | return '${ansiEsc}48;5;${bg}m'; 32 | } else { 33 | return ''; 34 | } 35 | } 36 | 37 | String call(String msg) { 38 | if (color) { 39 | return '${this}$msg$ansiDefault'; 40 | } else { 41 | return msg; 42 | } 43 | } 44 | 45 | AnsiColor toFg() => AnsiColor.fg(bg); 46 | 47 | AnsiColor toBg() => AnsiColor.bg(fg); 48 | 49 | /// Defaults the terminal's foreground color without altering the background. 50 | String get resetForeground => color ? '${ansiEsc}39m' : ''; 51 | 52 | /// Defaults the terminal's background color without altering the foreground. 53 | String get resetBackground => color ? '${ansiEsc}49m' : ''; 54 | 55 | static int grey(double level) => 232 + (level.clamp(0.0, 1.0) * 23).round(); 56 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # The .vscode folder contains launch configuration and tasks you configure in 19 | # VS Code which you may wish to be included in version control, so this line 20 | # is commented out by default. 21 | #.vscode/ 22 | 23 | # Flutter/Dart/Pub related 24 | **/doc/api/ 25 | .dart_tool/ 26 | .flutter-plugins 27 | .flutter-plugins-dependencies 28 | .packages 29 | .pub-cache/ 30 | .pub/ 31 | build/ 32 | 33 | # Android related 34 | **/android/**/gradle-wrapper.jar 35 | **/android/.gradle 36 | **/android/captures/ 37 | **/android/gradlew 38 | **/android/gradlew.bat 39 | **/android/local.properties 40 | **/android/**/GeneratedPluginRegistrant.java 41 | 42 | # iOS/XCode related 43 | **/ios/**/*.mode1v3 44 | **/ios/**/*.mode2v3 45 | **/ios/**/*.moved-aside 46 | **/ios/**/*.pbxuser 47 | **/ios/**/*.perspectivev3 48 | **/ios/**/*sync/ 49 | **/ios/**/.sconsign.dblite 50 | **/ios/**/.tags* 51 | **/ios/**/.vagrant/ 52 | **/ios/**/DerivedData/ 53 | **/ios/**/Icon? 54 | **/ios/**/Pods/ 55 | **/ios/**/.symlinks/ 56 | **/ios/**/profile 57 | **/ios/**/xcuserdata 58 | **/ios/.generated/ 59 | **/ios/Flutter/App.framework 60 | **/ios/Flutter/Flutter.framework 61 | **/ios/Flutter/Flutter.podspec 62 | **/ios/Flutter/Generated.xcconfig 63 | **/ios/Flutter/ephemeral 64 | **/ios/Flutter/app.flx 65 | **/ios/Flutter/app.zip 66 | **/ios/Flutter/flutter_assets/ 67 | **/ios/Flutter/flutter_export_environment.sh 68 | **/ios/ServiceDefinitions.json 69 | **/ios/Runner/GeneratedPluginRegistrant.* 70 | 71 | # Exceptions to above rules. 72 | !**/ios/**/default.mode1v3 73 | !**/ios/**/default.mode2v3 74 | !**/ios/**/default.pbxuser 75 | !**/ios/**/default.perspectivev3 76 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: flutter_ulog 2 | description: Flutter log lib 3 | version: 0.0.5 4 | homepage: https://github.com/smartbackme/ulog 5 | 6 | environment: 7 | sdk: ">=2.12.0 <3.0.0" 8 | flutter: ">=1.17.0" 9 | 10 | dependencies: 11 | flutter: 12 | sdk: flutter 13 | 14 | dev_dependencies: 15 | flutter_test: 16 | sdk: flutter 17 | # json_annotation: ^4.0.1 18 | # build_runner: any 19 | # json_serializable: any 20 | # For information on the generic Dart part of this file, see the 21 | # following page: https://dart.dev/tools/pub/pubspec 22 | 23 | # The following section is specific to Flutter. 24 | flutter: 25 | 26 | # To add assets to your package, add an assets section, like this: 27 | # assets: 28 | # - images/a_dot_burr.jpeg 29 | # - images/a_dot_ham.jpeg 30 | # 31 | # For details regarding assets in packages, see 32 | # https://flutter.dev/assets-and-images/#from-packages 33 | # 34 | # An image asset can refer to one or more resolution-specific "variants", see 35 | # https://flutter.dev/assets-and-images/#resolution-aware. 36 | 37 | # To add custom fonts to your package, add a fonts section here, 38 | # in this "flutter" section. Each entry in this list should have a 39 | # "family" key with the font family name, and a "fonts" key with a 40 | # list giving the asset and other descriptors for the font. For 41 | # example: 42 | # fonts: 43 | # - family: Schyler 44 | # fonts: 45 | # - asset: fonts/Schyler-Regular.ttf 46 | # - asset: fonts/Schyler-Italic.ttf 47 | # style: italic 48 | # - family: Trajan Pro 49 | # fonts: 50 | # - asset: fonts/TrajanPro.ttf 51 | # - asset: fonts/TrajanPro_Bold.ttf 52 | # weight: 700 53 | # 54 | # For details regarding fonts in packages, see 55 | # https://flutter.dev/custom-fonts/#from-packages 56 | -------------------------------------------------------------------------------- /lib/src/ulog.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | 4 | import 'i_ulog_adapter.dart'; 5 | import 'i_ulog_printer.dart'; 6 | import 'ulog_lib_printer.dart'; 7 | 8 | enum ULogType{ 9 | verbose, 10 | debug, 11 | info, 12 | warning, 13 | error 14 | } 15 | 16 | // typedef String? toJson(dynamic src); 17 | 18 | class ULog{ 19 | 20 | static ULogPrinter printer = ULogLibPrinter(); 21 | 22 | 23 | // static toJson? tojson; 24 | // 25 | // static void init(toJson? tojsonfun){ 26 | // tojson = tojsonfun; 27 | // } 28 | 29 | static void addLogAdapter(ULogAdapter adapter) { 30 | printer.addAdapter(adapter); 31 | } 32 | 33 | static void clearLogAdapters() { 34 | printer.clearLogAdapters(); 35 | } 36 | 37 | static void removeLogAdapters(ULogAdapter adapter) { 38 | printer.removeLogAdapters(adapter); 39 | } 40 | 41 | /// Log a message at level [ULogType.verbose]. 42 | static void v(dynamic message,{dynamic error, StackTrace? stackTrace, String? tag}){ 43 | _log(ULogType.verbose,message,error :error,tag: tag,stackTrace: stackTrace); 44 | } 45 | 46 | /// Log a message at level [ULogType.debug]. 47 | static void d(dynamic message,{dynamic error, StackTrace? stackTrace, String? tag}){ 48 | _log(ULogType.debug,message,error :error,tag: tag,stackTrace: stackTrace); 49 | } 50 | 51 | /// Log a message at level [ULogType.info]. 52 | static void i(dynamic message,{dynamic error, StackTrace? stackTrace, String? tag}){ 53 | _log(ULogType.info,message,error :error,tag: tag,stackTrace: stackTrace); 54 | } 55 | 56 | /// Log a message at level [ULogType.warning]. 57 | static void w(dynamic message,{dynamic error, StackTrace? stackTrace, String? tag}){ 58 | _log(ULogType.warning,message,error :error,tag: tag,stackTrace: stackTrace); 59 | } 60 | 61 | /// Log a message at level [ULogType.error]. 62 | static void e(dynamic message,{dynamic error, StackTrace? stackTrace, String? tag}){ 63 | _log(ULogType.error,message,error :error,tag: tag,stackTrace: stackTrace); 64 | } 65 | 66 | static void json(String json,{String? tag}) { 67 | printer.json(json,tag: tag); 68 | } 69 | 70 | // static void xml(String xml,{String? tag}) { 71 | // printer.xml(xml,tag:tag); 72 | // } 73 | 74 | // static void o(dynamic obj,{String? tag}) { 75 | // printer.o(obj,tag: tag); 76 | // } 77 | 78 | 79 | static void _log(ULogType type,dynamic message,{dynamic error, StackTrace? stackTrace, String? tag}){ 80 | printer.log(type,message,error: error,tag: tag,stackTrace: stackTrace); 81 | } 82 | 83 | } -------------------------------------------------------------------------------- /lib/src/ulog_utils.dart: -------------------------------------------------------------------------------- 1 | 2 | class ULogUtils{ 3 | 4 | /// Matches a stacktrace line as generated on Android/iOS devices. 5 | /// For example: 6 | /// #1 Logger.log (package:logger/src/logger.dart:115:29) 7 | static final _deviceStackTraceRegex = 8 | RegExp(r'#[0-9]+[\s]+(.+) \(([^\s]+)\)'); 9 | 10 | /// Matches a stacktrace line as generated by Flutter web. 11 | /// For example: 12 | /// packages/logger/src/printers/pretty_printer.dart 91:37 13 | static final _webStackTraceRegex = 14 | RegExp(r'^((packages|dart-sdk)\/[^\s]+\/)'); 15 | 16 | /// Matches a stacktrace line as generated by browser Dart. 17 | /// For example: 18 | /// dart:sdk_internal 19 | /// package:logger/src/logger.dart 20 | static final _browserStackTraceRegex = 21 | RegExp(r'^(?:package:)?(dart:[^\s]+|[^\s]+)'); 22 | 23 | static final ignorePackage = "flutter_ulog"; 24 | 25 | static List cropStackTrace(StackTrace stackTrace,int maxDepth){ 26 | var stack = getRealStackTrack(stackTrace); 27 | 28 | var realDepth = stack.length; 29 | if (maxDepth > 0) { 30 | realDepth = realDepth getRealStackTrack(StackTrace stackTrace){ 37 | var count = 0; 38 | var formatted = []; 39 | var stack = stackTrace.toString(); 40 | for (var line in stack.split('\n')) { 41 | if (_discardDeviceStacktraceLine(line) || 42 | _discardWebStacktraceLine(line) || 43 | _discardBrowserStacktraceLine(line) || 44 | line.isEmpty) { 45 | continue; 46 | } 47 | formatted.add('#$count ${line.replaceFirst(RegExp(r'#\d+\s+'), '')}'); 48 | count++; 49 | } 50 | return formatted; 51 | } 52 | 53 | static bool _discardDeviceStacktraceLine(String line) { 54 | var match = _deviceStackTraceRegex.matchAsPrefix(line); 55 | if (match == null) { 56 | return false; 57 | } 58 | return match.group(2)!.startsWith('package:$ignorePackage'); 59 | } 60 | static bool _discardWebStacktraceLine(String line) { 61 | var match = _webStackTraceRegex.matchAsPrefix(line); 62 | if (match == null) { 63 | return false; 64 | } 65 | return match.group(1)!.startsWith('packages/$ignorePackage') 66 | || match.group(1)!.startsWith('dart-sdk/lib'); 67 | } 68 | 69 | static bool _discardBrowserStacktraceLine(String line) { 70 | var match = _browserStackTraceRegex.matchAsPrefix(line); 71 | if (match == null) { 72 | return false; 73 | } 74 | return match.group(1)!.startsWith('package:$ignorePackage') 75 | || match.group(1)!.startsWith('dart:'); 76 | } 77 | } -------------------------------------------------------------------------------- /pubspec.lock: -------------------------------------------------------------------------------- 1 | # Generated by pub 2 | # See https://dart.dev/tools/pub/glossary#lockfile 3 | packages: 4 | async: 5 | dependency: transitive 6 | description: 7 | name: async 8 | url: "https://pub.flutter-io.cn" 9 | source: hosted 10 | version: "2.6.1" 11 | boolean_selector: 12 | dependency: transitive 13 | description: 14 | name: boolean_selector 15 | url: "https://pub.flutter-io.cn" 16 | source: hosted 17 | version: "2.1.0" 18 | characters: 19 | dependency: transitive 20 | description: 21 | name: characters 22 | url: "https://pub.flutter-io.cn" 23 | source: hosted 24 | version: "1.1.0" 25 | charcode: 26 | dependency: transitive 27 | description: 28 | name: charcode 29 | url: "https://pub.flutter-io.cn" 30 | source: hosted 31 | version: "1.2.0" 32 | clock: 33 | dependency: transitive 34 | description: 35 | name: clock 36 | url: "https://pub.flutter-io.cn" 37 | source: hosted 38 | version: "1.1.0" 39 | collection: 40 | dependency: transitive 41 | description: 42 | name: collection 43 | url: "https://pub.flutter-io.cn" 44 | source: hosted 45 | version: "1.15.0" 46 | fake_async: 47 | dependency: transitive 48 | description: 49 | name: fake_async 50 | url: "https://pub.flutter-io.cn" 51 | source: hosted 52 | version: "1.2.0" 53 | flutter: 54 | dependency: "direct main" 55 | description: flutter 56 | source: sdk 57 | version: "0.0.0" 58 | flutter_test: 59 | dependency: "direct dev" 60 | description: flutter 61 | source: sdk 62 | version: "0.0.0" 63 | matcher: 64 | dependency: transitive 65 | description: 66 | name: matcher 67 | url: "https://pub.flutter-io.cn" 68 | source: hosted 69 | version: "0.12.10" 70 | meta: 71 | dependency: transitive 72 | description: 73 | name: meta 74 | url: "https://pub.flutter-io.cn" 75 | source: hosted 76 | version: "1.3.0" 77 | path: 78 | dependency: transitive 79 | description: 80 | name: path 81 | url: "https://pub.flutter-io.cn" 82 | source: hosted 83 | version: "1.8.0" 84 | sky_engine: 85 | dependency: transitive 86 | description: flutter 87 | source: sdk 88 | version: "0.0.99" 89 | source_span: 90 | dependency: transitive 91 | description: 92 | name: source_span 93 | url: "https://pub.flutter-io.cn" 94 | source: hosted 95 | version: "1.8.1" 96 | stack_trace: 97 | dependency: transitive 98 | description: 99 | name: stack_trace 100 | url: "https://pub.flutter-io.cn" 101 | source: hosted 102 | version: "1.10.0" 103 | stream_channel: 104 | dependency: transitive 105 | description: 106 | name: stream_channel 107 | url: "https://pub.flutter-io.cn" 108 | source: hosted 109 | version: "2.1.0" 110 | string_scanner: 111 | dependency: transitive 112 | description: 113 | name: string_scanner 114 | url: "https://pub.flutter-io.cn" 115 | source: hosted 116 | version: "1.1.0" 117 | term_glyph: 118 | dependency: transitive 119 | description: 120 | name: term_glyph 121 | url: "https://pub.flutter-io.cn" 122 | source: hosted 123 | version: "1.2.0" 124 | test_api: 125 | dependency: transitive 126 | description: 127 | name: test_api 128 | url: "https://pub.flutter-io.cn" 129 | source: hosted 130 | version: "0.3.0" 131 | typed_data: 132 | dependency: transitive 133 | description: 134 | name: typed_data 135 | url: "https://pub.flutter-io.cn" 136 | source: hosted 137 | version: "1.3.0" 138 | vector_math: 139 | dependency: transitive 140 | description: 141 | name: vector_math 142 | url: "https://pub.flutter-io.cn" 143 | source: hosted 144 | version: "2.1.0" 145 | sdks: 146 | dart: ">=2.12.0 <3.0.0" 147 | flutter: ">=1.17.0" 148 | -------------------------------------------------------------------------------- /lib/src/ulog_lib_printer.dart: -------------------------------------------------------------------------------- 1 | 2 | import 'dart:convert'; 3 | 4 | import 'package:flutter_ulog/src/i_ulog_adapter.dart'; 5 | import 'package:flutter_ulog/src/ulog.dart'; 6 | 7 | import 'i_ulog_printer.dart'; 8 | 9 | class ULogLibPrinter implements ULogPrinter{ 10 | static const JSON_INDENT = 1; 11 | String getDeepSpace(int deep) { 12 | var tab = StringBuffer(); 13 | for (int i = 0; i < deep; i++) { 14 | tab.write("\t"); 15 | } 16 | return tab.toString(); 17 | } 18 | List _logAdapters = []; 19 | 20 | @override 21 | void addAdapter(ULogAdapter adapter) { 22 | if(!_logAdapters.contains(adapter)){ 23 | _logAdapters.add(adapter); 24 | } 25 | } 26 | 27 | @override 28 | void clearLogAdapters() { 29 | _logAdapters.clear(); 30 | } 31 | 32 | @override 33 | void json(String json, { String? tag}) { 34 | if (json.isEmpty) { 35 | log(ULogType.debug, "Empty/Null json content",tag: tag); 36 | }else{ 37 | var j = json.trim(); 38 | if (j.startsWith("{")) { 39 | Map decode = JsonCodec().decode(json); 40 | log(ULogType.debug, _convert(decode, JSON_INDENT),tag: tag); 41 | } 42 | if (j.startsWith("[")) { 43 | List decode = JsonCodec().decode(json); 44 | log(ULogType.debug, _convert(decode, JSON_INDENT,isObject: true),tag: tag); 45 | } 46 | } 47 | } 48 | 49 | 50 | /// [object] 解析的对象 51 | /// [deep] 递归的深度,用来获取缩进的空白长度 52 | /// [isObject] 用来区分当前map或list是不是来自某个字段,则不用显示缩进。单纯的map或list需要添加缩进 53 | String _convert(dynamic object, int deep, {bool isObject = false}) { 54 | var buffer = StringBuffer(); 55 | var nextDeep = deep + 1; 56 | if (object is Map) { 57 | var list = object.keys.toList(); 58 | if (!isObject) {//如果map来自某个字段,则不需要显示缩进 59 | buffer.write("${getDeepSpace(deep)}"); 60 | } 61 | buffer.write("{"); 62 | if (list.isEmpty) {//当map为空,直接返回‘}’ 63 | buffer.write("}"); 64 | }else { 65 | buffer.write("\n"); 66 | for (int i = 0; i < list.length; i++) { 67 | buffer.write("${getDeepSpace(nextDeep)}\"${list[i]}\":"); 68 | buffer.write(_convert(object[list[i]], nextDeep, isObject: true)); 69 | if (i < list.length - 1) { 70 | buffer.write(","); 71 | buffer.write("\n"); 72 | } 73 | } 74 | buffer.write("\n"); 75 | buffer.write("${getDeepSpace(deep)}}"); 76 | } 77 | } else if (object is List) { 78 | if (!isObject) {//如果list来自某个字段,则不需要显示缩进 79 | buffer.write("${getDeepSpace(deep)}"); 80 | } 81 | buffer.write("["); 82 | if (object.isEmpty) {//当list为空,直接返回‘]’ 83 | buffer.write("]"); 84 | }else { 85 | buffer.write("\n"); 86 | for (int i = 0; i < object.length; i++) { 87 | buffer.write(_convert(object[i], nextDeep)); 88 | if (i < object.length - 1) { 89 | buffer.write(","); 90 | buffer.write("\n"); 91 | } 92 | } 93 | buffer.write("\n"); 94 | buffer.write("${getDeepSpace(deep)}]"); 95 | } 96 | } else if (object is String) {//为字符串时,需要添加双引号并返回当前内容 97 | buffer.write("\"$object\""); 98 | } else if (object is num || object is bool) {//为数字或者布尔值时,返回当前内容 99 | buffer.write(object); 100 | } else {//如果对象为空,则返回null字符串 101 | buffer.write("null"); 102 | } 103 | return buffer.toString(); 104 | } 105 | 106 | @override 107 | void log(ULogType type, message, {error, StackTrace? stackTrace, String? tag}) { 108 | var msg = stringifyMessage(message); 109 | var emsg = ""; 110 | if(error!=null){ 111 | emsg = '\n${error.toString()}'; 112 | } 113 | var stmsg = ""; 114 | if(stackTrace!=null){ 115 | stmsg = '\n${stackTrace.toString()}'; 116 | } 117 | var str = msg + emsg + stmsg; 118 | _logAdapters.forEach((element) { 119 | if(element.isLoggable(type, tag)){ 120 | element.log(type,tag,str.toString()); 121 | } 122 | }); 123 | 124 | } 125 | 126 | // Handles any object that is causing JsonEncoder() problems 127 | Object toEncodableFallback(dynamic object) { 128 | return object.toString(); 129 | } 130 | 131 | String stringifyMessage(dynamic message) { 132 | final finalMessage = message is Function ? message() : message; 133 | if (finalMessage is Map || finalMessage is Iterable) { 134 | var encoder = JsonEncoder.withIndent(' ', toEncodableFallback); 135 | return encoder.convert(finalMessage); 136 | } else { 137 | return finalMessage.toString(); 138 | } 139 | } 140 | 141 | // @override 142 | // void o(obj, { String? tag}) { 143 | // assert(ULog.tojson != null); 144 | // json(ULog.tojson!(obj)??"",tag: tag); 145 | // } 146 | 147 | @override 148 | void removeLogAdapters(ULogAdapter adapter) { 149 | _logAdapters.remove(adapter); 150 | } 151 | 152 | 153 | } -------------------------------------------------------------------------------- /lib/src/ulog_lib_console_format_strategy.dart: -------------------------------------------------------------------------------- 1 | 2 | import 'dart:convert'; 3 | 4 | import 'package:flutter_ulog/src/ulog.dart'; 5 | import 'package:flutter_ulog/src/ulog_utils.dart'; 6 | 7 | import 'ansi_color.dart'; 8 | import 'i_ulog_format_strategy.dart'; 9 | 10 | class ULogLibConfig{ 11 | final int _stackDeep ; 12 | final String _tag ; 13 | ULogLibConfig(ULogLibConfigBuilder builder): _stackDeep = builder._stackDeep,_tag = builder._tag; 14 | } 15 | 16 | class ULogLibConfigBuilder { 17 | int _stackDeep = 2; 18 | String _tag = "LIB-LOG"; 19 | 20 | ULogLibConfigBuilder setStackDeep(int stackDeep){ 21 | _stackDeep = stackDeep; 22 | return this; 23 | } 24 | 25 | ULogLibConfigBuilder setTag(String tag){ 26 | _tag = tag; 27 | return this; 28 | } 29 | 30 | ULogLibConfig build() => ULogLibConfig(this); 31 | } 32 | 33 | class ULogLibConsoleFormatStrategy implements ULogFormatStrategy{ 34 | 35 | ///绘图工具箱 36 | static const topLeftCorner = '┌'; 37 | static const bottomLeftCorner = '└'; 38 | static const middleCorner = '├'; 39 | static const verticalLine = '│'; 40 | static const doubleDivider = '────────────────────────────────────────────────────────'; 41 | static const singleDivider = '┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄'; 42 | String _topBorder = '$topLeftCorner$doubleDivider$doubleDivider'; 43 | String _middleBorder = '$middleCorner$singleDivider$singleDivider'; 44 | String _bottomBorder = '$bottomLeftCorner$doubleDivider$doubleDivider'; 45 | 46 | static final typeColors = { 47 | ULogType.verbose: AnsiColor.fg(AnsiColor.grey(0.5)), 48 | ULogType.debug: AnsiColor.none(), 49 | ULogType.info: AnsiColor.fg(12), 50 | ULogType.warning: AnsiColor.fg(208), 51 | ULogType.error: AnsiColor.fg(196), 52 | }; 53 | 54 | static final typeEmojis = { 55 | ULogType.verbose: '', 56 | ULogType.debug: '🐛', 57 | ULogType.info: '💡', 58 | ULogType.warning: '⚠', 59 | ULogType.error: '⛔', 60 | }; 61 | 62 | ///一行最大字符数4000 63 | static const chunkSize = 4000; 64 | 65 | ULogLibConfig config = ULogLibConfigBuilder().build(); 66 | 67 | @override 68 | void log(ULogType type, String? onceOnlyTag, String? message) { 69 | var time = getTime(); 70 | var tag = _formatTag(onceOnlyTag); 71 | _logTopBorder(type, tag,time); 72 | _logHeaderContent(type, tag ,time); 73 | // List bytes = utf8.encode(message!); 74 | // var length = bytes.length; 75 | var length = message!.length; 76 | if (length <= chunkSize) { 77 | if (config._stackDeep > 0) { 78 | _logDivider(type, tag,time); 79 | } 80 | _logContent(type, tag,time, message); 81 | _logBottomBorder(type, tag,time); 82 | }else{ 83 | if (config._stackDeep > 0) { 84 | _logDivider(type, tag,time); 85 | } 86 | for (int i = 0; i < length; i += chunkSize) { 87 | int count = (length - i)0){ 104 | var stack = ULogUtils.cropStackTrace(StackTrace.current,config._stackDeep); 105 | var level = ""; 106 | 107 | for (var s in stack){ 108 | _logChunk(type, tag, time,'$verticalLine$level$s'); 109 | level += " "; 110 | } 111 | } 112 | } 113 | 114 | ///绘制顶线 115 | void _logTopBorder(ULogType type, String tag, String time) { 116 | _logChunk(type, tag, time,_topBorder); 117 | } 118 | 119 | ///绘制内容 120 | void _logContent(ULogType type, String tag, String time, String chunk) { 121 | for (var line in chunk.split('\n')) { 122 | _logChunk(type, tag, time, "$verticalLine $line"); 123 | } 124 | } 125 | 126 | ///绘制底线 127 | void _logBottomBorder(ULogType type, String tag, String time) { 128 | _logChunk(type, tag, time,_bottomBorder); 129 | } 130 | 131 | ///绘制分割线 132 | void _logDivider(ULogType type, String tag, String time) { 133 | _logChunk(type, tag, time,_middleBorder); 134 | } 135 | 136 | ///打印 137 | void _logChunk(ULogType type, String tag, String time, String message) { 138 | print(typeColors[type]!.call('${typeEmojis[type]}$time$verticalLine$tag $message')); 139 | } 140 | 141 | String getTime() { 142 | String _threeDigits(int n) { 143 | if (n >= 100) return '$n'; 144 | if (n >= 10) return '0$n'; 145 | return '00$n'; 146 | } 147 | 148 | String _twoDigits(int n) { 149 | if (n >= 10) return '$n'; 150 | return '0$n'; 151 | } 152 | 153 | var now = DateTime.now(); 154 | var h = _twoDigits(now.hour); 155 | var min = _twoDigits(now.minute); 156 | var sec = _twoDigits(now.second); 157 | var ms = _threeDigits(now.millisecond); 158 | return '$h:$min:$sec.$ms'; 159 | } 160 | 161 | } 162 | 163 | -------------------------------------------------------------------------------- /test/flutter_ulog_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:flutter_test/flutter_test.dart'; 4 | import 'package:flutter_ulog/src/i_ulog_format_strategy.dart'; 5 | import 'package:flutter_ulog/src/ulog.dart'; 6 | import 'package:flutter_ulog/src/ulog_console_adapter.dart'; 7 | 8 | 9 | class consoleAdapter extends ULogConsoleAdapter{ 10 | @override 11 | bool isLoggable(ULogType type, String? tag) => true; 12 | } 13 | // 14 | // // user.g.dart 将在我们运行生成命令后自动生成 15 | // part 'flutter_ulog_test.g.dart'; 16 | // 17 | // ///这个标注是告诉生成器,这个类是需要生成Model类的 18 | // @JsonSerializable() 19 | // class User{ 20 | // User(this.name, this.email); 21 | // 22 | // String name; 23 | // String email; 24 | // //不同的类使用不同的mixin即可 25 | // factory User.fromJson(Map json) => _$UserFromJson(json); 26 | // Map toJson() => _$UserToJson(this); 27 | // } 28 | 29 | 30 | // Handles any object that is causing JsonEncoder() problems 31 | Object toEncodableFallback(dynamic object) { 32 | return object.toString(); 33 | } 34 | void main() { 35 | test('adds one to input values', () { 36 | // ULog.init((value){ 37 | // return ; 38 | // }); 39 | ULog.addLogAdapter(consoleAdapter()); 40 | ULog.v("12321321\ndfafdasfdsa\ndafdasf"); 41 | ULog.d("12321321"); 42 | ULog.i("12321321"); 43 | ULog.w("12321321"); 44 | ULog.e("1321231",error: NullThrownError()); 45 | var map = []; 46 | map.add("1232"); 47 | map.add("1232"); 48 | map.add("1232"); 49 | map.add("1232"); 50 | ULog.e(map,error: NullThrownError()); 51 | ULog.json(''' 52 | { 53 | "a1": "value", 54 | "a2": 42, 55 | "bs": [ 56 | { 57 | "b1": "any value", 58 | "b2": 13 59 | }, 60 | { 61 | "b1": "another value", 62 | "b2": 0 63 | } 64 | ] 65 | } 66 | '''); 67 | 68 | // ULog.o(User("123","123")); 69 | ULog.e("1321231",error: NullThrownError(),tag: "12312"); 70 | ULog.e("123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321"); 71 | try { 72 | throw StateError('This is a Dart exception.'); 73 | } catch (e, stack) { 74 | ULog.e("1321231",error: e , stackTrace: stack,tag: "12312"); 75 | 76 | } 77 | 78 | 79 | }); 80 | } 81 | -------------------------------------------------------------------------------- /README-zh.md: -------------------------------------------------------------------------------- 1 | # ULog 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 模仿 Android logger库 [logger](https://github.com/orhanobut/logger) 11 | 12 | 13 | ## 开始使用 14 | 15 | 16 | 17 | 18 | ```dart 19 | dependencies: 20 | flutter_ulog: ^0.0.5 21 | // 初始化 22 | class ConsoleAdapter extends ULogConsoleAdapter{ 23 | @override 24 | bool isLoggable(ULogType type, String? tag) => true; 25 | } 26 | // 添加日志适配器,可以继承该适配器,来达到不同情况下打印不同内容 27 | ULog.addLogAdapter(ULogConsoleAdapter()); 28 | ``` 29 | 30 | 31 | 32 | ## Output 33 | 34 | 日常打印 35 | ![](art/base_image.png) 36 | 37 | ![](art/base_image2.png) 38 | 39 | 一行超过4000字符自动折行 40 | ![](art/base_image3.png) 41 | 42 | ## 日志等级 43 | 44 | 45 | ```dart 46 | ULog.v("12321321\ndfafdasfdsa\ndafdasf"); 47 | ULog.d("12321321"); 48 | ULog.i("12321321"); 49 | ULog.w("12321321"); 50 | ULog.e("1321231",error: NullThrownError()); 51 | var map = []; 52 | map.add("1232"); 53 | map.add("1232"); 54 | map.add("1232"); 55 | map.add("1232"); 56 | ULog.e(map,error: NullThrownError()); 57 | ULog.json(''' 58 | { 59 | "a1": "value", 60 | "a2": 42, 61 | "bs": [ 62 | { 63 | "b1": "any value", 64 | "b2": 13 65 | }, 66 | { 67 | "b1": "another value", 68 | "b2": 0 69 | } 70 | ] 71 | } 72 | '''); 73 | 74 | // ULog.o(User("123","123")); 75 | ULog.e("1321231",error: NullThrownError(),tag: "12312"); 76 | ULog.e("123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321"); 77 | 78 | ``` -------------------------------------------------------------------------------- /README-jp.md: -------------------------------------------------------------------------------- 1 | # ULog 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 模倣 Android logger [logger](https://github.com/orhanobut/logger) 11 | 12 | 13 | ## 使用を開始する 14 | 15 | 16 | 17 | ```dart 18 | dependencies: 19 | flutter_ulog: ^0.0.5 20 | // 初期化 21 | class ConsoleAdapter extends ULogConsoleAdapter{ 22 | @override 23 | bool isLoggable(ULogType type, String? tag) => true; 24 | } 25 | // ログアダプタを追加すると、このアダプターを引き継ぎ、異なる場合には異なる内容を印刷することができます。 26 | ULog.addLogAdapter(ConsoleAdapter()); 27 | ``` 28 | 29 | 30 | 31 | ## Output 32 | 33 | 日常印刷 34 | ![](art/base_image.png) 35 | 36 | ![](art/base_image2.png) 37 | 38 | 行が4000文字を超えると自動的に行を折ります。 39 | ![](art/base_image3.png) 40 | 41 | ## レベル 42 | 43 | 44 | ```dart 45 | ULog.v("12321321\ndfafdasfdsa\ndafdasf"); 46 | ULog.d("12321321"); 47 | ULog.i("12321321"); 48 | ULog.w("12321321"); 49 | ULog.e("1321231",error: NullThrownError()); 50 | var map = []; 51 | map.add("1232"); 52 | map.add("1232"); 53 | map.add("1232"); 54 | map.add("1232"); 55 | ULog.e(map,error: NullThrownError()); 56 | ULog.json(''' 57 | { 58 | "a1": "value", 59 | "a2": 42, 60 | "bs": [ 61 | { 62 | "b1": "any value", 63 | "b2": 13 64 | }, 65 | { 66 | "b1": "another value", 67 | "b2": 0 68 | } 69 | ] 70 | } 71 | '''); 72 | 73 | // ULog.o(User("123","123")); 74 | ULog.e("1321231",error: NullThrownError(),tag: "12312"); 75 | ULog.e("123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321"); 76 | 77 | ``` -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ULog 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Imitate Android logger library [logger](https://github.com/orhanobut/logger) 11 | 12 | 13 | 14 | ## start using 15 | 16 | 17 | 18 | ```dart 19 | dependencies: 20 | flutter_ulog: ^0.0.5 21 | //Initialization 22 | class ConsoleAdapter extends ULogConsoleAdapter{ 23 | @override 24 | bool isLoggable(ULogType type, String? tag) => true; 25 | } 26 | //Add a log adapter, which can be inherited to print different contents under different circumstances 27 | ULog.addLogAdapter(ConsoleAdapter()); 28 | ``` 29 | 30 | 31 | 32 | ## Output 33 | 34 | Daily printing 35 | ![](art/base_image.png) 36 | 37 | ![](art/base_image2.png) 38 | 39 | If a line exceeds 4000 characters, it will be automatically folded 40 | ![](art/base_image3.png) 41 | 42 | ## Log level 43 | 44 | 45 | ```dart 46 | ULog.v("12321321\ndfafdasfdsa\ndafdasf"); 47 | ULog.d("12321321"); 48 | ULog.i("12321321"); 49 | ULog.w("12321321"); 50 | ULog.e("1321231",error: NullThrownError()); 51 | var map = []; 52 | map.add("1232"); 53 | map.add("1232"); 54 | map.add("1232"); 55 | map.add("1232"); 56 | ULog.e(map,error: NullThrownError()); 57 | ULog.json(''' 58 | { 59 | "a1": "value", 60 | "a2": 42, 61 | "bs": [ 62 | { 63 | "b1": "any value", 64 | "b2": 13 65 | }, 66 | { 67 | "b1": "another value", 68 | "b2": 0 69 | } 70 | ] 71 | } 72 | '''); 73 | 74 | // ULog.o(User("123","123")); 75 | ULog.e("1321231",error: NullThrownError(),tag: "12312"); 76 | ULog.e("123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321123213211232132112321321"); 77 | 78 | ``` --------------------------------------------------------------------------------