-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logger #46
base: master
Are you sure you want to change the base?
Logger #46
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,14 @@ var path = require('path') | |
var serveStatic = require('serve-static') | ||
var serveStaticFile = require('connect-static-file') | ||
var compression = require('compression') | ||
var log4js = require('log4js') | ||
var app = connect() | ||
|
||
const PORT = 9000 | ||
const DIRECTORY = 'public' | ||
const FILE = 'index.html' | ||
const HOST = '0.0.0.0' | ||
const LOGGEROPTIONS = {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the default value for this should be false. Then we could check if it's true or an object, then attach the logger. |
||
|
||
exports.start = function (options, _onStarted) { | ||
options = options || {} | ||
|
@@ -20,16 +22,25 @@ exports.start = function (options, _onStarted) { | |
let directories = options.directories || [directory] | ||
let file = options.file || FILE | ||
let host = options.host || HOST | ||
let loggerOptions = options.logger || LOGGEROPTIONS | ||
let onStarted = _onStarted || function () {} | ||
|
||
app.use(compression()) | ||
|
||
// First, check the file system | ||
// configure logger | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably only use the logger if they provide a config for it (not default to all the time) |
||
log4js.configure(loggerOptions) | ||
if (loggerOptions.level) { | ||
const logger = log4js.getLogger() | ||
logger.setLevel(loggerOptions.level) | ||
app.use(log4js.connectLogger(logger, { level: log4js.levels[loggerOptions.level] })) | ||
} | ||
|
||
// check the file system | ||
directories.forEach(function(directory) { | ||
app.use(serveStatic(directory, { extensions: ['html'] })) | ||
}) | ||
|
||
// Then, serve the fallback file | ||
// serve the fallback file | ||
app.use(serveStaticFile(path.join(directory, file))) | ||
|
||
return app.listen(port, host, function (err) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, just a couple more changes, then it's ready to merge! 🎉 . Should probably add an example here of using a logger default values.