Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions packages/dragon_logs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.idea/
.vscode/
*.iml

# Android related
**/android/app/build/
**/android/.gradle/
**/android/captures/
**/android/gradle-wrapper.jar
**/android/local.properties
**/android/.idea/
**/android/.directory
**/android/*/src/main/res/mipmap-*/.DS_Store
**/android/*/src/main/res/drawable-*/.DS_Store
**/android/*/src/main/res/drawable-*/.DS_Store
**/android/*/src/main/res/raw/.DS_Store

# iOS related
**/ios/.generated/
**/ios/.idea/
**/ios/.vagrant/
**/ios/.sconsign.dblite
**/ios/.svn/
**/ios/*xcuserdata
**/ios/*.moved-aside
**/ios/*.pbxuser
**/ios/*.mode1v3
**/ios/*.mode2v3
**/ios/*.perspectivev3
**/ios/Podfile.lock
**/ios/Pods/
**/ios/.*.sw?
**/ios/*.bak
**/ios/*~
**/ios/.lock-wscript
**/ios/Build/
**/ios/DerivedData/
**/ios/.DS_Store

# Flutter/Dart related
.dart_tool/
.packages
.pub/
.pub-cache/
build/
**/doc/api/
.flutter-plugins
.flutter-plugins-dependencies
flutter_export_environment.sh
#Not required for packages
/pubspec.lock

# Exceptions to above rules.
!**/ios/**/default.profraw

30 changes: 30 additions & 0 deletions packages/dragon_logs/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: "efbf63d9c66b9f6ec30e9ad4611189aa80003d31"
channel: "stable"

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: efbf63d9c66b9f6ec30e9ad4611189aa80003d31
base_revision: efbf63d9c66b9f6ec30e9ad4611189aa80003d31
- platform: web
create_revision: efbf63d9c66b9f6ec30e9ad4611189aa80003d31
base_revision: efbf63d9c66b9f6ec30e9ad4611189aa80003d31

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
43 changes: 43 additions & 0 deletions packages/dragon_logs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
## 1.1.0

- Bump packages to latest versions.
- Apply new Dart format styling introduced in Dart `3.27`.

## 1.0.4

- Fix log message sorting bug. Thanks to @takenagain for their first contribution to this project.

## 1.0.2

- Bump `intl` dependency to latest version of `0.19.0`.

## 1.0.1

- Refactor to share more code with web and native platforms.
- Fix date parsing bug.
- Add public API to clear all logs.

Refactor to share more code between web and native platforms (focused mainly on file name and directory handling) and fix a bug where logs belonging to days with a single digit month or day could not be parsed.

## 1.0.0

- Stable release
- Tweak: Localisation initialisation no longer needs to be inialised before logs.


## 0.1.1-preview.1

- Memory improvement for log flushing.
- Bug fixes.


## 0.1.0-preview.1

- Bug fixes.


## 0.0.1-preview.1

- Initial preview version.


21 changes: 21 additions & 0 deletions packages/dragon_logs/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 - 2023 Komodo Platform

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
203 changes: 203 additions & 0 deletions packages/dragon_logs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
# 🚚 Repository Moved

> **⚠️ This repository has been migrated to the Komodo DeFi SDK Flutter monorepo.**
>
> 📍 **New location:** [packages/dragon_logs_flutter](https://github.com/KomodoPlatform/komodo-defi-sdk-flutter/tree/main/packages/dragon_logs_flutter)
>
> 🔄 **Active development** continues in the monorepo. Please update your forks, bookmarks, and links.
>
> 💡 **For issues, PRs, and contributions**, please use the [main monorepo](https://github.com/KomodoPlatform/komodo-defi-sdk-flutter).

---

# Dragon Logs (Archived)

<p align="center">
<a href="https://pub.dev/packages/dragon_logs"><img src="https://img.shields.io/pub/v/dragon_logs.svg" alt="Pub"></a>
</p>

A lightweight, high-throughput cross-platform logging framework for Flutter with persisted log storage.

[![Komodo Platform Logo](https://komodoplatform.com/assets/img/logo-dark.webp)](https://github.com/KomodoPlatform)

## Overview

Dragon Logs aims to simplify the logging and log storage process in your Flutter apps by ensuring it's efficient, easy to use, and uniform across different platforms. With its high-performance novel storage method for web, OPFS, Dragon Logs stands out as a modern solution for your logging needs.

## Roadmap

- ✅ Cross-platform log storage
- ✅ Cross-platform logs download
- ⬜ Flutter web wasm support
- ⬜ Web multi-threading support
- ⬜ Log levels (e.g. debug, info, warning, error)
- ⬜ Performance metrics (in progress)
- ⬜ Compressed file export
- ⬜ Dev environment configurable logging filters for console
- ⬜ Stacktrace formatting
- ⬜ Log analytics

Your feedback and contributions to help achieve these features would be much appreciated!

## Installation

To use Dragon Logs, add it as a dependency in your `pubspec.yaml` file:

```yaml
dependencies:
dragon_logs: ^1.0.4
```

Then, run:

```
flutter pub get
```

# Dragon Logs API Documentation and Usage

Dragon Logs is a lightweight, high-throughput logging framework designed for Flutter applications. This document provides an overview of the main API and usage instructions to help developers quickly integrate and use the package in their Flutter applications.

## API Overview

### Initialization

#### `init()`

Initialize the logger. This method prepares the logger for use and ensures any old logs beyond the set maximum storage size are deleted.

This method must be called after Widget binding has been initialized and before logging is attempted.

Usage:

```dart
await DragonLogs.init();
```

### Metadata Management

#### `setSessionMetadata(Map<String, dynamic> metadata)`

Set session metadata that can be attached to logs. This is useful for attaching session-specific information such as user IDs, device information, etc.

Usage:

```dart
DragonLogs.setSessionMetadata({
'userID': '12345',
'device': 'Pixel 4a',
'appVersion': '1.0.0'
});
```

#### `clearSessionMetadata()`

Clear any session metadata that was previously set.

Usage:

```dart
DragonLogs.clearSessionMetadata();
```

### Logging

#### `log(String message, [String key = 'LOG'])`

Log a message with an optional key. The message will be stored with any session metadata that's currently set.

Usage:

```dart
log('This is a sample log message.');
log('User logged in', 'USER_ACTION');
```

### Exporting Logs

#### `exportLogsStream() -> Stream<String>`

Get a stream of all stored logs. This is useful if you want to process logs in a streaming manner, e.g., for streaming uploads.

The stream events do not guarantee a uniform payload. Some events may contain a single log entry or a split log entry, while others may contain the entire log history for a given day. Appending all events to a single string (without any separators) represents the entire log history as is stored on the device.

**NB**: The stream will not emit any logs that are added after the stream is created and it completes after emitting all stored logs.

**NB**: It is highly recommended to not use **toList()** or store the entire stream in memory for extremely large log histories as this may cause memory issues. Prefer using lazy iterables where possible.

Usage:

```dart
final logsStream = DragonLogs.exportLogsStream();

File file = File('${getApplicationCacheDirectory}}/output.txt');

file = await file.exists() ? file : await file.create(recursive: true);

final logFileSink = file.openWrite(mode: FileMode.append);

for (final log in await logsStream) {
logFileSink.writeln(log);
}

await logFileSink.close();
```

#### `exportLogsString() -> Future<String>`

Get all stored logs as a single concatenated string.

**NB**: This method is not recommended for extremely large log histories as it may cause memory issues. Prefer using the stream-based API where possible.

Usage:

```dart
final logsString = await DragonLogs.exportLogsString();
print(logsString);
```

#### `exportLogsToDownload() -> Future<void>`

Export the stored logs, preparing them for download. The exact behavior may vary depending on platform specifics. The files are stored in the app's documents directory. On non-web platforms, the files are exported using the system's save-as or share dialog. On web, the files are downloaded to the default downloads directory.

Usage:

```dart
await DragonLogs.exportLogsToDownload();
```

### Utilities

#### `getLogFolderSize() -> Future<int>`

Get the current size of the log storage folder in bytes. This excludes generated export files.

Usage:

```dart
final sizeInBytes = await DragonLogs.getLogFolderSize();
print('Log folder size: $sizeInBytes bytes');
```

#### `perfomanceMetricsSummary -> String` (COMING SOON)

Get a summary of the logger's performance metrics.

Usage:

```dart
final metricsSummary = DragonLogs.perfomanceMetricsSummary;
print(metricsSummary);
```

## Contributing

Dragon Logs welcomes contributions from the community. Whether it's a bug report, feature suggestion, or a code contribution, we value all feedback. Please read the [CONTRIBUTING.md](link_to_contributing.md) file for detailed instructions.

## License

This project is licensed under the MIT License. See the [LICENSE](link_to_license_file) file for more details.

---

Made with ❤️ by [KomodoPlatform](https://github.com/KomodoPlatform)
30 changes: 30 additions & 0 deletions packages/dragon_logs/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.

include: package:lints/recommended.yaml

# Uncomment the following section to specify additional rules.

linter:
rules:
require_trailing_commas: true

# analyzer:
# exclude:
# - path/to/excluded/files/**

# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints

# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options
Loading
Loading