패키지, 저장소 및 앱 카테고리 검색

cr_logger 표지
패키지 상세v2.6.1

cr_logger

강력한 로깅 플러그인입니다. Android, iOS 및 웹 플랫폼을 지원합니다.

AndroidiOSWeb
30일 다운로드
444
좋아요
49
Pub 점수
120

패키지 설치

flutter pub add cr_logger

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

cr_logger는 Android, iOS, 웹 플랫폼 간에 일관되고 강력한 로깅을 제공하는 강력한 Flutter 로깅 플러그인입니다. 세부 디버깅 정보가 필요한 개발자를 위해 설계되었으며, 사용자 정의 가능한 출력 형식으로 구조화된 로깅을 지원합니다. 개발 워크플로우에 원활하게 통합되어 앱의 동작 및 성능 문제를 쉽게 추적할 수 있도록 합니다. 여러 플랫폼을 지원하기 때문에 타겟 환경에 관계없이 신뢰할 수 있는 로깅을 보장합니다. 설정 가능한 로그 레벨과 출력 대상을 통해 개발 및 운영 환경 모두에 적합합니다.

사용 사례

  • 앱 문제 디버깅
  • 앱 성능 모니터링
  • 사용자 작업 추적
  • 런타임 오류 캡처
  • 실시간 로그 분석 활성화
  • 크로스 플랫폼 개발 지원

주요 기능

  • 크로스 플랫폼 로깅(안드로이드, iOS, 웹)
  • 사용자 정의 로그 레벨
  • 구조화된 로그 출력
  • Flutter 앱과의 간편한 통합
  • 사용자 정의 로그 포맷터 지원
  • 최소 성능 오버헤드

적합한 대상

  • 통합 로깅이 필요한 플러터 개발자
  • 다중 플랫폼 애플리케이션을 개발하는 팀
  • 세부적인 런타임 진단이 필요한 앱
  • 개발 및 생산 환경
  • 엄격한 로깅 요구 사항을 가진 프로젝트

고려 사항

  • 생산 환경에 대한 구성이 필요할 수 있습니다
  • 릴리스 빌드에서는 로그 출력을 필터링해야 합니다
  • 성능에 미치는 영향은 로깅 빈도에 따라 달라집니다
  • 최적화 없이 고용량 로깅을 위한 것이 아님
  • 로그에서 민감한 데이터를 주의 깊게 다뤄야 합니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

cr_logger

Web example

Flutter plugin for logging

  • Simple logging to logcat.
  • Network request intercepting.
  • Log exporting (JSON format).
  • Proxy settings for "Charles".
  • Logs by level.

Supported Dart http client plugins:
✔️ Dio
✔️ Chopper
✔️ Http from http/http package
✔️ HttpClient from dart:io package

Table of contents

Screenshots

Getting Started

  1. Add plugin to the project:

    dependencies:
      cr_logger: ^2.2.0
    
  2. Initialize the logger. main.dart:

    ❗ Database won't be working in Web

    void main()  {
      ...
      CRLoggerInitializer.instance.init(
        theme: ThemeData.light(),
        levelColors: {
          Level.debug: Colors.grey.shade300,
          Level.warning: Colors.orange,
        },
        hiddenFields: [
          'token',
        ],
        logFileName: 'my_logs',
        printLogs: true,
        useCrLoggerInReleaseBuild: false,
        useDatabase: false,
      );
    }
    

    printLogs - Prints all logs while [printLogs] is true

    useCrLoggerInReleaseBuild - All logs will be printed and used database when [kReleaseMode] is true

    useDatabase - Use database for logs history. Allows persisting logs on app restart. It will work only with [useCrLoggerInReleaseBuild] set to true.

    theme - Custom logger theme

    levelColors - Colors for message types levelColors (debug, verbose, info, warning, error, wtf)

    hiddenFields - List of keys, whose value need to be replaced by string 'Hidden'

    logFileName - File name when sharing logs

    maxLogsCount - Maximum number of each type of logs (http, debug, info, error), by default = 50

    maxDatabaseLogsCount - Maximum number of each type of logs (http, debug, info, error), which will be saved to database, by default = 50

    logger - Custom logger

    printLogsCompactly - If the value is false, then all logs, except HTTP logs, will have borders, with a link to the place where the print is called and the time when the log was created. Otherwise it will write only log message. By default = true

  3. Initialize Inspector (optional):

    return MaterialApp(
      home: const MainPage(),
      builder: (context, child) => CrInspector(child: child!),
    );
    
  4. Define the variables:

    4.1 appInfo - you can provide custom information to be displayed on the AppInfo page

    CRLoggerInitializer.instance.appInfo = {
      'Build type': buildType.toString(),
      'Endpoint': 'https/cr_logger/example/',
    };
    

    4.2 logFileName - file name when exporting logs

    4.3 hiddenFields - list of keys for headers to hide when showing network logs

  5. Add the overlay button:

    CRLoggerInitializer.instance.showDebugButton(context);
    

    button - Custom floating button

    left - X-axis start position

    top - Y-axis start position

  6. Support for importing logs from json:

    await CRLoggerInitializer.instance.createLogsFromJson(json);
    
  7. You can get the current proxy settings to initialise Charles:

    final proxy = CRLoggerInitializer.instance.getProxySettings();
    if (proxy != null) {
      RestClient.instance.init(proxy);
    }
    

Usage

If the logger is enabled, a floating button appears on the screen; it also indicates the project build number. It's quite easy to use, just click on the floating button to show the main screen of the logger You can also double tap on the button to invoke Quick Actions.

Quick actions

Using this popup menu, you can quickly access the desired CRLogger options. Called by a long press or double tap on the debug button.

App info

Allows you to view Package name, app version, build version

Clear logs

Clears certain logs or all of them. It is possible to do this with logs from the database

Show Inspector

If the inspector is enabled, then a panel appears on the right side of the screen, with buttons to toggle size inspection and the color picker.

Set Charles proxy

Needed to set proxy settings for Charles

Search

Provides search by logs. By paths, you can search for HTTP log you need. Also there is a search for logs from the database.

Share logs

Share logs with your team

Create log with parameter

You can create log with parameters. To do this use {{parameter}} pattern to highlight text needed to be displayed as parameter.

Example:

  const parameter = 'PARAMETER';
  log.d('Debug message with param: {{$parameter}}');
  log.v('Verbose message with param: {{$parameter}}');
  log.i('Info message with param: {{$parameter}}');
  log.e('Error message with param: {{$parameter}}');

Now you can copy the value of this parameter by simply clicking on it in the details of the log.

Actions and values

Opens a page that contains action buttons and value notifiers.

Action buttons allows you to add different callbacks for testing

  1. Add actions:

    CRLoggerInitializer.instance.addActionButton('Log Hi', () => log.i('Hi'));
    CRLoggerInitializer.instance.addActionButton(
      'Log By',
      () => log.i('By'),
      connectedWidgetId: 'some identifier',
    );
    
  2. Remove actions by specified id:

    CRLoggerInitializer.instance.removeActionsById('some identifier');
    

Value notifiers help keep track of changes to variables of ValueNotifier type.

  1. Type notifiers:

     /// Type notifiers
      final boolNotifier = ValueNotifier<bool>(false);
      final stringNotifier = ValueNotifier<String>('integer: ');
    
     /// Widget notifiers
     final boolWithWidgetNotifier = ValueNotifier<bool>(false);
     final boolWidget = ValueListenableBuilder<bool>(
       valueListenable: boolWithWidgetNotifier,
       builder: (_, value, __) => SwitchListTile(
         title: const Text('Bool'),
         subtitle: Text(value.toString()),
         value: value,
         onChanged: (newValue) => boolWithWidgetNotifier.value = newValue,
       ),
     );
      final textNotifier = ValueNotifier<Text>(
       const Text('Widget text'),
      );
      final textWidget = ValueListenableBuilder<Text>(
       valueListenable: textNotifier,
       builder: (_, value, __) => Row(
         children: [
           const Text('Icon'),
           const Spacer(),
           value,
           const Spacer(),
         ],
       ),
     );
    
  2. Add notifiers: You can add either a name and a notifier or just a widget. If you just want to see the value of the notifier, it's better to use name + notifier. In other case, if you need to change notifier's value, for example via a switcher, it's better to add a widget.

     CRLoggerInitializer.instance.addValueNotifier(
       widget: boolWidget,
     );
     
     CRLoggerInitializer.instance.addValueNotifier(
       name: 'Bool',
       notifier: boolNotifier,
     );
     CRLoggerInitializer.instance.addValueNotifier(
       widget: textWidget,
     );
    
  3. Remove notifiers by specified id:

    CRLoggerInitializer.instance.removeNotifiersById('some identifier');
    
  4. Clear all notifiers:

    CRLoggerInitializer.instance.notifierListClear();
    
  5. Initialize the following callbacks (optional): 5.1. ShareLogsFileCallback - when needed to share logs file on the app's side

    CRLoggerInitializer.instance.onShareLogsFile = (path) async {
      await Share.shareFiles([path]);
    };
    
App settings

Opens application settings

Setup

In IntelliJ/Studio you can collapse the request/response body:

Gif showing collapsible body

Set up this is by going to Preferences -> Editor -> General -> Console and under Fold console lines that contain add these 2 rules: ║, ╟ and under Exceptions add 1 rule: ╔╣

Settings

카테고리

의존성

의존성 목록 23 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.