-
Notifications
You must be signed in to change notification settings - Fork 34
Logger #46
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
base: master
Are you sure you want to change the base?
Logger #46
Changes from 1 commit
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,17 @@ 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 = { | ||
| level: 'ALL', | ||
| appenders: [ { type: 'console' } ] | ||
| } | ||
|
|
||
| exports.start = function (options, _onStarted) { | ||
| options = options || {} | ||
|
|
@@ -20,16 +25,23 @@ 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 | ||
|
Owner
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) | ||
| 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) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |
| "compression": "^1.1.0", | ||
| "connect": "^3.2.0", | ||
| "connect-static-file": "^1.1.2", | ||
| "log4js": "^1.1.0", | ||
|
||
| "serve-static": "^1.6.2" | ||
| }, | ||
| "devDependencies": { | ||
|
|
||
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.