Skip to content
Zubair Rehman edited this page May 5, 2019 · 2 revisions

How to use

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

dependencies:
  f_logs: ^1.1.0

2. Install it

You can install packages from the command line:

with Flutter

$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:f_logs/constants/constants.dart';
import 'package:f_logs/constants/db_constants.dart';
import 'package:f_logs/data/local/app_database.dart';
import 'package:f_logs/data/local/flog_dao.dart';
import 'package:f_logs/model/datalog/data_log_type.dart';
import 'package:f_logs/model/flog/flog.dart';
import 'package:f_logs/model/flog/flog_config.dart';
import 'package:f_logs/model/flog/log.dart';
import 'package:f_logs/model/flog/log_level.dart';
import 'package:f_logs/utils/filters/filters.dart';
import 'package:f_logs/utils/formatter/formate_type.dart';
import 'package:f_logs/utils/formatter/formatter.dart';
import 'package:f_logs/utils/storage/logs_storage.dart';
import 'package:f_logs/utils/timestamp/timestamp_format.dart';

Runtime Permissions

Log files are exported on storage directory so it's very important to add these permissions to your project's manifest file first.

Android

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

iOS

<key>NSPhotoLibraryAddUsageDescription</key>
<string>FLogs would like to save photos from the app to your gallery</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>FLogs would like to access your photo gallery for uploading images to the app</string>

Configuration

FLogs can be configured by calling FLog.applyConfigurations(config); method and passing a configuration object as shown below:

Example 1

LogsConfig config = FLog.getDefaultConfigurations()
  ..isDevelopmentDebuggingEnabled = true
  ..timestampFormat = TimestampFormat.TIME_FORMAT_FULL_2;

FLog.applyConfigurations(config);

Example 2

LogsConfig config = LogsConfig()
    ..isDebuggable = true
    ..customClosingDivider = "|"
    ..customOpeningDivider = "|"
    ..csvDelimiter = ", "
    ..isLogEnabled = true
    ..encryptionEnabled = false
    ..encryptionKey = ""
    ..formatType = FormatType.FORMAT_CURLY
    ..logLevelsEnabled = [LogLevel.INFO, LogLevel.ERROR]
    ..dataLogTypes = [
      DataLogType.DEVICE.toString(),
      DataLogType.NETWORK.toString(),
      "Your own data type here"
    ]
    ..timestampFormat = TimestampFormat.TIME_FORMAT_READABLE;

  FLog.applyConfigurations(config);