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

added external logger support

parent 6cbea7a1
...@@ -8,14 +8,15 @@ var commands = require('./command'); ...@@ -8,14 +8,15 @@ var commands = require('./command');
var Context = function (stream, loggerOptions) { var Context = function (stream, loggerOptions) {
EventEmitter.call(this); EventEmitter.call(this);
function consoleDecorator(data){ function consoleDecorator(arrow, data){
return console.log(JSON.stringify (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 = new Readable();
this.stream.setEncoding('utf8'); this.stream.setEncoding('utf8');
this.stream.wrap(stream); this.stream.wrap(stream);
...@@ -119,11 +120,11 @@ Context.prototype.end = function () { ...@@ -119,11 +120,11 @@ Context.prototype.end = function () {
}; };
Context.prototype.sendCommand = function (command) { Context.prototype.sendCommand = function (command) {
if (this.debug) this.log({ command: command }); if (this.debug) this.log('------->', { command: command });
var self = this; var self = this;
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
self.send(command + '\n', function (err, result) { 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) { if (err) {
reject(err); reject(err);
} else { } else {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"author": "Sergey Dmitriev <serge.dmitriev@gmail.com>", "author": "Sergey Dmitriev <serge.dmitriev@gmail.com>",
"name": "ding-dong", "name": "ding-dong",
"description": "Write AGI-server quickly! (AGI - Asterisk Gateway Interface)", "description": "Write AGI-server quickly! (AGI - Asterisk Gateway Interface)",
"version": "0.1.5", "version": "0.1.6",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git://github.com/antirek/ding-dong.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