Commit 5d5b8c13 authored by Sergey Razuvaev's avatar Sergey Razuvaev

added external logger support

parent 6cbea7a1
......@@ -8,14 +8,15 @@ var commands = require('./command');
var Context = function (stream, loggerOptions) {
EventEmitter.call(this);
function consoleDecorator(data){
return console.log(JSON.stringify (data))
function consoleDecorator(arrow, data){
return console.log(arrow, JSON.stringify (data));
}
this.log = (loggerOptions.logger) ?
loggerOptions.logger :
consoleDecorator;
this.debug = loggerOptions.debug
this.log = loggerOptions.logger.debug || consoleDecorator;
this.debug = loggerOptions.debug
this.stream = new Readable();
this.stream.setEncoding('utf8');
this.stream.wrap(stream);
......@@ -119,11 +120,11 @@ Context.prototype.end = function () {
};
Context.prototype.sendCommand = function (command) {
if (this.debug) this.log({ command: command });
if (this.debug) this.log('------->', { command: command });
var self = this;
return new Promise(function (resolve, reject) {
self.send(command + '\n', function (err, result) {
if (self.debug) self.log({ err: err, result: result });
if (self.debug) self.log('<-------', { err: err, result: result });
if (err) {
reject(err);
} else {
......
......@@ -2,7 +2,7 @@
"author": "Sergey Dmitriev <serge.dmitriev@gmail.com>",
"name": "ding-dong",
"description": "Write AGI-server quickly! (AGI - Asterisk Gateway Interface)",
"version": "0.1.5",
"version": "0.1.6",
"repository": {
"type": "git",
"url": "git://github.com/antirek/ding-dong.git"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment