improvement of logging, replaced print method for developer.log
Showing
2 changed files
with
13 additions
and
10 deletions
1 | import 'package:get/instance_manager.dart'; | 1 | import 'package:get/instance_manager.dart'; |
2 | +import 'dart:developer' as developer; | ||
2 | 3 | ||
3 | -typedef LogWriterCallback = void Function(String text, {bool isError}); | 4 | +typedef LogWriterCallback = void Function(String text, {String name, bool isError}); |
4 | 5 | ||
5 | -void defaultLogWriterCallback(String value, {bool isError = false}) { | ||
6 | - if (isError || GetConfig.isLogEnable) print(value); | 6 | +void defaultLogWriterCallback(String value, {String name, bool isError = false}) { |
7 | + if (isError || GetConfig.isLogEnable) developer.log(value, name: name); | ||
7 | } | 8 | } |
1 | +import 'package:flutter/cupertino.dart'; | ||
1 | import 'package:get/src/core/log.dart'; | 2 | import 'package:get/src/core/log.dart'; |
2 | import 'package:get/src/navigation/root/smart_management.dart'; | 3 | import 'package:get/src/navigation/root/smart_management.dart'; |
3 | import 'package:get/src/state_manager/rx/rx_interface.dart'; | 4 | import 'package:get/src/state_manager/rx/rx_interface.dart'; |
@@ -127,7 +128,7 @@ class GetInstance { | @@ -127,7 +128,7 @@ class GetInstance { | ||
127 | 128 | ||
128 | if (i is DisposableInterface) { | 129 | if (i is DisposableInterface) { |
129 | i.onStart(); | 130 | i.onStart(); |
130 | - GetConfig.log('[GETX] $key has been initialized'); | 131 | + GetConfig.log('$key has been initialized', name: '[GETX]'); |
131 | } | 132 | } |
132 | } | 133 | } |
133 | 134 | ||
@@ -172,7 +173,7 @@ class GetInstance { | @@ -172,7 +173,7 @@ class GetInstance { | ||
172 | if (!_factory.containsKey(key)) | 173 | if (!_factory.containsKey(key)) |
173 | throw " $S not found. You need call put<$S>($S()) before"; | 174 | throw " $S not found. You need call put<$S>($S()) before"; |
174 | 175 | ||
175 | - GetConfig.log('[GETX] $S instance was created at that time'); | 176 | + GetConfig.log('$S instance was created at that time', name: '[GETX]'); |
176 | S _value = put<S>(_factory[key].builder() as S); | 177 | S _value = put<S>(_factory[key].builder() as S); |
177 | 178 | ||
178 | initDependencies<S>(name: tag); | 179 | initDependencies<S>(name: tag); |
@@ -216,7 +217,7 @@ class GetInstance { | @@ -216,7 +217,7 @@ class GetInstance { | ||
216 | 217 | ||
217 | return queue.add<bool>(() async { | 218 | return queue.add<bool>(() async { |
218 | if (!_singl.containsKey(newKey)) { | 219 | if (!_singl.containsKey(newKey)) { |
219 | - GetConfig.log('[GETX] Instance $newKey already been removed.', | 220 | + GetConfig.log('Instance $newKey already been removed.', name: '[GETX]', |
220 | isError: true); | 221 | isError: true); |
221 | return false; | 222 | return false; |
222 | } | 223 | } |
@@ -224,7 +225,8 @@ class GetInstance { | @@ -224,7 +225,8 @@ class GetInstance { | ||
224 | FcBuilder builder = _singl[newKey] as FcBuilder; | 225 | FcBuilder builder = _singl[newKey] as FcBuilder; |
225 | if (builder.permanent && !force) { | 226 | if (builder.permanent && !force) { |
226 | GetConfig.log( | 227 | GetConfig.log( |
227 | - '[GETX] [$newKey] has been marked as permanent, SmartManagement is not authorized to delete it.', | 228 | + '[$newKey] has been marked as permanent, SmartManagement is not authorized to delete it.', |
229 | + name: '[GETX]', | ||
228 | isError: true); | 230 | isError: true); |
229 | return false; | 231 | return false; |
230 | } | 232 | } |
@@ -235,14 +237,14 @@ class GetInstance { | @@ -235,14 +237,14 @@ class GetInstance { | ||
235 | } | 237 | } |
236 | if (i is DisposableInterface) { | 238 | if (i is DisposableInterface) { |
237 | await i.onClose(); | 239 | await i.onClose(); |
238 | - GetConfig.log('[GETX] onClose of $newKey called'); | 240 | + GetConfig.log('onClose of $newKey called', name: '[GETX]'); |
239 | } | 241 | } |
240 | 242 | ||
241 | _singl.removeWhere((oldKey, value) => (oldKey == newKey)); | 243 | _singl.removeWhere((oldKey, value) => (oldKey == newKey)); |
242 | if (_singl.containsKey(newKey)) { | 244 | if (_singl.containsKey(newKey)) { |
243 | - GetConfig.log('[GETX] error on remove object $newKey', isError: true); | 245 | + GetConfig.log('error on remove object $newKey', name: '[GETX]', isError: true); |
244 | } else { | 246 | } else { |
245 | - GetConfig.log('[GETX] $newKey deleted from memory'); | 247 | + GetConfig.log('$newKey deleted from memory', name: '[GETX]'); |
246 | } | 248 | } |
247 | // _routesKey?.remove(key); | 249 | // _routesKey?.remove(key); |
248 | return true; | 250 | return true; |
-
Please register or login to post a comment