|
| 1 | +<div align="center"> |
1 | 2 |
|
2 | | -## Usage |
| 3 | +<div align="center"> |
| 4 | + <img src="https://raw.githubusercontent.com/youmtinetflutterpacks/console_tools/refs/heads/main/assets/readme_banner.png" alt="console_tools logo"/> |
| 5 | +</div> |
| 6 | + |
| 7 | +[](https://pub.dev/packages/console_tools) |
| 8 | +[](https://pub.dev/packages/console_tools/score) |
| 9 | +[](https://pub.dev/packages/console_tools/score) |
| 10 | +[](https://flutter.dev) |
| 11 | + |
| 12 | +[](https://github.com/youmtinetflutterpacks/console_tools/stargazers) |
| 13 | +[](https://github.com/youmtinetflutterpacks/console_tools/issues) |
| 14 | +[](https://github.com/youmtinetflutterpacks/console_tools/blob/main/LICENSE) |
| 15 | +[](https://github.com/youmtinetflutterpacks/console_tools/commits/main) |
| 16 | + |
| 17 | + |
| 18 | +[](https://github.com/youmtinetflutterpacks/console_tools) |
| 19 | +</div> |
| 20 | + |
| 21 | +A lightweight Dart console logger with ANSI color support, log-level icons, timestamps, and JSON pretty-printing. |
| 22 | + |
| 23 | +--- |
| 24 | + |
| 25 | +## Features |
| 26 | + |
| 27 | +- **Five log levels**: `debug`, `info`, `success`, `warning`, `error` |
| 28 | +- **ANSI color-coded output** (grey, cyan, green, yellow, red) |
| 29 | +- **Icons** for each level: 🐛 ℹ️ ✅ ⚠️ ❌ |
| 30 | +- **Optional tag** to identify the source of a log entry |
| 31 | +- **Timestamp** prefix (`[HH:mm:ss]`) |
| 32 | +- **JSON pretty-printing** with indentation |
| 33 | +- Global toggles: `Console.enableColors` and `Console.showTimestamp` |
| 34 | + |
| 35 | +--- |
| 36 | + |
| 37 | +## Installation |
3 | 38 |
|
| 39 | +Add the package to your `pubspec.yaml`: |
| 40 | + |
| 41 | +```yaml |
| 42 | +dependencies: |
| 43 | + console_tools: ^2.0.0 |
| 44 | +``` |
| 45 | +
|
| 46 | +Then run: |
| 47 | +
|
| 48 | +```sh |
| 49 | +dart pub get |
| 50 | +``` |
| 51 | + |
| 52 | +--- |
| 53 | + |
| 54 | +## Usage |
4 | 55 |
|
5 | 56 | ```dart |
6 | 57 | import 'package:console_tools/console_tools.dart'; |
7 | 58 |
|
8 | 59 | void main() { |
9 | | - for (var element in ConsoleColors.values) { |
10 | | - Console.log( |
11 | | - element.name, |
12 | | - color: element, |
13 | | - consoleStyle: ConsoleStyles.normal, |
14 | | - ); |
15 | | - } |
16 | | - Console.log('awesome: Console log normal 002', consoleStyle: ConsoleStyles.clineote); |
17 | | - Console.log('awesome: Console log normal 003', consoleStyle: ConsoleStyles.clineote); |
18 | | - Console.log('awesome: Console log normal 004', consoleStyle: ConsoleStyles.clineote); |
19 | | - Console.log('awesome: Console log normal', consoleStyle: ConsoleStyles.bold); |
20 | | - Console.log('awesome: Console log', consoleStyle: ConsoleStyles.bold); |
21 | | - Console.log('awesome: Console log clineote', consoleStyle: ConsoleStyles.clineote); |
22 | | - Console.log('awesome: Console log clineoteFast', consoleStyle: ConsoleStyles.clineoteFast); |
23 | | - Console.log('awesome: Console log italic', consoleStyle: ConsoleStyles.italic); |
24 | | - Console.log('awesome: Console log lineThrought', consoleStyle: ConsoleStyles.lineThrought); |
25 | | - Console.log('awesome: Console log normal2', consoleStyle: ConsoleStyles.normal2); |
26 | | - Console.log('awesome: Console log opacity', consoleStyle: ConsoleStyles.opacity); |
27 | | - Console.log('awesome: Console log underline', consoleStyle: ConsoleStyles.underline); |
| 60 | + Console.d("Debug message"); |
| 61 | + Console.i("Info message", tag: "AUTH"); |
| 62 | + Console.s("Login successful"); |
| 63 | + Console.w("API slow response"); |
| 64 | + Console.e("Crash detected"); |
| 65 | +
|
| 66 | + Console.json({ |
| 67 | + "user": "Younes", |
| 68 | + "role": "developer", |
| 69 | + }); |
28 | 70 | } |
| 71 | +``` |
29 | 72 |
|
| 73 | +### Sample output |
| 74 | + |
| 75 | +``` |
| 76 | +[12:34:56] 🐛 Debug message |
| 77 | +[12:34:56] ℹ️ [AUTH] Info message |
| 78 | +[12:34:56] ✅ Login successful |
| 79 | +[12:34:56] ⚠️ API slow response |
| 80 | +[12:34:56] ❌ Crash detected |
| 81 | +[12:34:56] 🐛 { |
| 82 | + "user": "Younes", |
| 83 | + "role": "developer" |
| 84 | +} |
| 85 | +``` |
| 86 | + |
| 87 | +--- |
| 88 | + |
| 89 | +## API Reference |
| 90 | + |
| 91 | +### `Console` class |
| 92 | + |
| 93 | +| Method | Level | Color | Description | |
| 94 | +|---|---|---|---| |
| 95 | +| `Console.d(msg, {tag})` | debug | grey | Debug information | |
| 96 | +| `Console.i(msg, {tag})` | info | cyan | General information | |
| 97 | +| `Console.s(msg, {tag})` | success | green | Success confirmation | |
| 98 | +| `Console.w(msg, {tag})` | warning | yellow | Non-critical warnings | |
| 99 | +| `Console.e(msg, {tag})` | error | red | Errors and exceptions | |
| 100 | +| `Console.json(obj, {tag})` | debug | grey | Pretty-prints a JSON object | |
| 101 | +| `Console.log(msg, {name})` | info | cyan | Alias for `Console.i` | |
| 102 | + |
| 103 | +### Global settings |
| 104 | + |
| 105 | +```dart |
| 106 | +Console.enableColors = false; // disable ANSI colors (default: true) |
| 107 | +Console.showTimestamp = false; // hide the [HH:mm:ss] prefix (default: true) |
30 | 108 | ``` |
31 | 109 |
|
| 110 | +--- |
| 111 | + |
| 112 | +## License |
| 113 | + |
| 114 | +MIT |
| 115 | + |
| 116 | +## 🔗 More Packages |
| 117 | + |
| 118 | +- [Power GeoJSON](https://pub.dev/packages/power_geojson) |
| 119 | +- [PopupMenu2](https://pub.dev/packages/popup_menu_2) |
| 120 | +- [Flutter Azimuth](https://pub.dev/packages/flutter_azimuth) |
| 121 | +- [Map Contextual Menu](https://pub.dev/packages/longpress_popup) |
| 122 | + |
| 123 | +--- |
| 124 | + |
| 125 | +## 👨💻 Developer Card |
| 126 | + |
| 127 | +<div align="center"> |
| 128 | + <img src="https://avatars.githubusercontent.com/u/47449165?v=4" alt="Younes M'rabti avatar" width="120" height="120" style="border-radius: 50%;" /> |
| 129 | + |
| 130 | +### Younes M'rabti |
| 131 | + |
| 132 | +📧 Email: [admin@youmti.net](mailto:admin@youmti.net) |
| 133 | +🌐 Website: [youmti.net](https://www.youmti.net/) |
| 134 | +💼 LinkedIn: [younesmrabti1996](https://www.linkedin.com/in/younesmrabti1996/) |
| 135 | +</div> |
0 commit comments