Commit 40501609 authored by Josh Nohle's avatar Josh Nohle Committed by Commit Bot

[Nearby] Minor fixes to chrome://nearby-internals logging tab

(1) Add a newline at the end of each line when saving logs file.
(2) Show logs in chronological order.
(3) Fix issue which showed "../../" at the start of every filename.
(4) Fix issue where logs extend a few pixels past the horizontal width
of the page, resulting in an overflow and making it possible to scroll
left and right.
(5) Clean up some code in the <log-object> element.
(6) Use Polymer's array mutation method for unshift, which notifies
other elements bound to the same array of the changes. This will fix the
issue of needing to refresh to page to show log changes.

Changes 1-5 mirror exactly crrev/c/2372600 and crrev/c/2383790, which
correct the issues on the analogous chrome://multidevice-internals page.

Change-Id: I3bd2d922e291f86be5533716cfac74f67c5bdd2b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2401807
Commit-Queue: Josh Nohle <nohle@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#805886}
parent 96c9b031
<style> <style>
.warning-log { :host {
padding: 3px;
}
:host(.warning-log) {
background-color: rgb(255, 252, 239); background-color: rgb(255, 252, 239);
} }
.error-log { :host(.error-log) {
background-color: rgb(255, 241, 241); background-color: rgb(255, 241, 241);
} }
.verbose-log { :host(.verbose-log) {
background-color: rgb(235, 235, 235); background-color: rgb(235, 235, 235);
} }
.default-log { :host(.default-log) {
background-color: rgb(255, 255, 255); background-color: rgb(255, 255, 255);
} }
#item-metadata { #log-container {
color: #888; color: #888;
display: flex; display: flex;
font-size: 10px; font-size: 10px;
...@@ -28,17 +32,15 @@ ...@@ -28,17 +32,15 @@
#text { #text {
display: inline-block; display: inline-block;
margin: 3px; text-align: start;
padding: 5px;
text-align: left;
width: 100%; width: 100%;
} }
</style> </style>
<div id="item" severity="[[item.severity]]"> <div>
<p id="text">[[item.text]]</p> <p id="text">[[logMessage.text]]</p>
<div id="item-metadata"> <div id="log-container">
<span>[[item.time]]</span> <span>[[logMessage.time]]</span>
<div id="flex"></div> <div id="flex"></div>
<span>[[item.file]]:[[item.line]]</span> <span>[[getFilenameWithLine_(logMessage.file, logMessage.line)]]</span>
</div> </div>
</div> </div>
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; import {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {Severity} from './types.js'; import {LogMessage, Severity} from './types.js';
Polymer({ Polymer({
is: 'log-object', is: 'log-object',
...@@ -12,13 +12,12 @@ Polymer({ ...@@ -12,13 +12,12 @@ Polymer({
properties: { properties: {
/** /**
* Underlying LogMessage data for this item. Contains read-only fields * Log whose metadata is displayed within this element.
* from the NearbyShare backend, as well as fields computed by logging tab. * @type {!LogMessage}
* Type: {!LogMessage}
*/ */
item: { logMessage: {
type: Object, type: Object,
observer: 'itemChanged_', observer: 'logMessageChanged_',
}, },
}, },
...@@ -26,20 +25,34 @@ Polymer({ ...@@ -26,20 +25,34 @@ Polymer({
* Sets the log message style based on severity level. * Sets the log message style based on severity level.
* @private * @private
*/ */
itemChanged_() { logMessageChanged_() {
switch (this.item.severity) { switch (this.logMessage.severity) {
case Severity.WARNING: case Severity.WARNING:
this.$['item'].className = 'warning-log'; this.className = 'warning-log';
break; break;
case Severity.ERROR: case Severity.ERROR:
this.$['item'].className = 'error-log'; this.className = 'error-log';
break; break;
case Severity.VERBOSE: case Severity.VERBOSE:
this.$['item'].className = 'verbose-log'; this.className = 'verbose-log';
break; break;
default: default:
this.$['item'].className = 'default-log'; this.className = 'default-log';
break; break;
} }
}, },
/**
* @return {string}
* @private
*/
getFilenameWithLine_() {
if (!this.logMessage) {
return '';
}
// The filename is prefixed with "../../", so replace it with "//".
const filename = this.logMessage.file.replace('../../', '//');
return filename + ':' + this.logMessage.line;
},
}); });
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
</cr-button> </cr-button>
<iron-list items="[[logList_]]" as="log" id="logs-list"> <iron-list items="[[logList_]]" as="log" id="logs-list">
<template> <template>
<log-object item="[[log]]"> <log-object log-message="[[log]]">
</log-object> </log-object>
</template> </template>
</iron-list> </iron-list>
...@@ -39,7 +39,7 @@ function logToSavedString_(log) { ...@@ -39,7 +39,7 @@ function logToSavedString_(log) {
// Reduce the file path to just the file name for logging simplification. // Reduce the file path to just the file name for logging simplification.
const file = log.file.substring(log.file.lastIndexOf('/') + 1); const file = log.file.substring(log.file.lastIndexOf('/') + 1);
return `[${log.time} ${severity} ${file} (${log.line})] ${log.text}`; return `[${log.time} ${severity} ${file} (${log.line})] ${log.text}\n`;
} }
Polymer({ Polymer({
...@@ -120,10 +120,12 @@ Polymer({ ...@@ -120,10 +120,12 @@ Polymer({
/** /**
* Iterates through log messages in |logList_| and prepares them for download. * Iterates through log messages in |logList_| and prepares them for download.
* @private * @private
* @return * @return {!Array<string>}
*/ */
getSerializedLogStrings_() { getSerializedLogStrings_() {
return this.logList_.map(logToSavedString_); // Reverse the logs so that the oldest logs appear first and the newest logs
// appear last.
return this.logList_.map(logToSavedString_).reverse();
}, },
/** /**
...@@ -133,7 +135,7 @@ Polymer({ ...@@ -133,7 +135,7 @@ Polymer({
* @private * @private
*/ */
onLogMessageAdded_(log) { onLogMessageAdded_(log) {
this.logList_.unshift(log); this.unshift('logList_', log);
}, },
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment