removed --refresh-rate option.. log and test fixes

This commit is contained in:
Lloyd Brookes
2015-11-13 10:50:59 +00:00
parent ffc39145ee
commit b615ffe4e0
5 changed files with 270 additions and 74 deletions

View File

@ -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)', '')
}