Skip to content

Commit b094b07

Browse files
committed
+feat: Shorten the location string in logs for cleaner output
1 parent 4246684 commit b094b07

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,4 @@ If you're enjoying this package and find it valuable, consider showing your appr
172172
## License
173173

174174
This project is released under the [MIT License](https://raw.githubusercontent.com/dev-cetera/df_log/main/LICENSE). See [LICENSE](https://raw.githubusercontent.com/dev-cetera/df_log/main/LICENSE) for more information.
175+

lib/src/log.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ final class Log {
522522
// Maybe get the basepath.
523523
String? location;
524524
if (includePath) {
525-
location = Here(initialStackLevel).location.orNull();
525+
location = _shortenedLocation(Here(initialStackLevel).location.orNull());
526526
}
527527

528528
// Combine tags with the tag from category.
@@ -578,6 +578,19 @@ typedef Glog = Log;
578578

579579
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
580580

581+
String? _shortenedLocation(String? location) {
582+
if (location == null) {
583+
return null;
584+
}
585+
// Remove 'package:' prefix
586+
var cleaned = location.replaceFirst(RegExp(r'^package:[^\/]+\/'), '');
587+
// Remove column number (e.g., ':123' at the end)
588+
cleaned = cleaned.replaceFirst(RegExp(r':\d+$'), '');
589+
return cleaned.trim();
590+
}
591+
592+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
593+
581594
enum _IconCategory {
582595
//
583596
//

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ repository: https://github.com/robmllze/df_log
1616
funding:
1717
- https://www.buymeacoffee.com/dev_cetera
1818
description: A package that provides logging utilities for better debugging.
19-
version: 0.3.14
19+
version: 0.3.15
2020
topics:
2121
- console
2222
- debugging

0 commit comments

Comments
 (0)