Skip to main content

Logging

The main purpose of logging is to record operations performed in the task for further analysis. Keeping logs allows identifying errors in the task's operation

this.doLog

Indicates whether the task's log is enabled, can be used as a flag for optimization, for cases when the log is not kept and the argument to this.logger.put is a complex expression

this.logger.*

.put(message)

this.logger.put(message) - adds the line message to the task log, formats the output similarly to console.log

this.logger.put("Start scraping query: " + set.query);
Example of message output to the task log

.putHTML(HTML)

this.logger.putHTML(code) - outputs HTML code to the task log, which will be displayed in a textarea

const message = "<!DOCTYPE html>\n"
+ "<html>\n"
+ "<body>\n"
+ "<h1>This is heading 1</h1>\n"
+ "<h2>This is heading 2</h2>\n"
+ "<h3>This is heading 3</h3>\n"
+ "<h4>This is heading 4</h4>\n"
+ "<h5>This is heading 5</h5>\n"
+ "<h6>This is heading 6</h6>\n"
+ "</body>\n"
+ "</html>";
this.logger.putHTML(message);
Example of html output to the task log

console.log(message)

Outputs the contents of message to the log file - aparser.log

this.console.*

All methods relate to the output of console logs, created to improve logging of different tasks and different streams within tasks

.log(...message)

this.console.log(...message) - logging tied to the current stream, allows outputting a prefix for each stream

.setPrefix(prefix)

Used in conjunction with BaseParser.setGlobalConsolePrefix(prefix) - allows setting a global prefix for all streams within the current task

this.console.setPrefix(prefix) - allows setting a prefix for the current stream, for example

this.console.setPrefix(this.threadId())