fix: re-enabled dio logs (developer debug console)

This commit is contained in:
Aliaksei Tratseuski 2024-06-30 18:49:07 +04:00
parent f7f791cc0c
commit 4bda23eaf9
2 changed files with 15 additions and 10 deletions

View file

@ -4,7 +4,9 @@ import 'dart:io';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:dio/io.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/config/get_it_config.dart';
import 'package:selfprivacy/logic/models/console_log.dart'; import 'package:selfprivacy/logic/models/console_log.dart';
import 'package:selfprivacy/utils/app_logger.dart'; import 'package:selfprivacy/utils/app_logger.dart';
@ -14,12 +16,10 @@ abstract class RestApiMap {
Future<Dio> getClient({final BaseOptions? customOptions}) async { Future<Dio> getClient({final BaseOptions? customOptions}) async {
final Dio dio = Dio(customOptions ?? (await options)); final Dio dio = Dio(customOptions ?? (await options));
if (hasLogger) { if (hasLogger && config.shouldDebugPrint) {
// dio.interceptors.add( dio.interceptors.add(
// PrettyDioLogger( PrettyDioLogger(logPrint: (final object) => debugPrint('$object')),
// logPrint: (final object) => log('$object'), );
// ),
// );
} }
dio.interceptors.add(ConsoleInterceptor()); dio.interceptors.add(ConsoleInterceptor());
dio.httpClientAdapter = IOHttpClientAdapter( dio.httpClientAdapter = IOHttpClientAdapter(
@ -34,10 +34,13 @@ abstract class RestApiMap {
dio.interceptors.add( dio.interceptors.add(
InterceptorsWrapper( InterceptorsWrapper(
onError: (final DioException e, final ErrorInterceptorHandler handler) { onError: (
log('got dio error', error: e); final DioException exception,
final ErrorInterceptorHandler handler,
) {
log('got dio exception:', error: exception);
return handler.next(e); return handler.next(exception);
}, },
), ),
); );

View file

@ -4,6 +4,7 @@ import 'package:selfprivacy/config/config.dart';
class AppLogger { class AppLogger {
const AppLogger({required this.name}); const AppLogger({required this.name});
final String name; final String name;
// TODO: research other possible options, which could support both // TODO: research other possible options, which could support both
@ -14,6 +15,7 @@ class AppLogger {
final StackTrace? stackTrace, final StackTrace? stackTrace,
}) { }) {
if (config.shouldDebugPrint) { if (config.shouldDebugPrint) {
// TODO: could probably add UI logging for console_page
developer.log( developer.log(
message, message,
error: error, error: error,