All files / src/log-reporters PlainLogReporter.js

83.02% Statements 44/53
50% Branches 11/22
92.86% Functions 13/14
83.02% Lines 44/53
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88      1x 1x     1x   1x 1x   1x 2x   1x 13x 13x     1x 7x 7x   1x 1x   1x 1x   1x 3x 3x     3x   3x   1x                 1x 1x   1x 1x     1x   1x 1x     1x   1x 1x     1x   1x 1x           1x   1x 1x 1x 1x 1x 1x       1x
/* jslint es6 */
'use strict';
 
const BaseLogReporter = require('./BaseLogReporter');
const util = require('util');
 
function PlainLogReporter() {
  BaseLogReporter.call(this);
}
PlainLogReporter.prototype = Object.create(BaseLogReporter.prototype);
PlainLogReporter.prototype.constructor = PlainLogReporter;
 
PlainLogReporter.prototype.scriptFinished = function () {
  console.log(`# Script finished`);
}
PlainLogReporter.prototype.normizalizeForOutput = function (message) {
  let isObject = (message instanceof Object) || ("function" ==  typeof message);;
  return isObject? util.inspect(message, {depth: 4, color: false, showHidden: true}) : message.toString()
}
 
PlainLogReporter.prototype.messageReceived = function (step, message) {
  let outputMessage = this.normizalizeForOutput(message);
  console.log(`#${step} Bot: ${outputMessage}`);
}
PlainLogReporter.prototype.endConversation = function (step) {
  console.log(`#${step} End of conversation`);
}
PlainLogReporter.prototype.typing = function (step) {
  console.log(`#${step} Typing...`);
}
PlainLogReporter.prototype.messageSent = function (step, message) {
  let outputMessage = '';
  Iif ("function" == typeof message.user) {
    outputMessage = message.user.toString();
  } else {
    outputMessage = message.user ? message.user : this.normizalizeForOutput(message);
  }
  console.log(`#${step} User: ${outputMessage}`);
}
PlainLogReporter.prototype.customStep = function (step, message) {
  let outputMessage = '';
  if ("function" == typeof message.custom) {
    outputMessage = message.custom.toString();
  } else {
    outputMessage = message.custom ? message.custom : this.normizalizeForOutput(message);
  }
  console.log(`#${step} Custom Validation Step: ${outputMessage}`);
}
PlainLogReporter.prototype.expectationError = function (step, received, error) {
  console.error(`#${step} Expectation Error: ` +error);
}
PlainLogReporter.prototype.error = function (errorHeader, message) {
  Iif ( "undefined" == typeof errorHeader ) {
    errorHeader = 'Error:';
  }
  console.error(`# ${errorHeader} ${this.normizalizeForOutput(message)}`);
}
PlainLogReporter.prototype.warning = function (warningHeader, message) {
  Iif ( "undefined" == typeof warningHeader ) {
    warningHeader = 'WARNING:';
  }
  console.log(`# ${warningHeader} ${this.normizalizeForOutput(message)}`);
}
PlainLogReporter.prototype.info = function (infoHeader, message) {
  Iif ( !infoHeader ) {
    infoHeader = 'Info:';
  }
  console.log(`# ${infoHeader} ${this.normizalizeForOutput(message)}`);
}
PlainLogReporter.prototype.session = function (step, session) {
  let output = {
    userData : Object.assign({}, session.userData),
    conversationData : Object.assign({}, session.conversationData),
    privateConversationData : Object.assign({}, session.privateConversationData),
    sessionState : Object.assign({}, session.sessionState)
  }
  console.log(`#${step} Session: ${this.normizalizeForOutput(output)}`);
}
PlainLogReporter.prototype.startupDialog = function (step, dialog, args) {
  this.isLeftPaddingEnabled = false;
  dialog = dialog || '';
  args = args || '';
  console.log(`#${step} Next Dialog: ${this.normizalizeForOutput(dialog)}`);
  console.log(`#${step} ARGS Set: ${this.normizalizeForOutput(args)}`);
}
 
 
module.exports = PlainLogReporter;