Skip to content

Commit c0af779

Browse files
committed
+feat: Add metadata field, add fixes
1 parent 3677593 commit c0af779

3 files changed

Lines changed: 28 additions & 36 deletions

File tree

lib/src/log.dart

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,7 @@ final class Log {
6060
static final items = Queue<LogItem>();
6161

6262
/// If `true`, enables colors and other ANSI styling in the console output.
63-
static var enableStyling = true;
64-
65-
@Deprecated('Use "enableStyling" instead!')
66-
static bool get stylize => enableStyling;
67-
68-
@Deprecated('Use "enableStyling" instead!')
69-
static set stylize(bool value) => enableStyling = value;
63+
static var enableStyling = false;
7064

7165
/// If `true`, `Log.assert()` will be evaluated and logs will be printed
7266
/// even in release builds.
@@ -467,6 +461,7 @@ final class Log {
467461
static _LogMessage log({
468462
_IconCategory? category,
469463
Object? message,
464+
Object? metadata,
470465
AnsiStyle? messageStyle,
471466
AnsiStyle? nonMessageStyle,
472467
Set<Symbol> tags = const {},
@@ -478,6 +473,7 @@ final class Log {
478473
inReleaseMode = false;
479474
_printLog(
480475
message: message,
476+
metadata: metadata,
481477
category: category,
482478
messageStyle: messageStyle,
483479
nonMessageStyle: nonMessageStyle,
@@ -490,6 +486,7 @@ final class Log {
490486
if (inReleaseMode && enableReleaseAsserts) {
491487
_printLog(
492488
message: message,
489+
metadata: metadata,
493490
category: category,
494491
messageStyle: messageStyle,
495492
nonMessageStyle: nonMessageStyle,
@@ -509,6 +506,7 @@ final class Log {
509506
@pragma('vm:prefer-inline')
510507
static void _printLog({
511508
required Object? message,
509+
required Object? metadata,
512510
required _IconCategory? category,
513511
required AnsiStyle? messageStyle,
514512
required AnsiStyle? nonMessageStyle,
@@ -532,6 +530,7 @@ final class Log {
532530
location: location,
533531
icon: category?.icon,
534532
message: message,
533+
metadata: metadata,
535534
tags: combinedTags,
536535
showId: showIds,
537536
showTags: showTags,
@@ -600,12 +599,12 @@ String? _shortLocation(String? location, String? member) {
600599
final path = parts.first;
601600
final line = parts.last.split(':').first;
602601
final file = path.split('/').last.replaceAll('.dart', '');
603-
if (path.startsWith('package:')) {
604-
final package = path.split(':')[1].split('/').first;
605-
return '$package:$file #$line';
606-
} else {
607-
return '$file/$member #$line';
608-
}
602+
return [
603+
if (path.startsWith('package:')) '${path.split(':')[1].split('/').first}:',
604+
file,
605+
if (member != null) ...['/$member'],
606+
' #$line',
607+
].join();
609608
}
610609

611610
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

lib/src/log_item.dart

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ final class LogItem {
2525
final String? location;
2626
final String? icon;
2727
final Object? message;
28+
final Object? metadata;
2829
final Set<Symbol> tags;
2930

3031
//
@@ -43,13 +44,14 @@ final class LogItem {
4344
required this.location,
4445
required this.icon,
4546
required this.message,
47+
required this.metadata,
4648
required this.tags,
4749
required this.showId,
4850
required this.showTags,
4951
required this.showTimestamp,
5052
required this.frame,
51-
}) : id = const Uuid().v4(),
52-
timestamp = DateTime.now();
53+
}) : id = const Uuid().v4(),
54+
timestamp = DateTime.now();
5355

5456
//
5557
//
@@ -102,12 +104,10 @@ final class LogItem {
102104
final hasLocation = location1 != null && location1.isNotEmpty;
103105

104106
if (hasLocation) {
105-
final bracketStyle = nonMessageStyle != null
106-
? AnsiStyle.bold + nonMessageStyle
107-
: null;
108-
final pathTextStyle = nonMessageStyle != null
109-
? AnsiStyle.italic + nonMessageStyle
110-
: null;
107+
final bracketStyle =
108+
nonMessageStyle != null ? AnsiStyle.bold + nonMessageStyle : null;
109+
final pathTextStyle =
110+
nonMessageStyle != null ? AnsiStyle.italic + nonMessageStyle : null;
111111
if (icon != null) {
112112
buffer.write('$icon ');
113113
}
@@ -124,8 +124,8 @@ final class LogItem {
124124

125125
if (message != null) {
126126
final styledMessage = message.toString().trim().withAnsiStyle(
127-
messageStyle,
128-
);
127+
messageStyle,
128+
);
129129
buffer.write(styledMessage);
130130
}
131131

@@ -157,13 +157,7 @@ final class LogItem {
157157
? icon
158158
: null,
159159
'location': location != null && location!.isNotEmpty ? location : null,
160-
'message': () {
161-
try {
162-
return message?.toString();
163-
} catch (e) {
164-
return null;
165-
}
166-
}(),
160+
'message': message,
167161
'timestamp': timestamp.toIso8601String(),
168162
'tags': tags.isNotEmpty ? tags.map(_unmangleSymbol).toList() : null,
169163
'id': id,
@@ -181,9 +175,8 @@ final class LogItem {
181175

182176
String toJson({bool pretty = true}) {
183177
final map = toMap();
184-
final encoder = pretty
185-
? const JsonEncoder.withIndent(' ')
186-
: const JsonEncoder();
178+
final encoder =
179+
pretty ? const JsonEncoder.withIndent(' ') : const JsonEncoder();
187180
return encoder.convert(map);
188181
}
189182

pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ funding:
2020
- https://github.com/sponsors/t0mb3rr
2121

2222
description: A package that provides logging utilities for better debugging.
23-
version: 0.3.27
23+
version: 0.3.28
2424
topics:
2525
- console
2626
- debugging
@@ -37,8 +37,8 @@ environment:
3737

3838
dependencies:
3939
meta: ^1.16.0
40-
path: ^1.9.1
41-
stack_trace: ^1.12.1
40+
path: ^1.9.0
41+
stack_trace: ^1.12.0
4242
uuid: ^4.5.1
4343

4444
df_safer_dart: ^0.17.8

0 commit comments

Comments
 (0)