Skip to content

Commit 5546aa5

Browse files
committed
📝 Added some documentation for BoltLogger
1 parent ef09f95 commit 5546aa5

File tree

3 files changed

+81
-14
lines changed

3 files changed

+81
-14
lines changed

docs/bolt_logger.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# ⚡️ BoltLogger!
2+
_**Super charge your logging and zap logs like Zeus with the BoltLogger.**_
3+
4+
## 🚀 Features
5+
- Built on top of the `logging` package. Meaning package that use the `logging` package will also be visible in the BoltLogger.
6+
- Easy to use and setup.
7+
- Supports multiple charges (log outputs).
8+
- Supports multiple log levels.
9+
- Has extension methods for easy logging, with include reference to the calling class.
10+
11+
## 🛠 Setup
12+
To use the `BoltLogger`, you need to charge the logger with a `BoltCharge`.
13+
14+
```dart
15+
BoltLogger.charge(DebugConsoleCharge());
16+
```
17+
18+
Available charges:
19+
- `DebugConsoleCharge`: Logs output to the console.
20+
- `FileCharge`: Logs output to a file.
21+
- `MemoryCharge`: Keeps track of logs in memory.
22+
23+
## 📝 Zapping! (Usage)
24+
The `BoltLogger` aims to be easy to use. Once `BoltLogger` is charged you can start zapping logs! By zapping we mean literally calling `zap`.
25+
26+
Logging a message in `BoltLogger` is as simple as calling the `zap` method.
27+
28+
```dart
29+
class MyAwesomeClass{
30+
void doSomething() {
31+
zap('This is a message');
32+
}
33+
}
34+
```
35+
36+
`BoltLogger` offer `zap` as a extension on `Object` meaning you can call `zap` on or in any object.
37+
Because it's an extension we can automatically include the `runtimeType` of the object that called `zap` as tag for the log message.
38+
39+
Just as Zeus when zapping your not only limited to only zap `String`s, you can zap any object. For example: Exceptions, Errors, StackTrace. BoltLogger will take care of the objects accordingly.
40+
41+
Beside zapping messages you can also provide a custom `tag` and `level` to the `zap` method.
42+
43+
`BoltLogger` also offers a `shock` to zap logs with at a `Level.SERVERE` level.
44+
45+
If the extension methods are not available you can call `BoltLogger.zap` directly.
46+
47+
## 📦 Example
48+
```dart
49+
50+
class MyAwesomeClass{
51+
void doSomething() {
52+
zap('This is a message');
53+
}
54+
55+
void doSomethingElse() {
56+
shock(Exception('Shocking!'));
57+
}
58+
}
59+
60+
void main() {
61+
BoltLogger.charge(DebugConsoleCharge());
62+
63+
final myAwesomeClass = MyAwesomeClass();
64+
myAwesomeClass.doSomething();
65+
myAwesomeClass.doSomethingElse();
66+
}
67+
```

lib/logger/bolt_logger.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ class BoltLogger {
5959
}
6060

6161
/// Discharge the logger and all charges.
62-
void discharge() {
63-
_subscription?.cancel();
64-
_subscription = null;
65-
for (final output in _outputs.values) {
62+
static void discharge() {
63+
_instance._subscription?.cancel();
64+
_instance._subscription = null;
65+
for (final output in _instance._outputs.values) {
6666
output.discharge();
6767
}
68-
_outputs.clear();
68+
_instance._outputs.clear();
6969
}
7070

7171
/// {@template zap}
@@ -113,7 +113,7 @@ class BoltLogger {
113113
for (final Object? value in message) {
114114
zapMap(value);
115115
}
116-
}else {
116+
} else {
117117
zapMap(message);
118118
}
119119

@@ -126,11 +126,11 @@ class BoltLogger {
126126
/// {@macro zap}
127127
///
128128
/// {@endtemplate}
129-
static void shock(
130-
Object? message, {
131-
String? tag,
132-
Level level = Level.SEVERE,
133-
}) {
129+
static void shock(
130+
Object? message, {
131+
String? tag,
132+
Level level = Level.SEVERE,
133+
}) {
134134
zap(message, tag: tag, level: level);
135-
}
135+
}
136136
}

test/logger/bolt_logger_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'package:parameterized_test/parameterized_test.dart';
77
class _MockCharge extends Mock implements BoltCharge {}
88

99
void main() {
10-
tearDown(() => BoltLogger().discharge());
10+
tearDown(() => BoltLogger.discharge());
1111

1212
group('charge tests', () {
1313
test('BoltLogger without a charge only redirect log event to root Logger', () {
@@ -57,7 +57,7 @@ void main() {
5757
when(() => charge2.discharge()).thenReturn(null);
5858

5959
BoltLogger.charge([charge, charge2]);
60-
BoltLogger().discharge();
60+
BoltLogger.discharge();
6161

6262
verify(() => charge.discharge()).called(1);
6363
verify(() => charge2.discharge()).called(1);

0 commit comments

Comments
 (0)