Merge #2111 from gasi: Autofix: Move Debug Logs From GitHub Gists to debuglogs.org
- [x] Apply ESLint autofixes in preparation of changes to debug log publish change.
- [x] Remove now unnecessary `/* eslint-env browser */` directives from some files. This is now part of our per-folder ESLint configuration.
Manual changes: 77cc9b61c9..0cf64f5083
This commit is contained in:
commit
770e4ac96b
5 changed files with 110 additions and 106 deletions
|
@ -16,9 +16,11 @@ test/views/*.js
|
||||||
|
|
||||||
# ES2015+ files
|
# ES2015+ files
|
||||||
!js/background.js
|
!js/background.js
|
||||||
|
!js/logging.js
|
||||||
!js/models/conversations.js
|
!js/models/conversations.js
|
||||||
!js/views/attachment_view.js
|
!js/views/attachment_view.js
|
||||||
!js/views/conversation_search_view.js
|
!js/views/conversation_search_view.js
|
||||||
|
!js/views/debug_log_view.js
|
||||||
!js/views/file_input_view.js
|
!js/views/file_input_view.js
|
||||||
!js/views/inbox_view.js
|
!js/views/inbox_view.js
|
||||||
!main.js
|
!main.js
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
|
|
||||||
/* eslint-env browser */
|
|
||||||
|
|
||||||
/* global Backbone: false */
|
/* global Backbone: false */
|
||||||
/* global $: false */
|
/* global $: false */
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,10 @@
|
||||||
|
/* eslint-env node */
|
||||||
|
|
||||||
|
/* eslint strict: ['error', 'never'] */
|
||||||
|
|
||||||
|
/* global $: false */
|
||||||
|
/* global textsecure: false */
|
||||||
|
|
||||||
const electron = require('electron');
|
const electron = require('electron');
|
||||||
const bunyan = require('bunyan');
|
const bunyan = require('bunyan');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
@ -23,13 +30,14 @@ const LEVELS = {
|
||||||
// Backwards-compatible logging, simple strings and no level (defaulted to INFO)
|
// Backwards-compatible logging, simple strings and no level (defaulted to INFO)
|
||||||
|
|
||||||
function redactPhone(text) {
|
function redactPhone(text) {
|
||||||
return text.replace(PHONE_REGEX, "+[REDACTED]$1");
|
return text.replace(PHONE_REGEX, '+[REDACTED]$1');
|
||||||
}
|
}
|
||||||
|
|
||||||
function redactGroup(text) {
|
function redactGroup(text) {
|
||||||
return text.replace(GROUP_REGEX, function(match, before, id, after) {
|
return text.replace(
|
||||||
return before + '[REDACTED]' + id.slice(-3) + after;
|
GROUP_REGEX,
|
||||||
});
|
(match, before, id, after) => `${before}[REDACTED]${id.slice(-3)}${after}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function now() {
|
function now() {
|
||||||
|
@ -37,19 +45,16 @@ function now() {
|
||||||
return date.toJSON();
|
return date.toJSON();
|
||||||
}
|
}
|
||||||
|
|
||||||
function log() {
|
function log(...args) {
|
||||||
const args = Array.prototype.slice.call(arguments, 0);
|
|
||||||
|
|
||||||
const consoleArgs = ['INFO ', now()].concat(args);
|
const consoleArgs = ['INFO ', now()].concat(args);
|
||||||
console._log.apply(console, consoleArgs);
|
console._log(...consoleArgs);
|
||||||
|
|
||||||
// To avoid [Object object] in our log since console.log handles non-strings smoothly
|
// To avoid [Object object] in our log since console.log handles non-strings smoothly
|
||||||
const str = args.map(function(item) {
|
const str = args.map((item) => {
|
||||||
if (typeof item !== 'string') {
|
if (typeof item !== 'string') {
|
||||||
try {
|
try {
|
||||||
return JSON.stringify(item);
|
return JSON.stringify(item);
|
||||||
}
|
} catch (error) {
|
||||||
catch (e) {
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,14 +76,14 @@ if (window.console) {
|
||||||
function getHeader() {
|
function getHeader() {
|
||||||
let header = window.navigator.userAgent;
|
let header = window.navigator.userAgent;
|
||||||
|
|
||||||
header += ' node/' + window.config.node_version;
|
header += ` node/${window.config.node_version}`;
|
||||||
header += ' env/' + window.config.environment;
|
header += ` env/${window.config.environment}`;
|
||||||
|
|
||||||
return header;
|
return header;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLevel(level) {
|
function getLevel(level) {
|
||||||
var text = LEVELS[level];
|
const text = LEVELS[level];
|
||||||
if (!text) {
|
if (!text) {
|
||||||
return BLANK_LEVEL;
|
return BLANK_LEVEL;
|
||||||
}
|
}
|
||||||
|
@ -87,7 +92,7 @@ function getLevel(level) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatLine(entry) {
|
function formatLine(entry) {
|
||||||
return getLevel(entry.level) + ' ' + entry.time + ' ' + entry.msg;
|
return `${getLevel(entry.level)} ${entry.time} ${entry.msg}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function format(entries) {
|
function format(entries) {
|
||||||
|
@ -95,30 +100,31 @@ function format(entries) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetch() {
|
function fetch() {
|
||||||
return new Promise(function(resolve) {
|
return new Promise((resolve) => {
|
||||||
ipc.send('fetch-log');
|
ipc.send('fetch-log');
|
||||||
|
|
||||||
ipc.on('fetched-log', function(event, text) {
|
ipc.on('fetched-log', (event, text) => {
|
||||||
var result = getHeader() + '\n' + format(text);
|
const result = `${getHeader()}\n${format(text)}`;
|
||||||
resolve(result);
|
resolve(result);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function publish(log) {
|
function publish(rawContent) {
|
||||||
log = log || fetch();
|
const content = rawContent || fetch();
|
||||||
|
|
||||||
return new Promise(function(resolve) {
|
return new Promise((resolve) => {
|
||||||
const payload = textsecure.utils.jsonThing({
|
const payload = textsecure.utils.jsonThing({
|
||||||
files: {
|
files: {
|
||||||
'debugLog.txt': {
|
'debugLog.txt': {
|
||||||
content: log
|
content,
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// eslint-disable-next-line more/no-then
|
||||||
$.post('https://api.github.com/gists', payload)
|
$.post('https://api.github.com/gists', payload)
|
||||||
.then(function(response) {
|
.then((response) => {
|
||||||
console._log('Posted debug log to ', response.html_url);
|
console._log('Posted debug log to ', response.html_url);
|
||||||
resolve(response.html_url);
|
resolve(response.html_url);
|
||||||
})
|
})
|
||||||
|
@ -136,22 +142,19 @@ const logger = bunyan.createLogger({
|
||||||
streams: [{
|
streams: [{
|
||||||
level: 'debug',
|
level: 'debug',
|
||||||
stream: {
|
stream: {
|
||||||
write: function(entry) {
|
write(entry) {
|
||||||
console._log(formatLine(JSON.parse(entry)));
|
console._log(formatLine(JSON.parse(entry)));
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}]
|
}],
|
||||||
});
|
});
|
||||||
|
|
||||||
// The Bunyan API: https://github.com/trentm/node-bunyan#log-method-api
|
// The Bunyan API: https://github.com/trentm/node-bunyan#log-method-api
|
||||||
function logAtLevel() {
|
function logAtLevel(level, ...args) {
|
||||||
const level = arguments[0];
|
const ipcArgs = [`log-${level}`].concat(args);
|
||||||
const args = Array.prototype.slice.call(arguments, 1);
|
ipc.send(...ipcArgs);
|
||||||
|
|
||||||
const ipcArgs = ['log-' + level].concat(args);
|
logger[level](...args);
|
||||||
ipc.send.apply(ipc, ipcArgs);
|
|
||||||
|
|
||||||
logger[level].apply(logger, args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
window.log = {
|
window.log = {
|
||||||
|
@ -165,11 +168,11 @@ window.log = {
|
||||||
publish,
|
publish,
|
||||||
};
|
};
|
||||||
|
|
||||||
window.onerror = function(message, script, line, col, error) {
|
window.onerror = (message, script, line, col, error) => {
|
||||||
const errorInfo = error && error.stack ? error.stack : JSON.stringify(error);
|
const errorInfo = error && error.stack ? error.stack : JSON.stringify(error);
|
||||||
window.log.error('Top-level unhandled error: ' + errorInfo);
|
window.log.error(`Top-level unhandled error: ${errorInfo}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addEventListener('unhandledrejection', function(rejectionEvent) {
|
window.addEventListener('unhandledrejection', (rejectionEvent) => {
|
||||||
window.log.error('Top-level unhandled promise rejection: ' + rejectionEvent.reason);
|
window.log.error(`Top-level unhandled promise rejection: ${rejectionEvent.reason}`);
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
/* eslint-env browser */
|
|
||||||
|
|
||||||
/* global $: false */
|
/* global $: false */
|
||||||
/* global _: false */
|
/* global _: false */
|
||||||
/* global Backbone: false */
|
/* global Backbone: false */
|
||||||
|
|
|
@ -1,66 +1,69 @@
|
||||||
/*
|
/* global i18n: false */
|
||||||
* vim: ts=4:sw=4:expandtab
|
/* global Whisper: false */
|
||||||
*/
|
|
||||||
|
// eslint-disable-next-line func-names
|
||||||
(function () {
|
(function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
window.Whisper = window.Whisper || {};
|
|
||||||
|
|
||||||
Whisper.DebugLogLinkView = Whisper.View.extend({
|
window.Whisper = window.Whisper || {};
|
||||||
templateName: 'debug-log-link',
|
|
||||||
initialize: function(options) {
|
|
||||||
this.url = options.url;
|
|
||||||
},
|
|
||||||
render_attributes: function() {
|
|
||||||
return {
|
|
||||||
url: this.url,
|
|
||||||
reportIssue: i18n('reportIssue')
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Whisper.DebugLogView = Whisper.View.extend({
|
|
||||||
templateName: 'debug-log',
|
|
||||||
className: 'debug-log modal',
|
|
||||||
initialize: function() {
|
|
||||||
this.render();
|
|
||||||
this.$('textarea').val(i18n('loading'));
|
|
||||||
|
|
||||||
window.log.fetch().then(function(text) {
|
Whisper.DebugLogLinkView = Whisper.View.extend({
|
||||||
this.$('textarea').val(text);
|
templateName: 'debug-log-link',
|
||||||
}.bind(this));
|
initialize(options) {
|
||||||
},
|
this.url = options.url;
|
||||||
events: {
|
},
|
||||||
'click .submit': 'submit',
|
render_attributes() {
|
||||||
'click .close': 'close'
|
return {
|
||||||
},
|
url: this.url,
|
||||||
render_attributes: {
|
reportIssue: i18n('reportIssue'),
|
||||||
title: i18n('submitDebugLog'),
|
};
|
||||||
cancel: i18n('cancel'),
|
},
|
||||||
submit: i18n('submit'),
|
});
|
||||||
close: i18n('gotIt'),
|
Whisper.DebugLogView = Whisper.View.extend({
|
||||||
debugLogExplanation: i18n('debugLogExplanation')
|
templateName: 'debug-log',
|
||||||
},
|
className: 'debug-log modal',
|
||||||
close: function(e) {
|
initialize() {
|
||||||
e.preventDefault();
|
this.render();
|
||||||
this.remove();
|
this.$('textarea').val(i18n('loading'));
|
||||||
},
|
|
||||||
submit: function(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
var text = this.$('textarea').val();
|
|
||||||
if (text.length === 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
log.publish(text).then(function(url) {
|
|
||||||
var view = new Whisper.DebugLogLinkView({
|
|
||||||
url: url,
|
|
||||||
el: this.$('.result')
|
|
||||||
});
|
|
||||||
this.$('.loading').removeClass('loading');
|
|
||||||
view.render();
|
|
||||||
this.$('.link').focus().select();
|
|
||||||
}.bind(this));
|
|
||||||
this.$('.buttons, textarea').remove();
|
|
||||||
this.$('.result').addClass('loading');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
})();
|
// eslint-disable-next-line more/no-then
|
||||||
|
window.log.fetch().then((text) => {
|
||||||
|
this.$('textarea').val(text);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
events: {
|
||||||
|
'click .submit': 'submit',
|
||||||
|
'click .close': 'close',
|
||||||
|
},
|
||||||
|
render_attributes: {
|
||||||
|
title: i18n('submitDebugLog'),
|
||||||
|
cancel: i18n('cancel'),
|
||||||
|
submit: i18n('submit'),
|
||||||
|
close: i18n('gotIt'),
|
||||||
|
debugLogExplanation: i18n('debugLogExplanation'),
|
||||||
|
},
|
||||||
|
close(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
this.remove();
|
||||||
|
},
|
||||||
|
submit(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
const text = this.$('textarea').val();
|
||||||
|
if (text.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line more/no-then
|
||||||
|
window.log.publish(text).then((url) => {
|
||||||
|
const view = new Whisper.DebugLogLinkView({
|
||||||
|
url,
|
||||||
|
el: this.$('.result'),
|
||||||
|
});
|
||||||
|
this.$('.loading').removeClass('loading');
|
||||||
|
view.render();
|
||||||
|
this.$('.link').focus().select();
|
||||||
|
});
|
||||||
|
this.$('.buttons, textarea').remove();
|
||||||
|
this.$('.result').addClass('loading');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue