Creates new instance of TadConsole class.
Instantiation creates a new file the object can save itself to as JSON.
This JSON structure along with some additional logging options and meta-data provides
an option a little more advanced than the standard console.log("foo")
option.
the path to the file store for the log.
Details about the action being run at the point the log was last saved to file.
Details about the draft (and draft version) being processed at the point the log was last saved to file.
The timestamp for when the log was last saved. e.g. "2020-07-18-12.13.14.150"
An array of sets of log entries.
The path to the file store for the log.
Add a log entry to the console object instance. This does not save the entry to file, it simply adds it to the console instance. The timestamp at which the entry was logged is also recorded.
the text to be logged.
an optional categorisation of a log entry; defaults to an empty string.
an optional unique, short code for the log entry; defaults to an empty string.
// Example
tadCon.TA_addEntry("Lorem ipsum", "WARNING", "W01");
Convert an array of log entries to a sorted plain text format suitable for display. Returns a set of text-based log entries with each log entry separated by a new line.
the array of log entries, expressed in the standard log entry JSON format, to be formatted
when set as true
, the default, the entries will be sorted alphabetically.
Since a date/timestamp format is being used, this will put the entries in chronological order.
Setting to false
reverses the order and will put the latest entry at the start and the oldest entry at the end.
// Example
alert(tadCon.TA_arrayToSimpleText(true, tadCon.log));
Example output.
2020-07-20-20.32.34.010 - INFO: Processing initiated.
2020-07-20-20.32.34.299 - WARN: Language not specified. Defaulting to English.
2020-07-20-20.32.34.898 - INFO: File content generated.
2020-07-20-20.32.35.006 - ERROR [66]: File write for "test1.txt" failed.
Clear all log entries from the console object.
This effectively nulls out the content of the log
property of the console instance.
// Example
tadCon.TA_clearLog();
Clear all log entries from the console object and file.
This effectively nulls out the content of the log
property of the console instance, and
saves the resulting object properties to file, effectively nulling them out there too.
Returns true
if the file update was successful.
// Example
tadCon.TA_clearSaveLog();
Delete the log file.
The file location is specified by the path
property of the console instance.
Returns true
if the file deletion was successful.
// Example
tadCon.TA_deleteLog();
Query the log entries with filters and sort order to return a set of matching log entries.
when set as true
, the entries will be sorted alphabetically.
Since a date/timestamp format is being used, this will put the entries in chronological order.
Setting to false
reverses the order and will put the latest entry at the start and the oldest entry at the end.
the name of the log entry property to match against (stamp
, entry
, type
, code
).
the value of the log property to match against; an exact match should be specified.
determines if the key match is to be the basis of inclusion (true
) or exclusion (false
).
// Example
let arrJSONErrors = tadCon.TA_filterLog(true, "type", "ERROR", true);
// Returns an array of log entries in JSON format with a type of 'ERROR', and sorted chronologically in the array based on the time stamp
Query the log entries, possibly filtered, for a range of positional matched and return the array of matching log entry objects.
the positional index of the start of the log entry range to return. Index is 1-based.
the positional index of the end of the log entry range to return. Index is 1-based.
when set as true
(the default), the entries will be sorted alphabetically.
Since a date/timestamp format is being used, this will put the entries in chronological order.
Setting to false
reverses the order and will put the latest entry at the start and the oldest entry at the end.
the name of the log entry property to match against (stamp
, entry
, type
, code
), defaults to an empty string.
the value of the log property to match against; an exact match should be specified, defaults to an empty string.
determines if the key match is to be the basis of inclusion (true
, default) or exclusion (false
).
// Example
let arrJSONLastFiveWarnings = tadCon.TA_filterLogEntries(1, 5, false, "type", "WARN", true);
// Returns an array of the last five log entries in JSON format with a type of 'WARN', and sorted reverse chronologically in the array based on the time stamp
Query the log entries, possibly filtered, for a positional match and return the log entry object.
the positional index of the log entry to return. Index is 1-based.
when set as true
(the default), the entries will be sorted alphabetically.
Since a date/timestamp format is being used, this will put the entries in chronological order.
Setting to false
reverses the order and will put the latest entry at the start and the oldest entry at the end.
the name of the log entry property to match against (stamp
, entry
, type
, code
), defaults to an empty string.
the value of the log property to match against; an exact match should be specified, defaults to an empty string.
determines if the key match is to be the basis of inclusion (true
, default) or exclusion (false
).
// Example
alert(tadCon.TA_filterLogEntry(1, true, "type", "ERROR", true)).entry;
// Displays the log entry for the first error that occurs in the log instance
Return the array of log elements filtered to exclude on a key by a single match.
the JSON key to be checked in each array element: stamp
, entry
, type
, code
.
the value held against the key which constitutes a match and thus will be excluded.
// Example
tadCon.TA_filterLogExclude("type", "INFO");
Return the array of log elements filtered to include on a key by a single match.
the JSON key to be checked in each array element: stamp
, entry
, type
, code
.
the value held against the key which constitutes a match and thus will be included.
// Example
tadCon.TA_filterLogInclude("code", "123");
Returns the first log entry.
// Example
alert(tadCon.TA_logEntryFirst().entry);
Returns the first log entry for a specific code.
the value to match against the code
key for filtering log entries.
// Example
alert(tadCon.TA_logEntryFirstCode("W01").entry);
Returns the first log entry of a specific type.
the value to match against the type
key for filtering log entries.
// Example
alert(tadCon.TA_logEntryFirstType("WARN").entry);
Returns the last log entry.
// Example
alert(tadCon.TA_logEntryLast().entry);
Returns the last log entry for a specific code.
the value to match against the code
key for filtering log entries.
// Example
alert(tadCon.TA_logEntryLastCode("W01").entry);
Returns the last log entry of a specific type.
the value to match against the type
key for filtering log entries.
// Example
alert(tadCon.TA_logEntryLastType("WARN").entry);
Log a set of text based log entries to log file.
Returns true
if the log file was created successfully.
a string containing the set of processed log entries exactly as they should be written to file.
to include a timestamp in the file name, this should be set to true
, the default is false
.
the extension to use for the output file. Defaults to log
.
// Example
tadCon.TA_logExportEntriesToFile(strProcessedLogEntries, true, "txt");
Convert the array of log entries for the console object instance to a sorted plain text format and save to an optionally time stamped log file.
Returns true
if the log file was created successfully.
when set as true
, the default, the entries will be sorted alphabetically.
Since a date/timestamp format is being used, this will put the entries in chronological order.
Setting to false
reverses the order and will put the latest entry at the start and the oldest entry at the end.
to include a timestamp in the file name, this should be set to true
, the default is false
.
the extension to use for the output file. Defaults to log
.
// Example
tadCon.TA_logExportEntriesToFile(true, true, "txt");
Convert the array of log entries for the console object instance to a sorted plain text format suitable for display, and display it in an alert. Displays a set of text-based log entries with each log entry separated by a new line.
when set as true
, the default, the entries will be sorted alphabetically.
Since a date/timestamp format is being used, this will put the entries in chronological order.
Setting to false
reverses the order and will put the latest entry at the start and the oldest entry at the end.
// Example
tadCon.TA_logExportToAlert(true);
Example alert output.
2020-07-20-20.32.34.010 - INFO: Processing initiated.
2020-07-20-20.32.34.299 - WARN: Language not specified. Defaulting to English.
2020-07-20-20.32.34.898 - INFO: File content generated.
2020-07-20-20.32.35.006 - ERROR [66]: File write for "test1.txt" failed.
Convert an array of log entries to a sorted plain text format suitable for display, including only log entries where a key match is not made, and display it in an alert. Displays a set of text-based log entries with each log entry separated by a new line.
the name of the log entry property to match against (stamp
, entry
, type
, code
).
the value of the log property to match against; an exact match should be specified. Matches will be excluded.
when set as true
, the default, the entries will be sorted alphabetically.
Since a date/timestamp format is being used, this will put the entries in chronological order.
Setting to false
reverses the order and will put the latest entry at the start and the oldest entry at the end.
// Example
tadCon.TA_logExportToAlertExclude("type", "ERROR", true);
Example alert output.
2020-07-20-20.32.34.010 - INFO: Processing initiated.
2020-07-20-20.32.34.299 - WARN: Language not specified. Defaulting to English.
2020-07-20-20.32.34.898 - INFO: File content generated.
Convert an array of log entries to a sorted plain text format suitable for display, including only log entries where a key match is made, and display it in an alert. Displays a set of text-based log entries with each log entry separated by a new line.
the name of the log entry property to match against (stamp
, entry
, type
, code
).
the value of the log property to match against; an exact match should be specified. Matches will be included.
when set as true
, the default, the entries will be sorted alphabetically.
Since a date/timestamp format is being used, this will put the entries in chronological order.
Setting to false
reverses the order and will put the latest entry at the start and the oldest entry at the end.
// Example
tadCon.TA_logExportToAlertInclude("type", "ERROR", true);
Example alert output.
2020-07-20-20.32.35.006 - ERROR [66]: File write for "test1.txt" failed.
Convert the array of log entries for the console object instance to a sorted plain text format suitable for display, and place it on the clipboard. Places the set of text-based log entries on the clipboard with each log entry separated by a new line.
when set as true
, the default, the entries will be sorted alphabetically.
Since a date/timestamp format is being used, this will put the entries in chronological order.
Setting to false
reverses the order and will put the latest entry at the start and the oldest entry at the end.
// Example
tadCon.TA_logExportToClipboard(true);
Example clipboard content.
2020-07-20-20.32.34.010 - INFO: Processing initiated.
2020-07-20-20.32.34.299 - WARN: Language not specified. Defaulting to English.
2020-07-20-20.32.34.898 - INFO: File content generated.
2020-07-20-20.32.35.006 - ERROR [66]: File write for "test1.txt" failed.
Convert an array of log entries to a sorted plain text format suitable for display, including only log entries where a key match is not made, and place it on the clipboard. Places the set of text-based log entries on the clipboard with each log entry separated by a new line.
the name of the log entry property to match against (stamp
, entry
, type
, code
).
the value of the log property to match against; an exact match should be specified. Matches will be excluded.
when set as true
, the default, the entries will be sorted alphabetically.
Since a date/timestamp format is being used, this will put the entries in chronological order.
Setting to false
reverses the order and will put the latest entry at the start and the oldest entry at the end.
// Example
tadCon.TA_logExportToClipboardExclude("type", "ERROR", true);
Example clipboard content.
2020-07-20-20.32.34.010 - INFO: Processing initiated.
2020-07-20-20.32.34.299 - WARN: Language not specified. Defaulting to English.
2020-07-20-20.32.34.898 - INFO: File content generated.
Convert an array of log entries to a sorted plain text format suitable for display, including only log entries where a key match is made, and place it on the clipboard. Places the set of text-based log entries on the clipboard with each log entry separated by a new line.
the name of the log entry property to match against (stamp
, entry
, type
, code
).
the value of the log property to match against; an exact match should be specified. Matches will be included.
when set as true
, the default, the entries will be sorted alphabetically.
Since a date/timestamp format is being used, this will put the entries in chronological order.
Setting to false
reverses the order and will put the latest entry at the start and the oldest entry at the end.
// Example
tadCon.TA_logExportToClipboardInclude("type", "ERROR", true);
Example clipboard content.
2020-07-20-20.32.35.006 - ERROR [66]: File write for "test1.txt" failed.
Convert the array of log entries for the console object instance to a sorted plain text format suitable for display, and place it in a new draft. Places a set of text-based log entries with each log entry separated by a new line.
when set as true
, the default, the entries will be sorted alphabetically.
Since a date/timestamp format is being used, this will put the entries in chronological order.
Setting to false
reverses the order and will put the latest entry at the start and the oldest entry at the end.
// Example
tadCon.TA_logExportToDraft(true);
Example draft content.
2020-07-20-20.32.34.010 - INFO: Processing initiated.
2020-07-20-20.32.34.299 - WARN: Language not specified. Defaulting to English.
2020-07-20-20.32.34.898 - INFO: File content generated.
2020-07-20-20.32.35.006 - ERROR [66]: File write for "test1.txt" failed.
Convert an array of log entries to a sorted plain text format suitable for display, including only log entries where a key match is made, and place it in a new draft. Returns a set of text-based log entries with each log entry separated by a new line.
the name of the log entry property to match against (stamp
, entry
, type
, code
).
the value of the log property to match against; an exact match should be specified. Matches will be excluded.
when set as true
, the default, the entries will be sorted alphabetically.
Since a date/timestamp format is being used, this will put the entries in chronological order.
Setting to false
reverses the order and will put the latest entry at the start and the oldest entry at the end.
// Example
tadCon.TA_logExportToDraftExclude("type", "ERROR", true);
Example draft content.
2020-07-20-20.32.34.010 - INFO: Processing initiated.
2020-07-20-20.32.34.299 - WARN: Language not specified. Defaulting to English.
2020-07-20-20.32.34.898 - INFO: File content generated.
Convert an array of log entries to a sorted plain text format suitable for display, including only log entries where a key match is made, and place it in a new draft. Returns a set of text-based log entries with each log entry separated by a new line.
the name of the log entry property to match against (stamp
, entry
, type
, code
).
the value of the log property to match against; an exact match should be specified. Matches will be included.
when set as true
, the default, the entries will be sorted alphabetically.
Since a date/timestamp format is being used, this will put the entries in chronological order.
Setting to false
reverses the order and will put the latest entry at the start and the oldest entry at the end.
// Example
tadCon.TA_logExportToDraftInclude("type", "ERROR", true);
Example draft content.
2020-07-20-20.32.35.006 - ERROR [66]: File write for "test1.txt" failed.
Convert the array of log entries to a sorted plain text format and save to an optionally time stamped log file, including only log entries where a key match is not made.
Returns true
if the log file was created successfully.
the name of the log entry property to match against (stamp
, entry
, type
, code
).
the value of the log property to match against; an exact match should be specified. Matches will not be included.
when set as true
, the default, the entries will be sorted alphabetically.
Since a date/timestamp format is being used, this will put the entries in chronological order.
Setting to false
reverses the order and will put the latest entry at the start and the oldest entry at the end.
to include a timestamp in the file name, this should be set to true
, the default is false
.
the extension to use for the output file. Defaults to log
.
// Example
tadCon.TA_logExportToFileExclude("type", "ERROR", true, true, "txt");
Convert the array of log entries to a sorted plain text format and save to an optionally time stamped log file, including only log entries where a key match is made.
Returns true
if the log file was created successfully.
the name of the log entry property to match against (stamp
, entry
, type
, code
).
the value of the log property to match against; an exact match should be specified. Matches will be included.
when set as true
, the default, the entries will be sorted alphabetically.
Since a date/timestamp format is being used, this will put the entries in chronological order.
Setting to false
reverses the order and will put the latest entry at the start and the oldest entry at the end.
to include a timestamp in the file name, this should be set to true
, the default is false
.
the extension to use for the output file. Defaults to log
.
// Example
tadCon.TA_logExportToFileInclude("type", "ERROR", true, true, "txt");
Convert the array of log entries for the console object instance to a sorted plain text format suitable for display, and insert it at the current cursor position. Returns a set of text-based log entries with each log entry separated by a new line, matching the text inserted into the draft.
when set as true
, the default, the entries will be sorted alphabetically.
Since a date/timestamp format is being used, this will put the entries in chronological order.
Setting to false
reverses the order and will put the latest entry at the start and the oldest entry at the end.
// Example
tadCon.TA_logExportToInsert(true);
Example output/inserted text.
2020-07-20-20.32.34.010 - INFO: Processing initiated.
2020-07-20-20.32.34.299 - WARN: Language not specified. Defaulting to English.
2020-07-20-20.32.34.898 - INFO: File content generated.
2020-07-20-20.32.35.006 - ERROR [66]: File write for "test1.txt" failed.
Convert an array of log entries to a sorted plain text format suitable for display, including only log entries where a key match is not made, and insert it at the current cursor position. Returns a set of text-based log entries with each log entry separated by a new line, matching the text inserted into the draft.
the name of the log entry property to match against (stamp
, entry
, type
, code
).
the value of the log property to match against; an exact match should be specified. Matches will be excluded.
when set as true
, the default, the entries will be sorted alphabetically.
Since a date/timestamp format is being used, this will put the entries in chronological order.
Setting to false
reverses the order and will put the latest entry at the start and the oldest entry at the end.
// Example
tadCon.TA_logExportToInsertExclude("type", "ERROR", true);
Example output/inserted text.
2020-07-20-20.32.34.010 - INFO: Processing initiated.
2020-07-20-20.32.34.299 - WARN: Language not specified. Defaulting to English.
2020-07-20-20.32.34.898 - INFO: File content generated.
Convert an array of log entries to a sorted plain text format suitable for display, including only log entries where a key match is made, and insert it at the current cursor position. Returns a set of text-based log entries with each log entry separated by a new line, matching the text inserted into the draft.
the name of the log entry property to match against (stamp
, entry
, type
, code
).
the value of the log property to match against; an exact match should be specified. Matches will be included.
when set as true
, the default, the entries will be sorted alphabetically.
Since a date/timestamp format is being used, this will put the entries in chronological order.
Setting to false
reverses the order and will put the latest entry at the start and the oldest entry at the end.
// Example
tadCon.TA_logExportToInsertInclude("type", "ERROR", true);
Example output/inserted text.
2020-07-20-20.32.35.006 - ERROR [66]: File write for "test1.txt" failed.
Convert the array of log entries for the console object instance to a sorted plain text format suitable for display. Returns a set of text-based log entries with each log entry separated by a new line.
when set as true
, the default, the entries will be sorted alphabetically.
Since a date/timestamp format is being used, this will put the entries in chronological order.
Setting to false
reverses the order and will put the latest entry at the start and the oldest entry at the end.
// Example
alert(tadCon.TA_logToSimpleText(true));
Example output.
2020-07-20-20.32.34.010 - INFO: Processing initiated.
2020-07-20-20.32.34.299 - WARN: Language not specified. Defaulting to English.
2020-07-20-20.32.34.898 - INFO: File content generated.
2020-07-20-20.32.35.006 - ERROR [66]: File write for "test1.txt" failed.
Convert an array of log entries to a sorted plain text format suitable for display, including only log entries where a key match is made. Returns a set of text-based log entries with each log entry separated by a new line.
the name of the log entry property to match against (stamp
, entry
, type
, code
).
the value of the log property to match against; an exact match should be specified. Matches will be excluded.
when set as true
, the default, the entries will be sorted alphabetically.
Since a date/timestamp format is being used, this will put the entries in chronological order.
Setting to false
reverses the order and will put the latest entry at the start and the oldest entry at the end.
// Example
alert(tadCon.TA_logToSimpleTextExclude("type", "ERROR", true));
Example output.
2020-07-20-20.32.34.010 - INFO: Processing initiated.
2020-07-20-20.32.34.299 - WARN: Language not specified. Defaulting to English.
2020-07-20-20.32.34.898 - INFO: File content generated.
Convert an array of log entries to a sorted plain text format suitable for display, including only log entries where a key match is made. Returns a set of text-based log entries with each log entry separated by a new line.
the name of the log entry property to match against (stamp
, entry
, type
, code
).
the value of the log property to match against; an exact match should be specified. Matches will be included.
when set as true
, the default, the entries will be sorted alphabetically.
Since a date/timestamp format is being used, this will put the entries in chronological order.
Setting to false
reverses the order and will put the latest entry at the start and the oldest entry at the end.
// Example
alert(tadCon.TA_logToSimpleTextInclude("type", "ERROR", true));
Example output.
2020-07-20-20.32.35.006 - ERROR [66]: File write for "test1.txt" failed.
Display the log using a filterable, sortable table layout.
An HTML preview is utilised along with a datatables implementation. This
function includes some online files in the HTML for the datatable and jquery components, so connectivity
is required to utilise this function.
Returns true
if the preview window was closed with continue, and false
if it was closed with cancel.
stamp
(timestamp) and entry
(log entry) are mandatory fields and are always displayed.
When set to true
(the default), the optional fields of type
and code
will also be displayed.
// Example
tadCon.TA_previewLogTable(false);
Add an entry to the console object and save any unsaved console updates to file.
The file location is specified by the path
property of the console instance.
Returns true
if the file update was successful.
the text to be logged.
an optional categorisation of a log entry; defaults to an empty string.
an optional unique, short code for the log entry; defaults to an empty string.
// Example
tadCon.TA_saveEntry("Lorem ipsum", "WARNING", "W01");
Save the console object to file.
The file location is specified by the path
property of the console instance.
Returns true
if the file update was successful.
// Example
tadCon.TA_saveLog();
Snapshot a file by duplicating it in the same folder, but prefixing the file name with a time stamp.
Returns true
if the duplicate file was created successfully.
// Example
tadCon.TA_snapshot();
TadConsole (Library)
This is a class that provides advanced logging.