my_logger

Creator: coderz1093

Last updated:

Add to Cart

Description:

my logger

MyLogger #
MyLogger is improved fork of Flogs package developed in flutter that provides quick & simple logging solution.
All logs are saved into DB which can be exported as a text file.
Overview #
MyLogger is written in Dart.
Logs are saved into Sembast database which can be exported into document directory and uploaded into server.
Logs are helpful when developer wants to analyze user activities within the app.
Many times we want to log a set of data to analyze certain activity.
For example:

Location (GPS Coordinates),
Device info,
Network requests
etc..

This helps us to quickly identify and fix issues that are hard to debug when app is in the production.
MyLogger provide functionality for log these data sets into database and fetch it by different filters.
Features #

Log messages by various levels (DEBUG, TRACE, INFO, WARNING, ERROR, SEVERE, FATAL)
Save logs into database
Export logs into file
Fetch or delete logs easily
Log filtering support
Custom timestamps support
Custom data type logging support
Custom log format support
Encryption support

Use this package as a library #
1. Depend on it
Add this to your package's pubspec.yaml file:
dependencies:
my_logger: ^1.0.2
copied to clipboard
2. Install it
You can install packages from the command line:
with Flutter
$ flutter packages get
copied to clipboard
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:my_logger/logger.dart';
copied to clipboard
How to use #
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"/>
copied to clipboard
iOS
<key>NSPhotoLibraryAddUsageDescription</key>
<string>MyLogger would like to save photos from the app to your gallery</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>MyLogger would like to access your photo gallery for uploading images to the app</string>
copied to clipboard
To save logs, simply call any of the method mentioned below:
MyLogger.trace("My trace log");

MyLogger.debug("My debug log");

MyLogger.info("My info log");

MyLogger.warning("My warning log");

MyLogger.error("My error log");

MyLogger.severe("My severe log");

MyLogger.fatal("My fatal log");

MyLoggerlog(
className: "HomePage",
methodName: "_buildRow1",
text: "My severe log with exception and stacktrace",
type: LogLevel.SEVERE,
exception: Exception("This is an Exception!"),
stacktrace: StackTrace.current,
);

MyLoggerlog(
className: "HomePage",
methodName: "_buildRow1",
text: "My severe log with dataLogType",
type: LogLevel.SEVERE,
dataLogType: DataLogType.DEVICE,
);
copied to clipboard
Available Methods #
MyLogger provide many other methods for save, filter or fetch logs. Below is list of all this methods:
Get logs:
MyLogger.logs.getAll(); // Get all saved logs
MyLogger.logs.getLastHour(); // Get all saved logs for last hour

// Get logs by LogFilter:
MyLogger.logs.getByFilter(
LogFilter(
startDateTime: DateTime(2019),
endDateTime: DateTime(2020),
dataLogsType: [DataLogType.NETWORK],
logLevels: [LogLevel.ERROR, LogLevel.WARNING],
),
);

// LogFilters also have some named constructors:
MyLogger.logs.getByFilter(LogFilter.last24Hours());
copied to clipboard
Write logs:
MyLogger.logs.write(Log log); // Save your own Log object
copied to clipboard
Delete logs:
MyLogger.logs.deleteAll(); // Delete all saved logs
MyLogger.logs.deleteLastHour(); // Delete all saved logs for last hour

// Delete logs by LogFilter:
MyLogger.logs.deleteByFilter(
LogFilter(
startDateTime: DateTime(2019),
endDateTime: DateTime(2020),
dataLogsType: [DataLogType.NETWORK],
logLevels: [LogLevel.ERROR, LogLevel.WARNING],
),
);

copied to clipboard
Export logs:
File fileExport = await MyLogger.logs.export(
fileName: "export-all-logs",
exportType: FileType.TXT,
filter: LogFilter.last24Hours(),
);
copied to clipboard
Change configuration:
LogConfig config = MyLogger.config
..outputFormat = "{{level}} {{time}} - {{message}}"
..dataLogTypeValues = DataLogType.values
..encryption = EncryptionType.XXTEA
..encryptionKey = encryptionKey
..timestampFormat = TimestampFormat.DEFAULT;

MyLogger.applyConfig(config);
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.