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
|
||||
!js/background.js
|
||||
!js/logging.js
|
||||
!js/models/conversations.js
|
||||
!js/views/attachment_view.js
|
||||
!js/views/conversation_search_view.js
|
||||
!js/views/debug_log_view.js
|
||||
!js/views/file_input_view.js
|
||||
!js/views/inbox_view.js
|
||||
!main.js
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
/* eslint-disable */
|
||||
|
||||
/* eslint-env browser */
|
||||
|
||||
/* global Backbone: false */
|
||||
/* global $: false */
|
||||
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
/* eslint-env node */
|
||||
|
||||
/* eslint strict: ['error', 'never'] */
|
||||
|
||||
/* global $: false */
|
||||
/* global textsecure: false */
|
||||
|
||||
const electron = require('electron');
|
||||
const bunyan = require('bunyan');
|
||||
const _ = require('lodash');
|
||||
|
@ -23,13 +30,14 @@ const LEVELS = {
|
|||
// Backwards-compatible logging, simple strings and no level (defaulted to INFO)
|
||||
|
||||
function redactPhone(text) {
|
||||
return text.replace(PHONE_REGEX, "+[REDACTED]$1");
|
||||
return text.replace(PHONE_REGEX, '+[REDACTED]$1');
|
||||
}
|
||||
|
||||
function redactGroup(text) {
|
||||
return text.replace(GROUP_REGEX, function(match, before, id, after) {
|
||||
return before + '[REDACTED]' + id.slice(-3) + after;
|
||||
});
|
||||
return text.replace(
|
||||
GROUP_REGEX,
|
||||
(match, before, id, after) => `${before}[REDACTED]${id.slice(-3)}${after}`
|
||||
);
|
||||
}
|
||||
|
||||
function now() {
|
||||
|
@ -37,19 +45,16 @@ function now() {
|
|||
return date.toJSON();
|
||||
}
|
||||
|
||||
function log() {
|
||||
const args = Array.prototype.slice.call(arguments, 0);
|
||||
|
||||
function log(...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
|
||||
const str = args.map(function(item) {
|
||||
const str = args.map((item) => {
|
||||
if (typeof item !== 'string') {
|
||||
try {
|
||||
return JSON.stringify(item);
|
||||
}
|
||||
catch (e) {
|
||||
} catch (error) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
@ -71,14 +76,14 @@ if (window.console) {
|
|||
function getHeader() {
|
||||
let header = window.navigator.userAgent;
|
||||
|
||||
header += ' node/' + window.config.node_version;
|
||||
header += ' env/' + window.config.environment;
|
||||
header += ` node/${window.config.node_version}`;
|
||||
header += ` env/${window.config.environment}`;
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
function getLevel(level) {
|
||||
var text = LEVELS[level];
|
||||
const text = LEVELS[level];
|
||||
if (!text) {
|
||||
return BLANK_LEVEL;
|
||||
}
|
||||
|
@ -87,7 +92,7 @@ function getLevel(level) {
|
|||
}
|
||||
|
||||
function formatLine(entry) {
|
||||
return getLevel(entry.level) + ' ' + entry.time + ' ' + entry.msg;
|
||||
return `${getLevel(entry.level)} ${entry.time} ${entry.msg}`;
|
||||
}
|
||||
|
||||
function format(entries) {
|
||||
|
@ -95,30 +100,31 @@ function format(entries) {
|
|||
}
|
||||
|
||||
function fetch() {
|
||||
return new Promise(function(resolve) {
|
||||
return new Promise((resolve) => {
|
||||
ipc.send('fetch-log');
|
||||
|
||||
ipc.on('fetched-log', function(event, text) {
|
||||
var result = getHeader() + '\n' + format(text);
|
||||
ipc.on('fetched-log', (event, text) => {
|
||||
const result = `${getHeader()}\n${format(text)}`;
|
||||
resolve(result);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function publish(log) {
|
||||
log = log || fetch();
|
||||
function publish(rawContent) {
|
||||
const content = rawContent || fetch();
|
||||
|
||||
return new Promise(function(resolve) {
|
||||
return new Promise((resolve) => {
|
||||
const payload = textsecure.utils.jsonThing({
|
||||
files: {
|
||||
'debugLog.txt': {
|
||||
content: log
|
||||
}
|
||||
}
|
||||
content,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// eslint-disable-next-line more/no-then
|
||||
$.post('https://api.github.com/gists', payload)
|
||||
.then(function(response) {
|
||||
.then((response) => {
|
||||
console._log('Posted debug log to ', response.html_url);
|
||||
resolve(response.html_url);
|
||||
})
|
||||
|
@ -136,22 +142,19 @@ const logger = bunyan.createLogger({
|
|||
streams: [{
|
||||
level: 'debug',
|
||||
stream: {
|
||||
write: function(entry) {
|
||||
write(entry) {
|
||||
console._log(formatLine(JSON.parse(entry)));
|
||||
}
|
||||
}
|
||||
}]
|
||||
},
|
||||
},
|
||||
}],
|
||||
});
|
||||
|
||||
// The Bunyan API: https://github.com/trentm/node-bunyan#log-method-api
|
||||
function logAtLevel() {
|
||||
const level = arguments[0];
|
||||
const args = Array.prototype.slice.call(arguments, 1);
|
||||
function logAtLevel(level, ...args) {
|
||||
const ipcArgs = [`log-${level}`].concat(args);
|
||||
ipc.send(...ipcArgs);
|
||||
|
||||
const ipcArgs = ['log-' + level].concat(args);
|
||||
ipc.send.apply(ipc, ipcArgs);
|
||||
|
||||
logger[level].apply(logger, args);
|
||||
logger[level](...args);
|
||||
}
|
||||
|
||||
window.log = {
|
||||
|
@ -165,11 +168,11 @@ window.log = {
|
|||
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);
|
||||
window.log.error('Top-level unhandled error: ' + errorInfo);
|
||||
window.log.error(`Top-level unhandled error: ${errorInfo}`);
|
||||
};
|
||||
|
||||
window.addEventListener('unhandledrejection', function(rejectionEvent) {
|
||||
window.log.error('Top-level unhandled promise rejection: ' + rejectionEvent.reason);
|
||||
window.addEventListener('unhandledrejection', (rejectionEvent) => {
|
||||
window.log.error(`Top-level unhandled promise rejection: ${rejectionEvent.reason}`);
|
||||
});
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
/* eslint-env browser */
|
||||
|
||||
/* global $: false */
|
||||
/* global _: false */
|
||||
/* global Backbone: false */
|
||||
|
|
|
@ -1,66 +1,69 @@
|
|||
/*
|
||||
* vim: ts=4:sw=4:expandtab
|
||||
*/
|
||||
/* global i18n: false */
|
||||
/* global Whisper: false */
|
||||
|
||||
// eslint-disable-next-line func-names
|
||||
(function () {
|
||||
'use strict';
|
||||
window.Whisper = window.Whisper || {};
|
||||
'use strict';
|
||||
|
||||
Whisper.DebugLogLinkView = Whisper.View.extend({
|
||||
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.Whisper = window.Whisper || {};
|
||||
|
||||
window.log.fetch().then(function(text) {
|
||||
this.$('textarea').val(text);
|
||||
}.bind(this));
|
||||
},
|
||||
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: function(e) {
|
||||
e.preventDefault();
|
||||
this.remove();
|
||||
},
|
||||
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');
|
||||
}
|
||||
});
|
||||
Whisper.DebugLogLinkView = Whisper.View.extend({
|
||||
templateName: 'debug-log-link',
|
||||
initialize(options) {
|
||||
this.url = options.url;
|
||||
},
|
||||
render_attributes() {
|
||||
return {
|
||||
url: this.url,
|
||||
reportIssue: i18n('reportIssue'),
|
||||
};
|
||||
},
|
||||
});
|
||||
Whisper.DebugLogView = Whisper.View.extend({
|
||||
templateName: 'debug-log',
|
||||
className: 'debug-log modal',
|
||||
initialize() {
|
||||
this.render();
|
||||
this.$('textarea').val(i18n('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