Skip to content

Commit 7eb0c73

Browse files
ferraraferFilledStacks
authored andcommitted
chore: add logger document
1 parent 1417fb5 commit 7eb0c73

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed

docs/in-depth/logger.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
id: logger
3+
title: Logger
4+
sidebar_label: Logger
5+
sidebar_position: 4
6+
tags: [logger]
7+
---
8+
9+
If you want to add a Logger to your app, all you have to do is supply a logger config.
10+
11+
```dart
12+
@StackedApp(
13+
logger: StackedLogger(),
14+
)
15+
```
16+
17+
In addition to that you have to add the `logger` package into your project's pubspec file.
18+
19+
```yaml
20+
dependencies:
21+
...
22+
logger:
23+
```
24+
25+
When you run the **build_runner** it will create a new file called `app.logger.dart` in the same folder as your app folder. In that file you will see some code for the logger. The most important part of that file for you is the `getLogger` function. This function is what you'll use for logging in your app. There's a few things about how this logger is setup.
26+
27+
### How to use it
28+
29+
When using the logger provide the exact class name it's being used in. To make use of a logger you'll do the following.
30+
31+
```dart
32+
class MyViewModel {
33+
final logger = getLogger('MyViewModel');
34+
35+
void doStuff() {
36+
logger.i('');
37+
}
38+
}
39+
```
40+
41+
The code above will print out the following.
42+
43+
```
44+
💡 MyViewModel | doStuff
45+
```
46+
47+
It will automatically print out the name of the function that it's in. This can only be done if we know the exact class name that the logger is for. Which is why that's so important.
48+
49+
### Avoid clash with getLogger
50+
51+
If you already have `getLogger` function in your code base and you want to use a different name you can supply that to the logger config.
52+
53+
```dart
54+
@StackedApp(
55+
logger: StackedLogger(
56+
logHelperName: 'getStackedLogger',
57+
)
58+
)
59+
```
60+
61+
Now the function to get your logger will be called `getStackedLogger`. If you want a more detailed guide on how to effectively log in your application read [this guide](https://www.filledstacks.com/post/flutter-logging-a-guide-to-use-it-effectively/) that we use for our production apps.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
id: logger
3+
title: Logger
4+
sidebar_label: Logger
5+
sidebar_position: 4
6+
tags: [logger]
7+
---
8+
9+
If you want to add a Logger to your app, all you have to do is supply a logger config.
10+
11+
```dart
12+
@StackedApp(
13+
logger: StackedLogger(),
14+
)
15+
```
16+
17+
In addition to that you have to add the `logger` package into your project's pubspec file.
18+
19+
```yaml
20+
dependencies:
21+
...
22+
logger:
23+
```
24+
25+
When you run the **build_runner** it will create a new file called `app.logger.dart` in the same folder as your app folder. In that file you will see some code for the logger. The most important part of that file for you is the `getLogger` function. This function is what you'll use for logging in your app. There's a few things about how this logger is setup.
26+
27+
### How to use it
28+
29+
When using the logger provide the exact class name it's being used in. To make use of a logger you'll do the following.
30+
31+
```dart
32+
class MyViewModel {
33+
final logger = getLogger('MyViewModel');
34+
35+
void doStuff() {
36+
logger.i('');
37+
}
38+
}
39+
```
40+
41+
The code above will print out the following.
42+
43+
```
44+
💡 MyViewModel | doStuff
45+
```
46+
47+
It will automatically print out the name of the function that it's in. This can only be done if we know the exact class name that the logger is for. Which is why that's so important.
48+
49+
### Avoid clash with getLogger
50+
51+
If you already have `getLogger` function in your code base and you want to use a different name you can supply that to the logger config.
52+
53+
```dart
54+
@StackedApp(
55+
logger: StackedLogger(
56+
logHelperName: 'getStackedLogger',
57+
)
58+
)
59+
```
60+
61+
Now the function to get your logger will be called `getStackedLogger`. If you want a more detailed guide on how to effectively log in your application read [this guide](https://www.filledstacks.com/post/flutter-logging-a-guide-to-use-it-effectively/) that we use for our production apps.

0 commit comments

Comments
 (0)