removed --refresh-rate option.. log and test fixes
This commit is contained in:
@ -17,10 +17,6 @@ module.exports = {
|
||||
description: 'Enable gzip compression, reduces bandwidth.', group: 'server'
|
||||
},
|
||||
{
|
||||
name: 'refresh-rate', alias: 'r', type: Number,
|
||||
description: 'Statistics view refresh rate in ms. Defaults to 500.', group: 'server'
|
||||
},
|
||||
{
|
||||
name: 'help', alias: 'h', type: Boolean,
|
||||
description: 'Print these usage instructions', group: 'misc'
|
||||
},
|
||||
|
@ -20,40 +20,38 @@ function getApp (options) {
|
||||
options = Object.assign({
|
||||
static: {},
|
||||
serveIndex: {},
|
||||
logger: {},
|
||||
log: {},
|
||||
compress: false
|
||||
}, options)
|
||||
|
||||
|
||||
const log = options.log
|
||||
log.options = log.options || {}
|
||||
|
||||
const app = new Koa()
|
||||
|
||||
// app.use((ctx, next) => {
|
||||
// return next().then(() => ctx.type = 'text/plain')
|
||||
// })
|
||||
|
||||
if (options.compress) {
|
||||
console.log('comp');
|
||||
app.use(convert(compress()))
|
||||
}
|
||||
|
||||
let log = { format: options.logger.format }
|
||||
if (options.logger.format) {
|
||||
|
||||
/* special case log formats */
|
||||
if (log.format) {
|
||||
if (log.format === 'none'){
|
||||
log.format = undefined
|
||||
} else if (log.format === 'logstalgia') {
|
||||
/* customised logger :date token, purely to satisfy Logstalgia. */
|
||||
morgan.token('date', function () {
|
||||
var d = new Date()
|
||||
return (d.getDate() + '/' + d.getUTCMonth() + '/' + d.getFullYear() + ':' + d.toTimeString())
|
||||
.replace('GMT', '').replace(' (BST)', '')
|
||||
})
|
||||
morgan.token('date', logstalgiaDate)
|
||||
log.format = 'combined'
|
||||
} else if (log.format) {
|
||||
log.stream = process.stdout
|
||||
}
|
||||
/* if no specific log format was requested, show log stats */
|
||||
} else {
|
||||
log.format = 'common'
|
||||
log.stream = streamLogStats({ refreshRate: 100 })
|
||||
log.options.stream = streamLogStats({ refreshRate: 500 })
|
||||
}
|
||||
options.logger.options = options.logger.options || {}
|
||||
options.logger.options.stream = log.stream
|
||||
if (log.format) app.use(convert(morgan.middleware(log.format, options.logger.options)))
|
||||
if (log.format) app.use(convert(morgan.middleware(log.format, log.options)))
|
||||
|
||||
if (options.static.root) {
|
||||
app.use(convert(serve(options.static.root, options.static.options)))
|
||||
@ -64,3 +62,10 @@ function getApp (options) {
|
||||
|
||||
return app
|
||||
}
|
||||
|
||||
function logstalgiaDate () {
|
||||
var d = new Date()
|
||||
return (`${d.getDate()}/${d.getUTCMonth()}/${d.getFullYear()}:${d.toTimeString()}`)
|
||||
.replace('GMT', '')
|
||||
.replace(' (BST)', '')
|
||||
}
|
||||
|
Reference in New Issue
Block a user