From 4bda23eaf9d9300b2b1b3908402ae9b82a78ce78 Mon Sep 17 00:00:00 2001 From: Aliaksei Tratseuski Date: Sun, 30 Jun 2024 18:49:07 +0400 Subject: [PATCH] fix: re-enabled dio logs (developer debug console) --- .../api_maps/rest_maps/rest_api_map.dart | 23 +++++++++++-------- lib/utils/app_logger.dart | 2 ++ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/logic/api_maps/rest_maps/rest_api_map.dart b/lib/logic/api_maps/rest_maps/rest_api_map.dart index 73c44c1e..3e06a803 100644 --- a/lib/logic/api_maps/rest_maps/rest_api_map.dart +++ b/lib/logic/api_maps/rest_maps/rest_api_map.dart @@ -4,7 +4,9 @@ import 'dart:io'; import 'package:dio/dio.dart'; import 'package:dio/io.dart'; -// import 'package:pretty_dio_logger/pretty_dio_logger.dart'; +import 'package:flutter/foundation.dart'; +import 'package:pretty_dio_logger/pretty_dio_logger.dart'; +import 'package:selfprivacy/config/config.dart'; import 'package:selfprivacy/config/get_it_config.dart'; import 'package:selfprivacy/logic/models/console_log.dart'; import 'package:selfprivacy/utils/app_logger.dart'; @@ -14,12 +16,10 @@ abstract class RestApiMap { Future getClient({final BaseOptions? customOptions}) async { final Dio dio = Dio(customOptions ?? (await options)); - if (hasLogger) { - // dio.interceptors.add( - // PrettyDioLogger( - // logPrint: (final object) => log('$object'), - // ), - // ); + if (hasLogger && config.shouldDebugPrint) { + dio.interceptors.add( + PrettyDioLogger(logPrint: (final object) => debugPrint('$object')), + ); } dio.interceptors.add(ConsoleInterceptor()); dio.httpClientAdapter = IOHttpClientAdapter( @@ -34,10 +34,13 @@ abstract class RestApiMap { dio.interceptors.add( InterceptorsWrapper( - onError: (final DioException e, final ErrorInterceptorHandler handler) { - log('got dio error', error: e); + onError: ( + final DioException exception, + final ErrorInterceptorHandler handler, + ) { + log('got dio exception:', error: exception); - return handler.next(e); + return handler.next(exception); }, ), ); diff --git a/lib/utils/app_logger.dart b/lib/utils/app_logger.dart index b03c01f7..863eba9e 100644 --- a/lib/utils/app_logger.dart +++ b/lib/utils/app_logger.dart @@ -4,6 +4,7 @@ import 'package:selfprivacy/config/config.dart'; class AppLogger { const AppLogger({required this.name}); + final String name; // TODO: research other possible options, which could support both @@ -14,6 +15,7 @@ class AppLogger { final StackTrace? stackTrace, }) { if (config.shouldDebugPrint) { + // TODO: could probably add UI logging for console_page developer.log( message, error: error,