Skip to content

Commit 7d8c8eb

Browse files
committed
Initial commit
0 parents  commit 7d8c8eb

File tree

15 files changed

+523
-0
lines changed

15 files changed

+523
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.DS_Store
2+
.dart_tool/
3+
.idea/
4+
.iml
5+
6+
.packages
7+
.pub/
8+
9+
build/
10+
ios/
11+
android/
12+
demo/
13+
14+
pubspec.lock
15+
doc/

.metadata

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: 7a4c33425ddd78c54aba07d86f3f9a4a0051769b
8+
channel: stable
9+
10+
project_type: package

.vscode/launch.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Example",
9+
"request": "launch",
10+
"type": "dart",
11+
"program": "example/lib/main.dart"
12+
}
13+
]
14+
}

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
## 0.4.0
2+
- First version of the new logger

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Simon Leier
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Logger
2+
3+
[![Version](https://img.shields.io/pub/v/logger.svg)](https://pub.dartlang.org/packages/logger) ![Runtime](https://img.shields.io/badge/dart-%3E%3D2.1-brightgreen.svg) ![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)
4+
5+
Small, easy to use and extensible logger which prints beautiful logs.
6+
Inspired by [logger](https://github.com/orhanobut/logger) for Android.
7+
8+
**Show some ❤️ and star the repo to support the project**
9+
10+
### Resources:
11+
- [Documentation](https://pub.dartlang.org/documentation/logger/latest/logger/)
12+
- [Pub Package](https://pub.dartlang.org/packages/logger)
13+
- [GitHub Repository](https://github.com/leisim/logger)
14+
15+
## Getting Started
16+
17+
Just create an instance of `Logger` and start logging:
18+
```dart
19+
var logger = Logger();
20+
21+
logger.d("Logger is working!");
22+
```
23+
24+
Instead of a string message, you can also pass other objects like `List`, `Map` or `Set`.
25+
26+
## Output
27+
28+
![](https://raw.githubusercontent.com/leisim/logger/master/art/screenshot.png)
29+
30+
## Log level
31+
32+
You can log with different levels:
33+
34+
```dart
35+
logger.v("Verbose log");
36+
37+
logger.d("Debug log");
38+
39+
logger.i("Info log");
40+
41+
logger.w("Warning log");
42+
43+
logger.e("Error log");
44+
45+
logger.wtf("What a terrible failure log");
46+
```
47+
48+
To show only specific log levels, you can set:
49+
50+
```dart
51+
Logger.level = Level.warning;
52+
```
53+
54+
This hides all `verbose`, `debug` and `info` log events.
55+
56+
## Options
57+
58+
When creating a logger, you can pass some options:
59+
60+
```dart
61+
var logger = Logger(
62+
printer: PrettyPrinter(), // Use the PrettyPrinter to format and print log
63+
filter: null, // Use the default LogFilter (-> only log in debug mode)
64+
);
65+
```
66+
67+
If you use the `PrettyPrinter`, there are more options:
68+
69+
```dart
70+
var logger = Logger(
71+
printer: PrettyPrinter(
72+
methodCount: 2, // number of method calls to be displayed
73+
errorMethodCount: 8, // number of method calls if stacktrace is provided
74+
lineLength : 120 // width of the output
75+
),
76+
)
77+
```
78+
79+
## LogPrinter
80+
81+
You can implement your own `LogPrinter`. This gives you maximum flexibility. A very basic printer could look like this:
82+
83+
```
84+
class MyPrinter extends LogPrinter {
85+
@override
86+
void log(Level level, dynamic message, dynamic error, StackTrace stackTrace) {
87+
print(message);
88+
}
89+
}
90+
```
91+
92+
If you created a cool `LogPrinter` which might be helpful to others, feel free to open a pull request. :)
93+
94+
## LogFilter
95+
96+
The `LogFilter` filters which logs should be shown and which don't.
97+
The default implementation shows all logs with `level >= Logger.level` while in debug mode. In release mode all logs are omitted.
98+
99+
You can create your own `LogFilter` like this:
100+
```dart
101+
var filter = (Level level, dynamic message, dynamic error, StackTrace stackTrace) {
102+
return true;
103+
}
104+
```
105+
This will show all logs even in release mode. (**NOT** a good idea)
106+
107+
## MIT License
108+
```
109+
Copyright (c) 2019 Simon Leier
110+
111+
Permission is hereby granted, free of charge, to any person obtaining a copy
112+
of this software and associated documentation files (the "Software"), to deal
113+
in the Software without restriction, including without limitation the rights
114+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
115+
copies of the Software, and to permit persons to whom the Software is
116+
furnished to do so, subject to the following conditions:
117+
118+
The above copyright notice and this permission notice shall be included in all
119+
copies or substantial portions of the Software.
120+
121+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
122+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
123+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
124+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
125+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
126+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
127+
SOFTWARE.
128+
```

art/screenshot.png

51.7 KB
Loading

example/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/test

example/lib/main.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import 'package:logger/logger.dart';
2+
3+
var logger = Logger();
4+
5+
var loggerNoStack = Logger(printer: PrettyPrinter());
6+
7+
void main() {
8+
teesr();
9+
}
10+
11+
void foo() {
12+
logger.v("Log message with 2 methods");
13+
14+
logger.d("Log message with 2 methods", "MIST");
15+
16+
logger.i("Log message with 2 methods");
17+
18+
logger.w("Just a warning!");
19+
20+
logger.e("Error! Something bad happened", "PROB");
21+
22+
logger.wtf("Hello world.", "PROBLEM!", StackTrace.current);
23+
24+
logger.d({"key": 5, "value": "something"});
25+
}
26+
27+
void teesr() {
28+
foo();
29+
}

0 commit comments

Comments
 (0)