Skip to content

Commit 006e0f1

Browse files
committed
update
1 parent 7102be7 commit 006e0f1

File tree

10 files changed

+248
-188
lines changed

10 files changed

+248
-188
lines changed

ARTICLE.md

Lines changed: 156 additions & 112 deletions
Large diffs are not rendered by default.

doc/assets/banner.png

240 KB
Loading

doc/assets/screenshot1.png

17.4 KB
Loading

doc/assets/screenshot2.png

128 KB
Loading

doc/assets/screenshot3.png

30.2 KB
Loading

example/example.dart

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,18 @@
1-
//.title
2-
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
3-
//
4-
// Dart/Flutter (DF) Packages by dev-cetera.com & contributors. The use of this
5-
// source code is governed by an MIT-style license described in the LICENSE
6-
// file located in this project's root directory.
7-
//
8-
// See: https://opensource.org/license/mit
9-
//
10-
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
11-
//.title~
12-
131
import 'package:df_log/df_log.dart';
142

15-
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
16-
173
void main() {
184
Log.start('Application starting...');
19-
Log.info('This is an informational message.');
20-
Log.ok('User successfully authenticated.');
21-
Log.alert('Network connection is slow.');
22-
Log.err('Failed to load user data!');
5+
Log.info('Checking for user session...');
6+
Log.alert('Network connection is slow. Retrying in 5s.');
7+
Log.ok('User session found and validated.');
8+
Log.err('Failed to load user preferences!');
239
Log.stop('Application shutting down.');
24-
Log.printRed('printRed: This is an important error.');
25-
Log.printGreen('printGreen: Operation was successful.');
26-
Log.printYellow('printYellow: This is a warning.');
27-
print(Log.items.map((e) => e.toJson()));
10+
Log.printRed('This is printed in RED!');
11+
Log.printGreen('This is printed in GREEN!');
12+
Log.printBlue('This is printed in BLUE!');
13+
Log.printYellow('This is printed in YELLOW!');
14+
Log.printCyan('This is printed in CYAN!');
15+
Log.printPurple('This is printed in PURPLE!');
16+
Log.printBlack('This is printed in BLACK!');
17+
Log.printWhite('This is printed in WHITE!');
2818
}

lib/_common.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//.title
2+
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
3+
//
4+
// Dart/Flutter (DF) Packages by dev-cetera.com & contributors. The use of this
5+
// source code is governed by an MIT-style license described in the LICENSE
6+
// file located in this project's root directory.
7+
//
8+
// See: https://opensource.org/license/mit
9+
//
10+
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
11+
//.title~
12+
13+
export 'dart:math' show max;
14+
export 'package:stack_trace/stack_trace.dart' show Frame;
15+
export 'package:df_safer_dart/df_safer_dart.dart' show Here;
16+
export 'package:meta/meta.dart' show visibleForTesting;
17+
export 'dart:collection' show Queue;
18+
export 'dart:convert' show JsonEncoder;
19+
export 'package:uuid/uuid.dart' show Uuid;
20+
21+
export 'src/_src.g.dart';

lib/src/log.dart

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,9 @@
88
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
99
//title~
1010

11-
import 'dart:math';
12-
13-
import 'package:df_safer_dart/df_safer_dart.dart' show Here;
14-
import 'package:meta/meta.dart' show visibleForTesting;
1511
import 'dart:developer' as developer;
16-
import 'dart:collection' show Queue;
1712

18-
import '_src.g.dart';
13+
import '/_common.dart';
1914

2015
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
2116

@@ -47,7 +42,7 @@ final class Log {
4742
/// If `true`, new logs are added to the in-memory `items` queue.
4843
static var storeLogs = true;
4944

50-
static int _maxStoredLogs = 1000;
45+
static int _maxStoredLogs = 50;
5146

5247
/// The maximum number of logs to keep in memory. Older logs are discarded.
5348
static int get maxStoredLogs => _maxStoredLogs;
@@ -122,7 +117,7 @@ final class Log {
122117

123118
@pragma('vm:prefer-inline')
124119
static _LogMessage trace(
125-
dynamic message, [
120+
Object? message, [
126121
Set<Symbol> tags = const {},
127122
@visibleForTesting int initialStackLevel = 0,
128123
]) {
@@ -137,7 +132,7 @@ final class Log {
137132

138133
@pragma('vm:prefer-inline')
139134
static _LogMessage err(
140-
dynamic message, [
135+
Object? message, [
141136
Set<Symbol> tags = const {},
142137
@visibleForTesting int initialStackLevel = 0,
143138
]) {
@@ -152,7 +147,7 @@ final class Log {
152147

153148
@pragma('vm:prefer-inline')
154149
static _LogMessage alert(
155-
dynamic message, [
150+
Object? message, [
156151
Set<Symbol> tags = const {},
157152
@visibleForTesting int initialStackLevel = 0,
158153
]) {
@@ -167,7 +162,7 @@ final class Log {
167162

168163
@pragma('vm:prefer-inline')
169164
static _LogMessage ignore(
170-
dynamic message, [
165+
Object? message, [
171166
Set<Symbol> tags = const {},
172167
@visibleForTesting int initialStackLevel = 0,
173168
]) {
@@ -183,7 +178,7 @@ final class Log {
183178

184179
@pragma('vm:prefer-inline')
185180
static _LogMessage ok(
186-
dynamic message, [
181+
Object? message, [
187182
Set<Symbol> tags = const {},
188183
@visibleForTesting int initialStackLevel = 0,
189184
]) {
@@ -198,7 +193,7 @@ final class Log {
198193

199194
@pragma('vm:prefer-inline')
200195
static _LogMessage start(
201-
dynamic message, [
196+
Object? message, [
202197
Set<Symbol> tags = const {},
203198
@visibleForTesting int initialStackLevel = 0,
204199
]) {
@@ -213,7 +208,7 @@ final class Log {
213208

214209
@pragma('vm:prefer-inline')
215210
static _LogMessage stop(
216-
dynamic message, [
211+
Object? message, [
217212
Set<Symbol> tags = const {},
218213
@visibleForTesting int initialStackLevel = 0,
219214
]) {
@@ -228,7 +223,7 @@ final class Log {
228223

229224
@pragma('vm:prefer-inline')
230225
static _LogMessage info(
231-
dynamic message, [
226+
Object? message, [
232227
Set<Symbol> tags = const {},
233228
@visibleForTesting int initialStackLevel = 0,
234229
]) {
@@ -243,7 +238,7 @@ final class Log {
243238

244239
@pragma('vm:prefer-inline')
245240
static _LogMessage message(
246-
dynamic message, [
241+
Object? message, [
247242
Set<Symbol> tags = const {},
248243
@visibleForTesting int initialStackLevel = 0,
249244
]) {
@@ -523,9 +518,10 @@ final class Log {
523518
}) {
524519
// Maybe get the basepath.
525520
String? location;
521+
Frame? frame;
526522
if (includePath) {
527-
final frame = Here(max(0, initialStackLevel - 1)).call().orNull();
528-
location = _shortenedLocation(frame?.location, frame?.member);
523+
frame = Here(max(0, initialStackLevel - 1)).call().orNull();
524+
location = _shortLocation(frame?.location, frame?.member);
529525
}
530526

531527
// Combine tags with the tag from category.
@@ -540,6 +536,7 @@ final class Log {
540536
showId: showIds,
541537
showTags: showTags,
542538
showTimestamp: showTimestamps,
539+
frame: frame,
543540
);
544541

545542
// Remove old logs.
@@ -556,9 +553,8 @@ final class Log {
556553
callback(logItem);
557554
}
558555

559-
// Only print if combinedTags is empty or all of combinedTags are in activeTags.
560-
if (combinedTags.isNotEmpty && !activeTags.containsAll(combinedTags)) {
561-
// TODO: Or just use contains?
556+
// Only print if combinedTags is empty or any of combinedTags are in activeTags.
557+
if (combinedTags.isNotEmpty && !activeTags.any((e) => combinedTags.contains(e))) {
562558
return;
563559
}
564560

@@ -582,7 +578,7 @@ typedef Glog = Log;
582578

583579
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
584580

585-
String? _shortenedLocation(String? location, String? member) {
581+
String? _shortLocation(String? location, String? member) {
586582
if (location == null) {
587583
return null;
588584
}
@@ -597,6 +593,7 @@ String? _shortenedLocation(String? location, String? member) {
597593
return '$file/$member #$line';
598594
}
599595
}
596+
600597
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
601598

602599
enum _IconCategory {

lib/src/log_item.dart

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@
1010
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
1111
//.title~
1212

13-
import 'dart:convert' show JsonEncoder;
14-
15-
import 'package:uuid/uuid.dart';
16-
17-
import 'ansi_styled_string.dart';
13+
import '/_common.dart';
1814

1915
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
2016

@@ -25,6 +21,7 @@ final class LogItem {
2521

2622
final String id;
2723
final DateTime timestamp;
24+
final Frame? frame;
2825
final String? location;
2926
final String? icon;
3027
final Object? message;
@@ -43,15 +40,16 @@ final class LogItem {
4340
//
4441

4542
LogItem({
46-
this.location,
47-
this.icon,
48-
this.message,
49-
this.tags = const {},
50-
this.showId = false,
51-
this.showTags = true,
52-
this.showTimestamp = false,
53-
}) : id = const Uuid().v4(),
54-
timestamp = DateTime.now();
43+
required this.location,
44+
required this.icon,
45+
required this.message,
46+
required this.tags,
47+
required this.showId,
48+
required this.showTags,
49+
required this.showTimestamp,
50+
required this.frame,
51+
}) : id = const Uuid().v4(),
52+
timestamp = DateTime.now();
5553

5654
//
5755
//
@@ -69,7 +67,6 @@ final class LogItem {
6967
buffer.write(location);
7068
if (showTimestamp) {
7169
final isoString = timestamp.toLocal().toIso8601String();
72-
// Grabs 'HH:mm:ss.SSS'
7370
final timeStr = isoString.substring(11, 23);
7471
buffer.write(' @$timeStr');
7572
}
@@ -105,12 +102,8 @@ final class LogItem {
105102
final hasLocation = location1 != null && location1.isNotEmpty;
106103

107104
if (hasLocation) {
108-
final bracketStyle = nonMessageStyle != null
109-
? AnsiStyle.bold + nonMessageStyle
110-
: null;
111-
final pathTextStyle = nonMessageStyle != null
112-
? AnsiStyle.italic + nonMessageStyle
113-
: null;
105+
final bracketStyle = nonMessageStyle != null ? AnsiStyle.bold + nonMessageStyle : null;
106+
final pathTextStyle = nonMessageStyle != null ? AnsiStyle.italic + nonMessageStyle : null;
114107
if (icon != null) {
115108
buffer.write('$icon ');
116109
}
@@ -127,8 +120,8 @@ final class LogItem {
127120

128121
if (message != null) {
129122
final styledMessage = message.toString().trim().withAnsiStyle(
130-
messageStyle,
131-
);
123+
messageStyle,
124+
);
132125
buffer.write(styledMessage);
133126
}
134127

@@ -149,14 +142,30 @@ final class LogItem {
149142
//
150143

151144
Map<String, dynamic> toMap() {
145+
final column = frame?.column;
146+
final library = frame?.library;
147+
final line = frame?.line;
148+
final package = frame?.package;
149+
final uri = frame?.uri.toString();
150+
152151
return {
153-
if (icon != null && (location != null && location!.isNotEmpty))
154-
'icon': icon,
155-
if (location != null && location!.isNotEmpty) 'location': location,
156-
if (message != null) 'message': message.toString(),
152+
'icon': icon != null && (location != null && location!.isNotEmpty) ? icon : null,
153+
'location': location != null && location!.isNotEmpty ? location : null,
154+
'message': () {
155+
try {
156+
return message?.toString();
157+
} catch (e) {
158+
return null;
159+
}
160+
}(),
157161
'timestamp': timestamp.toIso8601String(),
158-
if (tags.isNotEmpty) 'tags': tags.map(_unmangleSymbol).toList(),
162+
'tags': tags.isNotEmpty ? tags.map(_unmangleSymbol).toList() : null,
159163
'id': id,
164+
'column': column,
165+
'line': line,
166+
'package': package,
167+
'library': library,
168+
'uri': uri,
160169
};
161170
}
162171

@@ -166,9 +175,7 @@ final class LogItem {
166175

167176
String toJson({bool pretty = true}) {
168177
final map = toMap();
169-
final encoder = pretty
170-
? const JsonEncoder.withIndent(' ')
171-
: const JsonEncoder();
178+
final encoder = pretty ? const JsonEncoder.withIndent(' ') : const JsonEncoder();
172179
return encoder.convert(map);
173180
}
174181

pubspec.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ environment:
3434
## -----------------------------------------------------------------------------
3535

3636
dependencies:
37+
meta: ^1.16.0
3738
path: ^1.9.1
39+
stack_trace: ^1.12.1
3840
uuid: ^4.5.1
39-
meta: ^1.16.0
4041

4142
df_safer_dart: ^0.17.3
4243

0 commit comments

Comments
 (0)