mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
Improved exception beautifier plugin
- Keep the raw message in another tab - Added a button to show/hide the stacktrace - Fixes Windows paths
This commit is contained in:
parent
313321e6a6
commit
c2e621e504
@ -2,28 +2,38 @@
|
||||
width: auto !important;
|
||||
}
|
||||
|
||||
.plugin-exception-beautifier .beautifier-name {
|
||||
display: block;
|
||||
font-weight: bold;
|
||||
font-size: 1.2em;
|
||||
}
|
||||
|
||||
.plugin-exception-beautifier .beautifier-message {
|
||||
display: block;
|
||||
padding: 15px 0;
|
||||
font-size: 1.1em;
|
||||
}
|
||||
|
||||
.plugin-exception-beautifier .beautifier-stacktrace-title {
|
||||
.plugin-exception-beautifier .beautifier-toggle-stacktrace {
|
||||
background: #D0D9DD;
|
||||
color: #2b3e50;
|
||||
text-decoration: none;
|
||||
display: block;
|
||||
margin-top: 15px;
|
||||
font-weight: bold;
|
||||
padding: 20px;
|
||||
-webkit-border-radius: 4px;
|
||||
-moz-border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.plugin-exception-beautifier .beautifier-toggle-stacktrace.--hidden {
|
||||
background: #ecf0f1;
|
||||
color: #2b3e50;
|
||||
}
|
||||
|
||||
.plugin-exception-beautifier .beautifier-toggle-stacktrace:hover,
|
||||
.plugin-exception-beautifier .beautifier-toggle-stacktrace.--hidden:hover {
|
||||
background: #0181b9;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.plugin-exception-beautifier .beautifier-stacktrace-line {
|
||||
display: block;
|
||||
white-space: nowrap;
|
||||
padding: 10px 0;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.plugin-exception-beautifier .beautifier-stacktrace-line:nth-child(even) {
|
||||
@ -53,6 +63,7 @@
|
||||
|
||||
.plugin-exception-beautifier .beautifier-file {
|
||||
color: #204bff;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.plugin-exception-beautifier .beautifier-line-number {
|
||||
|
@ -22,7 +22,7 @@
|
||||
internalLine: /^(#[0-9]+)\s+(\[internal function\]\s*:)(.*)/,
|
||||
defaultLine: /^(#[0-9]+)\s*(.*)/,
|
||||
className: /([a-z0-9]+\\[a-z0-9\\]+(?:\.\.\.)?)/gi,
|
||||
filePath: /((?:[A-Z]:[/\\]|\/)?[\w/\\]+\.php)(\(([0-9]+)\)|:([0-9]+))?/gi,
|
||||
filePath: /((?:[A-Z]:)?(?:[\\\/][\w\.-_~@%]+)\.(?:php|js|css|less|yaml|txt|ini))(\(([0-9]+)\)|:([0-9]+)|\s|$)/gi,
|
||||
staticCall: /::([^( ]+)\(([^()]*|(?:[^(]*\(.+\)[^)]*))\)/,
|
||||
functionCall: /->([^(]+)\(([^()]*|(?:[^(]*\(.+\)[^)]*))\)/,
|
||||
closureCall: /\{closure\}\(([^()]*|(?:[^(]*\(.+\)[^)]*))\)/
|
||||
@ -31,7 +31,8 @@
|
||||
ExceptionBeautifier.extensions = []
|
||||
|
||||
ExceptionBeautifier.prototype.init = function () {
|
||||
var self = this
|
||||
var self = this,
|
||||
markup
|
||||
|
||||
ExceptionBeautifier.extensions.forEach(function (extension) {
|
||||
if (typeof extension.onInit === 'function') {
|
||||
@ -39,13 +40,17 @@
|
||||
}
|
||||
})
|
||||
|
||||
self.$el.addClass('plugin-exception-beautifier')
|
||||
self.$el.html(self.parseSource()).find('.beautifier-message-container').addClass('form-control')
|
||||
markup = self.parseSource(self.$el.text())
|
||||
|
||||
self.$el
|
||||
.addClass('plugin-exception-beautifier')
|
||||
.empty()
|
||||
.append(markup)
|
||||
}
|
||||
|
||||
ExceptionBeautifier.prototype.parseSource = function () {
|
||||
ExceptionBeautifier.prototype.parseSource = function (raw) {
|
||||
var self = this,
|
||||
source = self.$el.text(),
|
||||
source = raw,
|
||||
markup = {lines: []},
|
||||
start = 0,
|
||||
end
|
||||
@ -57,10 +62,6 @@
|
||||
if (source.indexOf('Stack trace:') < 0) {
|
||||
source = '{exception-beautifier-message-container}{exception-beautifier-message}' + self.formatMessage(source) + '{/exception-beautifier-message}{/exception-beautifier-message-container}'
|
||||
} else {
|
||||
end = source.indexOf(':', start) + 1
|
||||
markup.name = source.substring(start, end)
|
||||
|
||||
start = end
|
||||
end = source.indexOf('Stack trace:', start)
|
||||
markup.message = source.substring(start, end)
|
||||
|
||||
@ -73,15 +74,16 @@
|
||||
markup.lines.push(self.parseLine(source.substring(start)))
|
||||
|
||||
source = '{exception-beautifier-message-container}' +
|
||||
'{exception-beautifier-name}' + markup.name + '{/exception-beautifier-name}' +
|
||||
'{exception-beautifier-message}' + self.formatMessage(markup.message) + '{/exception-beautifier-message}' +
|
||||
'{/exception-beautifier-message-container}' +
|
||||
'{exception-beautifier-stacktrace-title}Stack trace:{/exception-beautifier-stacktrace-title}'
|
||||
'{exception-beautifier-stacktrace#div}'
|
||||
|
||||
markup.lines.forEach(function (line) {
|
||||
source += '{exception-beautifier-stacktrace-line}' + self.formatStackTraceLine(line) + '{/exception-beautifier-stacktrace-line}'
|
||||
})
|
||||
|
||||
source += '{/exception-beautifier-stacktrace#div}'
|
||||
|
||||
ExceptionBeautifier.extensions.forEach(function (extension) {
|
||||
if (typeof extension.onParse === 'function') {
|
||||
extension.onParse(self)
|
||||
@ -89,7 +91,9 @@
|
||||
})
|
||||
}
|
||||
|
||||
return self.buildMarkup('{exception-beautifier-container}' + source + '{/exception-beautifier-container}')
|
||||
markup = $(self.buildMarkup('{exception-beautifier-container}' + source + '{/exception-beautifier-container}'))
|
||||
|
||||
return self.finalizeMarkup(markup, raw)
|
||||
}
|
||||
|
||||
ExceptionBeautifier.prototype.parseLine = function (str) {
|
||||
@ -117,13 +121,14 @@
|
||||
return line
|
||||
}
|
||||
|
||||
|
||||
ExceptionBeautifier.prototype.formatMessage = function (str) {
|
||||
var self = this
|
||||
|
||||
return self.formatLineCode(
|
||||
str
|
||||
.replace(/^\s+/, '')
|
||||
.replace(/\r|\n|\r\n/g, '{x-newline}')
|
||||
.replace(/\r\n|\r|\n/g, '{x-newline}')
|
||||
.replace(/\t| {2}/g, '{x-tabulation}')
|
||||
)
|
||||
}
|
||||
@ -190,7 +195,7 @@
|
||||
|
||||
str = str.replace(ExceptionBeautifier.REGEX.filePath, function (str, path, line, lineNumber, altLineNumber) {
|
||||
return self.formatFilePath(path, (lineNumber || '') + (altLineNumber || '')) +
|
||||
'{exception-beautifier-line-number}' + line + '{/exception-beautifier-line-number}'
|
||||
($.trim(line).length > 0 ? ('{exception-beautifier-line-number}' + line + '{/exception-beautifier-line-number}') : ' ')
|
||||
})
|
||||
|
||||
str = str.replace(ExceptionBeautifier.REGEX.className, function (str, name) {
|
||||
@ -271,6 +276,71 @@
|
||||
return markup
|
||||
}
|
||||
|
||||
ExceptionBeautifier.prototype.finalizeMarkup = function (markup, source) {
|
||||
var stacktrace,
|
||||
tabs
|
||||
|
||||
markup.find('.beautifier-file').each(function () {
|
||||
$(this).find('.beautifier-class').each(function () {
|
||||
var $el = $(this)
|
||||
|
||||
$el.replaceWith($el.text())
|
||||
})
|
||||
})
|
||||
|
||||
markup.find('.beautifier-file+.beautifier-line-number').each(function () {
|
||||
var $el = $(this)
|
||||
|
||||
$el.appendTo($el.prev())
|
||||
})
|
||||
|
||||
markup.find('.beautifier-message-container')
|
||||
.addClass('form-control')
|
||||
|
||||
stacktrace = markup.find('.beautifier-stacktrace')
|
||||
.addClass('hidden')
|
||||
|
||||
$('<a class="beautifier-toggle-stacktrace --hidden" href="#" data-hide-text="' + $.oc.lang.get('eventlog.hide_stacktrace') + '"><i class="icon-chevron-down"></i> <span>' + $.oc.lang.get('eventlog.show_stacktrace') + '</span></a>')
|
||||
.insertBefore(stacktrace)
|
||||
.on('click', function (event) {
|
||||
var $el = $(this)
|
||||
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
|
||||
$('.beautifier-stacktrace', markup).toggleClass('hidden')
|
||||
$el.toggleClass('--hidden')
|
||||
|
||||
if(!$el.hasClass('--hidden')) {
|
||||
if(!$el.data('show-text')) {
|
||||
$el.data('show-text', $('span', $el).html())
|
||||
}
|
||||
|
||||
$('i', $el).removeClass('icon-chevron-down').addClass('icon-chevron-up')
|
||||
$('span', $el).html($el.data('hide-text'))
|
||||
} else {
|
||||
$('i', $el).removeClass('icon-chevron-up').addClass('icon-chevron-down')
|
||||
$('span', $el).html($el.data('show-text'))
|
||||
}
|
||||
})
|
||||
|
||||
tabs = $('<div class="control-tabs content-tabs">' +
|
||||
'<ul class="nav nav-tabs">' +
|
||||
'<li class="active"><a href="#beautifier-tab-formatted">' + $.oc.lang.get('eventlog.tabs.formatted') + '</a></li>' +
|
||||
'<li><a href="#beautifier-tab-raw">' + $.oc.lang.get('eventlog.tabs.raw') + '</a></li>' +
|
||||
'</ul><div class="tab-content">' +
|
||||
'<div class="tab-pane active" id="beautifier-tab-formatted"></div>' +
|
||||
'<div class="tab-pane" id="beautifier-tab-raw"></div>' +
|
||||
'</div></div>')
|
||||
|
||||
tabs.find('#beautifier-tab-formatted').append(markup)
|
||||
tabs.find('#beautifier-tab-raw').append('<div class="form-control">' + source.replace(/\r\n|\r|\n/g, '<br>').replace(/ {2}/g, ' ') + '</div>')
|
||||
|
||||
tabs.ocTab({closable: false})
|
||||
|
||||
return tabs
|
||||
}
|
||||
|
||||
|
||||
// EXCEPTION BEAUTIFIER PLUGIN DEFINITION
|
||||
// ============================
|
||||
|
@ -22,7 +22,7 @@
|
||||
exceptionBeautfier.initEditorPopup()
|
||||
},
|
||||
onParse: function (exceptionBeautfier) {
|
||||
exceptionBeautfier.$el.on('click', 'a', function () {
|
||||
exceptionBeautfier.$el.on('click', 'a[data-href]', function () {
|
||||
exceptionBeautfier.openWithEditor($(this).data('href'))
|
||||
})
|
||||
}
|
||||
@ -33,7 +33,7 @@
|
||||
var title = $.oc.lang.get('eventlog.editor.title'),
|
||||
description = $.oc.lang.get('eventlog.editor.description'),
|
||||
openWith = $.oc.lang.get('eventlog.editor.openWith'),
|
||||
rememberChoice = $.oc.lang.get('eventlog.editor.rememberChoice'),
|
||||
rememberChoice = $.oc.lang.get('eventlog.editor.remember_choice'),
|
||||
open = $.oc.lang.get('eventlog.editor.open'),
|
||||
cancel = $.oc.lang.get('eventlog.editor.cancel'),
|
||||
popup = $(' \
|
||||
@ -120,7 +120,7 @@
|
||||
}
|
||||
|
||||
ExceptionBeautifier.prototype.rewritePath = function (path) {
|
||||
return path
|
||||
return path.replace(/\\/g, '/')
|
||||
}
|
||||
|
||||
ExceptionBeautifier.prototype.initCustomSelect = function (select) {
|
||||
|
@ -16,4 +16,4 @@ defaultRedirect: system/eventlogs
|
||||
|
||||
# Preview page
|
||||
preview:
|
||||
title: Event
|
||||
title: system::lang.event_log.preview_title
|
@ -74,6 +74,12 @@ return [
|
||||
],
|
||||
|
||||
'eventlog' => [
|
||||
'show_stacktrace' => 'Show the stacktrace',
|
||||
'hide_stacktrace' => 'Hide the stacktrace',
|
||||
'tabs' => [
|
||||
'formatted' => 'Formatted',
|
||||
'raw' => 'Raw',
|
||||
],
|
||||
'editor' => [
|
||||
'title' => 'Select the source code editor to use',
|
||||
'description' => 'Your OS environnement must be configured to listen to one of these URL schemes.',
|
||||
|
@ -310,7 +310,8 @@ return [
|
||||
'id_label' => 'Event ID',
|
||||
'created_at' => 'Date & Time',
|
||||
'message' => 'Message',
|
||||
'level' => 'Level'
|
||||
'level' => 'Level',
|
||||
'preview_title' => 'Event'
|
||||
],
|
||||
'request_log' => [
|
||||
'hint' => 'This log displays a list of browser requests that may require attention. For example, if a visitor opens a CMS page that cannot be found, a record is created with the status code 404.',
|
||||
|
@ -77,13 +77,19 @@ return [
|
||||
],
|
||||
|
||||
'eventlog' => [
|
||||
'show_stacktrace' => 'Afficher la pile d’exécution',
|
||||
'hide_stacktrace' => 'Masquer la pile d’exécution',
|
||||
'tabs' => [
|
||||
'formatted' => 'Formaté',
|
||||
'raw' => 'Message brut',
|
||||
],
|
||||
'editor' => [
|
||||
'title' => 'Sélectionnez l’éditeur de code source à utiliser',
|
||||
'description' => 'L’environnement de votre système d’exploitation doit être configuré pour ouvrir l’un des schémas d’URL ci-dessous.',
|
||||
'openWith' => 'Ouvrir avec',
|
||||
'rememberChoice' => 'Se souvenir de la sélection pour la durée de la session dans ce navigateur',
|
||||
'remember_choice' => 'Se souvenir de la sélection pour la durée de la session dans ce navigateur',
|
||||
'open' => 'Ouvrir',
|
||||
'cancel' => 'Annuler',
|
||||
'cancel' => 'Annuler'
|
||||
],
|
||||
]
|
||||
];
|
||||
|
@ -311,6 +311,7 @@ return [
|
||||
'created_at' => 'Date et heure',
|
||||
'message' => 'Message',
|
||||
'level' => 'Niveau',
|
||||
'preview_title' => 'Évènement',
|
||||
],
|
||||
'request_log' => [
|
||||
'hint' => 'Ce journal affiche une liste de requêtes potentiellement suspectes. par exemple, si un visiteur ouvre une page introuvable du CMS, une ligne avec le statut code 404 est alors créée.',
|
||||
|
Loading…
x
Reference in New Issue
Block a user