Skip to content

Commit

Permalink
get service logs
Browse files Browse the repository at this point in the history
  • Loading branch information
闪光 committed May 31, 2017
1 parent 4d50ed3 commit c2f32af
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 4 deletions.
41 changes: 41 additions & 0 deletions lib/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,45 @@ Service.prototype.update = function(auth, opts, callback) {
};



/**
* Service logs
* @param {Object} opts Logs options. (optional)
* @param {Function} callback Callback with data
*/
Service.prototype.logs = function(opts, callback) {
var self = this;
var args = util.processArgs(opts, callback, {});

var optsf = {
path: '/services/' + this.id + '/logs?',
method: 'GET',
isStream: true,
statusCodes: {
200: true,
404: 'no such service',
500: 'server error',
503: 'node is not part of a swarm'
},
options: args.opts
};

if(args.callback === undefined) {
return new this.modem.Promise(function(resolve, reject) {
self.modem.dial(optsf, function(err, data) {
if (err) {
return reject(err);
}
resolve(data);
});
});
} else {
this.modem.dial(optsf, function(err, data) {
args.callback(err, data);
});
}
};



module.exports = Service;
30 changes: 26 additions & 4 deletions test/swarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,38 @@ describe("#swarm", function() {
service.update(opts, handler);
});

it("should delete service", function(done) {
this.timeout(5000);

function handler(err, data) {

it("should get the logs for a service as a stream", function(done) {
this.timeout(30000);

var logs_opts = {
follow: true,
stdout: true,
stderr: true,
timestamps: true
};

function handler(err, stream) {
expect(err).to.be.null;
expect(stream.pipe).to.be.ok;
done();
}

service.remove(handler);
service.logs(logs_opts, handler);
});

it("should delete service", function(done) {
this.timeout(5000);

function handler(err, data) {
expect(err).to.be.null;
done();
}

service.remove(handler);
});

});

describe("#tasks", function() {
Expand Down

0 comments on commit c2f32af

Please sign in to comment.