Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(521)

Unified Diff: lib/logging.dart

Issue 1132533003: Add option to automatically record stack trace in logging (fixes #2) (Closed) Base URL: https://github.com/dart-lang/logging@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/logging.dart
diff --git a/lib/logging.dart b/lib/logging.dart
index 7654885721b1bf3c86dd7ff054b7f9f560313341..70c776b2f8bc610a03e0464f40e8b872f1c277aa 100644
--- a/lib/logging.dart
+++ b/lib/logging.dart
@@ -16,6 +16,12 @@ import 'dart:collection';
bool hierarchicalLoggingEnabled = false;
/**
+ * Automatically record stack traces for any message of this level or above.
+ * Because this is expensive, this is off by default.
+ */
+Level recordStackTraceAtLevel = Level.OFF;
+
+/**
* Level for the root-logger. This will be the level of all loggers if
* [hierarchicalLoggingEnabled] is false.
*/
@@ -147,11 +153,15 @@ class Logger {
void log(Level logLevel, message,
[Object error, StackTrace stackTrace, Zone zone]) {
if (isLoggable(logLevel)) {
- // If message is a Function, evaluate it.
if (message is Function) message = message();
- // If message is still not a String, call toString().
if (message is! String) message = message.toString();
- // Only record the current zone if it was not given.
+ if (stackTrace == null && logLevel >= recordStackTraceAtLevel) {
+ try {
+ throw "log stack trace";
Jennifer Messerly 2015/05/07 22:32:19 include message here? e.g. throw "log ${logLe
Siggi Cherem (dart-lang) 2015/05/08 00:31:03 Good point. Done.
+ } catch (e, t) {
+ stackTrace = t;
+ }
+ }
if (zone == null) zone = Zone.current;
var record =
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698