forked from openstf/stf
-
Notifications
You must be signed in to change notification settings - Fork 507
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minimal start with a custom logger and device tracker.
- Loading branch information
Showing
7 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# http://editorconfig.org/ | ||
|
||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/usr/bin/env node | ||
require('../lib/cli') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
var program = require('commander') | ||
|
||
var pkg = require('../package') | ||
|
||
program | ||
.version(pkg.version) | ||
|
||
program | ||
.command('provider') | ||
.description('run STF provider') | ||
.action(function() { | ||
require('./provider') | ||
}) | ||
|
||
program.parse(process.argv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
var adb = require('adbkit') | ||
var async = require('async') | ||
|
||
var log = require('./util/logger').createLogger('provider') | ||
var client = adb.createClient() | ||
|
||
client.trackDevices(function(err, tracker) { | ||
if (err) { | ||
log.fatal('Unable to track devices: %s', err.message) | ||
throw err | ||
} | ||
|
||
log.info('Tracking devices') | ||
|
||
tracker.on('add', function(device) { | ||
log.info('Found device "%s" (%s)', device.id, device.type) | ||
}) | ||
|
||
tracker.on('change', function(device) { | ||
log.info('Device "%s" is now "%s"', device.id, device.type) | ||
}) | ||
|
||
tracker.on('remove', function(device) { | ||
log.info('Lost device "%s" (%s)', device.id, device.type) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
var util = require('util') | ||
|
||
function Log(tag, stream) { | ||
this.tag = tag | ||
this.stream = stream || process.stderr | ||
this.levels = { | ||
DEBUG: 'DBG' | ||
, VERBOSE: 'VRB' | ||
, INFO: 'INF' | ||
, WARNING: 'WRN' | ||
, ERROR: 'ERR' | ||
, FATAL: 'FTL' | ||
} | ||
} | ||
|
||
Log.prototype.debug = function() { | ||
this._write(this._format(this.levels.DEBUG, arguments)) | ||
} | ||
|
||
Log.prototype.verbose = function() { | ||
this._write(this._format(this.levels.VERBOSE, arguments)) | ||
} | ||
|
||
Log.prototype.info = function() { | ||
this._write(this._format(this.levels.INFO, arguments)) | ||
} | ||
|
||
Log.prototype.warn = function() { | ||
this._write(this._format(this.levels.WARNING, arguments)) | ||
} | ||
|
||
Log.prototype.error = function() { | ||
this._write(this._format(this.levels.ERROR, arguments)) | ||
} | ||
|
||
Log.prototype.fatal = function() { | ||
this._write(this._format(this.levels.FATAL, arguments)) | ||
} | ||
|
||
Log.prototype._format = function(priority, args) { | ||
return util.format('%s %s/%s %d %s\n', | ||
Log.prefix, priority, this.tag, process.pid, util.format.apply(util, args)) | ||
} | ||
|
||
Log.prototype._write = function(out) { | ||
this.stream.write(out) | ||
} | ||
|
||
Log.prefix = '*' | ||
|
||
Log.createLogger = function(tag) { | ||
return new Log(tag) | ||
} | ||
|
||
Log.setPrefix = function(prefix) { | ||
Log.prefix = prefix | ||
} | ||
|
||
exports = module.exports = Log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
var chai = require('chai') | ||
var expect = chai.expect | ||
|
||
var logger = require('../../lib/util/logger') | ||
|
||
describe('Logger', function() { | ||
|
||
it('should have a createLogger method', function() { | ||
expect(logger).itself.to.respondTo('createLogger') | ||
}) | ||
|
||
}) |