All files / botbuilder-unit/src/log-reporters PlainLogReporter.js

100% Statements 46/46
78.57% Branches 11/14
100% Functions 14/14
100% Lines 46/46
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      2x 2x     4x   2x 2x   2x 4x   2x 32x     2x 14x 14x   2x 2x   2x 2x   2x 10x 10x 2x   8x   10x   2x 4x 4x 2x   2x   4x   2x 2x   2x 2x   2x 4x   2x 2x   2x 2x           2x   2x 2x 2x 2x 2x 2x       2x
/* 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) {
  return "string" == typeof message ? message : util.inspect(message, {depth: 4, color: false, showHidden: true});
}
 
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 = '';
  if ("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) {
  console.error(`# ${errorHeader} ${this.normizalizeForOutput(message)}`);
}
PlainLogReporter.prototype.warning = function (warningHeader, message) {
  console.log(`# ${warningHeader} ${this.normizalizeForOutput(message)}`);
}
PlainLogReporter.prototype.info = function (infoHeader, message) {
  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;