new TaskLogger()
Logs the start and the completion or error of a task whether synchronous or asynchronous
- Source:
Methods
(async, static) execute(logger, task, beginMessage, endMessage, errorMessageopt, errorHandleropt) → {Promise}
Creates two log entries for the execution of a task: 'begin' and either 'end' or 'error.'
- Creates a log entry with: a) tag: 'begin' b) tag: a newly generated unique id c) message = beginMessage
- await task() (Note: the task is not required to return a Promise). The parameter passed is a object with the properties 'logger' and 'taskId.'
- If an exception is thrown in step 2: a) If errorHandler is provided, it is called. If it returns a falsey value, go to c). Otherwise, use the return value as errorMessage. b) Logs an error with: i. error ii. tag: taskId iii. message: errorMessage c) Throws the error (thus terminating this workflow)
- Creates a log entry with: a) tag: 'end' b) tag: taskId c) message: endMessage
- Returns the value from step 2
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
logger |
object
|
||
task |
function
|
A function to invoke. One argument is passed to this function: an object with the properties 'logger' and 'taskId.' |
|
beginMessage |
*
|
A message to be logged before invoking the task |
|
endMessage |
*
|
A message to log when the task does not throw an exception |
|
errorMessage |
*
|
<optional> |
A message to log when the task throws an exception. errorMessage can be overridden by the provided errorHandler. |
errorHandler |
function
|
<optional> |
A function that is invoked with the following arguments when the task throws an exception:
|
Returns:
- Type:
-
Promise
Resolves to the value returned or rejects using exception thrown by the task