OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /// This library provides a single function called injectLogs which when called | 5 /// This library provides a single function called injectLogs which when called |
6 /// will request a logs json file and build a small widget out of them which | 6 /// will request a logs json file and build a small widget out of them which |
7 /// groups the logs by level. | 7 /// groups the logs by level. |
8 library polymer.build.log_injector; | 8 library polymer.build.log_injector; |
9 | 9 |
10 import 'dart:async'; | |
11 import 'dart:convert'; | 10 import 'dart:convert'; |
12 import 'dart:html'; | 11 import 'dart:html'; |
13 | 12 |
14 import 'package:path/path.dart' as path; | |
15 import 'package:source_span/source_span.dart'; | 13 import 'package:source_span/source_span.dart'; |
16 import 'package:dev_compiler/src/summary.dart'; | 14 import 'package:dev_compiler/src/summary.dart'; |
17 | 15 |
18 main() async { | 16 main() async { |
19 await window.animationFrame; | 17 await window.animationFrame; |
20 displayMessages(await HttpRequest.getString('messages.json')); | 18 displayMessages(await HttpRequest.getString('messages.json')); |
21 } | 19 } |
22 | 20 |
23 void displayMessages(String data) { | 21 void displayMessages(String data) { |
24 var summary = GlobalSummary.parse(JSON.decode(data)); | 22 var summary = GlobalSummary.parse(JSON.decode(data)); |
(...skipping 29 matching lines...) Expand all Loading... |
54 var message = _hyperlinkUrls(_escape(m.message)); | 52 var message = _hyperlinkUrls(_escape(m.message)); |
55 var span = m.span; | 53 var span = m.span; |
56 var sb = new StringBuffer(); | 54 var sb = new StringBuffer(); |
57 sb.write('<div class="message"><div class="text $level">$message</div>'); | 55 sb.write('<div class="message"><div class="text $level">$message</div>'); |
58 if (span != null) { | 56 if (span != null) { |
59 sb.write('<div class="location">' | 57 sb.write('<div class="location">' |
60 ' <span class="location">${span.start.toolString}</span></div>' | 58 ' <span class="location">${span.start.toolString}</span></div>' |
61 ' <span class="text">'); | 59 ' <span class="text">'); |
62 if (span is SourceSpanWithContext) { | 60 if (span is SourceSpanWithContext) { |
63 var context = span.context; | 61 var context = span.context; |
64 var text = span.text; | |
65 sb.write(_escape(context.substring(0, span.start.column))); | 62 sb.write(_escape(context.substring(0, span.start.column))); |
66 sb.write('<span class="$level">'); | 63 sb.write('<span class="$level">'); |
67 sb.write(_escape(span.text)); | 64 sb.write(_escape(span.text)); |
68 sb.write('</span>'); | 65 sb.write('</span>'); |
69 sb.write(_escape(context.substring(span.end.column))); | 66 sb.write(_escape(context.substring(span.end.column))); |
70 } else { | 67 } else { |
71 sb.write(_escape(span.text)); | 68 sb.write(_escape(span.text)); |
72 } | 69 } |
73 sb.write('</span></div></div>'); | 70 sb.write('</span></div></div>'); |
74 } | 71 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 class _Visitor extends RecursiveSummaryVisitor { | 123 class _Visitor extends RecursiveSummaryVisitor { |
127 final Map<String, List<MessageSummary>> messagesByLevel = {}; | 124 final Map<String, List<MessageSummary>> messagesByLevel = {}; |
128 | 125 |
129 @override | 126 @override |
130 void visitMessage(MessageSummary message) { | 127 void visitMessage(MessageSummary message) { |
131 var level = message.level.toLowerCase(); | 128 var level = message.level.toLowerCase(); |
132 messagesByLevel.putIfAbsent(level, () => []); | 129 messagesByLevel.putIfAbsent(level, () => []); |
133 messagesByLevel[level].add(message); | 130 messagesByLevel[level].add(message); |
134 } | 131 } |
135 } | 132 } |
OLD | NEW |