Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
alvagi
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
alvagi
Commits
d40e26df
Commit
d40e26df
authored
Nov 24, 2017
by
Sergey Razuvaev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add logger
parent
4c368700
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
5 deletions
+12
-5
context.js
lib/context.js
+10
-4
index.js
lib/index.js
+2
-1
No files found.
lib/context.js
View file @
d40e26df
...
...
@@ -5,10 +5,16 @@ var commands = require('./command');
//base context
var
Context
=
function
(
stream
,
debug
)
{
var
Context
=
function
(
stream
,
loggerOptions
)
{
EventEmitter
.
call
(
this
);
function
consoleDecorator
(
data
){
return
console
.
log
(
JSON
.
stringify
(
data
))
}
this
.
debug
=
loggerOptions
.
debug
this
.
log
=
loggerOptions
.
logger
.
debug
||
consoleDecorator
;
this
.
debug
=
debug
;
this
.
stream
=
new
Readable
();
this
.
stream
.
setEncoding
(
'
utf8
'
);
...
...
@@ -113,11 +119,11 @@ Context.prototype.end = function () {
};
Context
.
prototype
.
sendCommand
=
function
(
command
)
{
if
(
this
.
debug
)
console
.
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
)
console
.
log
(
'
err:
'
,
err
,
'
result:
'
,
result
);
if
(
self
.
debug
)
this
.
log
({
err
:
err
,
result
:
result
}
);
if
(
err
)
{
reject
(
err
);
}
else
{
...
...
lib/index.js
View file @
d40e26df
...
...
@@ -8,11 +8,12 @@ var agi = function (handler, optionsIn) {
var
settings
=
{
port
:
options
.
port
||
3000
,
debug
:
options
.
debug
||
false
,
logger
:
options
.
logger
||
false
,
host
:
options
.
host
,
};
var
handle
=
function
(
stream
)
{
var
context
=
new
Context
(
stream
,
settings
.
debug
);
var
context
=
new
Context
(
stream
,
{
debug
:
settings
.
debug
,
logger
:
options
.
logger
}
);
handler
(
context
);
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment