Apex Log Indenter - Add indents to Apex logs files to make them easier to read and navigate.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Responsible for producing the first half of the page all the way up to but | |
* not including the output. All of the elements produced by this function | |
* serve display purposes and input purposes. | |
* @param data {Object} | |
* An object mainly representing the input data. | |
* @returns {Array=} | |
* An array of objects that represent the elements that will be shown in the | |
* input section of the page. If nothing is returned, the input section will | |
* not be updated | |
*/ | |
function getInputs(data) { | |
return [ | |
{ type: 'uploadable-text', id: 'txtContents', rows: 20 }, | |
{ | |
type: 'div', | |
className: 'text-center', | |
children: [ | |
{ | |
type: 'button', | |
text: 'Indent', | |
disabled: !data.valuesById.txtContents, | |
id: 'btnIndent' | |
} | |
] | |
} | |
]; | |
} | |
/** | |
* Responsible for producing the second half of the page which starts after the | |
* input section and goes to the end of the page. All of the elements produced | |
* by this function only serve display purposes. | |
* @param data {Object} | |
* An object mainly representing the input data. | |
* @returns {Array=} | |
* An array of objects that represent the elements that will be shown in the | |
* output section of the page. If nothing is returned, the output section | |
* will not be updated. | |
*/ | |
function getOutputs(data) { | |
if (data.clickedButtonId === 'btnIndent') { | |
return [ | |
{ | |
type: 'downloadable-text', | |
value: indentApexLog(data.valuesById.txtContents), | |
rows: 20, | |
downloadName: (data.filesById.txtContents || {}).name || 'download.txt' | |
} | |
]; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Used by indentApexLog() to figure out when indentation should start and end. | |
var RGX_HEADER = /^[\d:\.]+\s*\(\w+\)\|(?:(CODE_UNIT_STARTED|\w+_ENTRY)|(CODE_UNIT_FINISHED|\w+_EXIT))\|/; | |
/** | |
* Indents the specified contents of an Apex file to make it easier to navigate | |
* within an IDE that has a tree-view whenever indentation is added. | |
* @param contents {string} | |
* The contents of the Apex log file. | |
* @returns {string} | |
* The contents with proper indentation whenever code units start and end and | |
* whenever other things have an ENTRY and an EXIT. | |
*/ | |
function indentApexLog(contents) { | |
var indentation = ""; | |
return contents.split(/\r?\n|\r/).map(function(line) { | |
var m = RGX_HEADER.exec(line) || []; | |
if (m[2]) { | |
indentation = indentation.slice(1) | |
} | |
line = indentation + line; | |
if (m[1]) { | |
indentation += "\t"; | |
} | |
return line; | |
}).join('\n'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Every YourJS IO App must be able to either find index.json or index.jsonc in the Gist. | |
{ | |
"title": "Apex Log Indenter", | |
"description": "Add indents to Apex logs files to make them easier to read and navigate.", | |
"js": [ | |
"<io-app> apex-log-indenter.js", | |
"indentApexLog.js" | |
], | |
"css": [] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// Name of the function responsable for transforming the input into the output. | |
"transform": "indentApexLog", | |
// Where to find the code that will be eval'd. | |
"files": ["indentApexLog.js"], | |
// Input setup | |
"input": { "label": "Log File Contents" }, | |
// Output setup | |
"output": { "label": "Formatted Log File Contents" }, | |
// Type of YourJS IO-App | |
"type": "split" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is the IO App:
https://www.yourjs.com/gist-io/088682af25f978c08aaf303ac8c95f40