Skip to content

Commit

Permalink
feat: new logging api
Browse files Browse the repository at this point in the history
  • Loading branch information
yasserf committed Sep 20, 2017
1 parent dab0fd7 commit 47f443e
Show file tree
Hide file tree
Showing 55 changed files with 2,314 additions and 2,111 deletions.
Binary file added .DS_Store
Binary file not shown.
38 changes: 38 additions & 0 deletions benchmarks/binary-parser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict'

const messageHandler = require('../src/cluster/messaging/message-handler')
const assert = require('assert')

const fs = require('fs')

const data = fs.readFileSync('./test-data.bin')
const Benchmark = require('benchmark')

const suite = new Benchmark('parser', () => {
let readBuffer = data
let result
do {
result = messageHandler.tryParseBinaryMsg(readBuffer, err => console.log('parse error', err))
if (result.bytesConsumed > 0) {
// this._onMessage(result.message)
readBuffer = readBuffer.slice(result.bytesConsumed)
}
} while (readBuffer.length !== 0 && result.bytesConsumed !== 0)
assert(readBuffer.length === 0)
}, {
maxTime: 10,
onComplete () {
console.log(`The mean run time after ${this.count} iterations was ${
this.stats.mean * 1000} ± ${this.stats.deviation * 1000} ms`)
console.log(`Variance ${this.stats.variance.toExponential(9)}`)
},
onError (err) {
console.error('an error occurred', err)
throw err
},
onAbort (err) {
console.error('an abort occurred', err)
throw err
}
})
suite.run()
7 changes: 4 additions & 3 deletions bin/deepstream-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ module.exports = function (program) {

.option('-c, --config [file]', 'configuration file, parent directory will be used as prefix for other config files')

.option('--service-name <name>', 'the name to register the service')
.option('--log-dir <directory>', 'the directory for output logs')
.option('-n, --service-name <name>', 'the name to register the service')
.option('-o, --log-dir <directory>', 'the directory for output logs')
.option('-p, --pid-directory <directory>', 'the directory for the pid file')
.option('--dry-run', 'outputs the service file to screen')
.action(execute)
}
Expand Down Expand Up @@ -38,7 +39,7 @@ function execute(action) {
const options = {
exec,
programArgs: [],
pidFile: `/var/run/deepstream/${name}.pid`,
pidFile: this.pidFile || `/var/run/deepstream/${name}.pid`,
logDir: this.logDir || '/var/log/deepstream',
dryRun: this.dryRun
}
Expand Down
4 changes: 4 additions & 0 deletions jasmine-runner.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
var Jasmine = require('jasmine')
var SpecReporter = require('jasmine-spec-reporter').SpecReporter
var noop = function() {}

var jrunner = new Jasmine()
var jasmine = global.jasmine
jrunner.configureDefaultReporter({ print: noop }) // remove default reporter logs
jasmine.getEnv().addReporter(new SpecReporter()) // add jasmine-spec-reporter
jrunner.loadConfigFile('./jasmine.json') // load jasmine.json configuration
jrunner.execute()
48 changes: 24 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/authentication/http-authentication-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ module.exports = class HttpAuthenticationRequest {
*/
_onComplete (error, response) {
if (error) {
this._logger.log(C.LOG_LEVEL.WARN, C.EVENT.AUTH_ERROR, `http auth error: ${error}`)
this._logger.warn(C.EVENT.AUTH_ERROR, `http auth error: ${error}`)
this._callback(false, null)
this._destroy()
return
}

if (response.statusCode >= 500 && response.statusCode < 600) {
this._logger.log(C.LOG_LEVEL.WARN, C.EVENT.AUTH_ERROR, `http auth server error: ${response.body}`)
this._logger.warn(C.EVENT.AUTH_ERROR, `http auth server error: ${response.body}`)
}

if (this._settings.permittedStatusCodes.indexOf(response.statusCode) === -1) {
Expand Down
6 changes: 6 additions & 0 deletions src/config/config-initialiser.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ function handleLogger (config) {
}

config.logger = new Logger(configOptions)
if (!config.logger.info) {
config.logger.debug = config.logger.log.bind(config.logger, C.LOG_LEVEL.DEBUG)
config.logger.info = config.logger.log.bind(config.logger, C.LOG_LEVEL.INFO)
config.logger.warn = config.logger.log.bind(config.logger, C.LOG_LEVEL.WARN)
config.logger.error = config.logger.log.bind(config.logger, C.LOG_LEVEL.ERROR)
}
if (LOG_LEVEL_KEYS.indexOf(config.logLevel) !== -1) {
// NOTE: config.logLevel has highest priority, compare to the level defined
// in the nested logger object
Expand Down
6 changes: 2 additions & 4 deletions src/constants/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,11 @@ exports.TOPIC.ERROR = 'X'
exports.TOPIC.EVENT = 'E'
exports.TOPIC.RECORD = 'R'
exports.TOPIC.RPC = 'P'
exports.TOPIC.RPC_PRIVATE = 'PRIVATE/P'
exports.TOPIC.PRESENCE = 'U'
exports.TOPIC.ONLINE_USERS = 'O'
exports.TOPIC.CLUSTER = 'CL'
exports.TOPIC.LEADER = 'L'
exports.TOPIC.LEADER_PRIVATE = 'LP_'
exports.TOPIC.PRIVATE = 'PRIVATE/'

exports.TOPIC.ONLINE_USERS = 'O'
exports.TOPIC.LISTEN = 'LI'
exports.TOPIC.PUBLISHED_SUBSCRIPTIONS = 'PS'
exports.TOPIC.LISTEN_PATTERNS = 'LIP'
Expand Down
Loading

0 comments on commit 47f443e

Please sign in to comment.