diff --git a/README.md b/README.md index 779a6e6..f2b379f 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ local-web-server is a command-line tool. To serve the current directory, run `ws -b, --forbid path ... A list of forbidden routes. -n, --no-cache Disable etag-based caching -forces loading from disk each request. -c, --compress Serve gzip-compressed resources, where applicable. - -f, --log-format string If a format is supplied an access log is written to stdout. If not, a dynamic + -f, --log.format string If a format is supplied an access log is written to stdout. If not, a dynamic statistics view is displayed. Use a preset ('none', 'dev','combined', 'short', 'tiny' or 'logstalgia') or supply a custom format (e.g. ':method -> :url'). diff --git a/doc/logging.md b/doc/logging.md index c41cd21..593c0ca 100644 --- a/doc/logging.md +++ b/doc/logging.md @@ -1,13 +1,13 @@ # Logging -By default, local-web-server outputs a simple, dynamic statistics view. To see traditional web server logs, use `--log-format`: +By default, local-web-server outputs a simple, dynamic statistics view. To see traditional web server logs, use `--log.format`: ```sh -$ ws --log-format combined +$ ws --log.format combined serving at http://localhost:8000 ::1 - - [16/Nov/2015:11:16:52 +0000] "GET / HTTP/1.1" 200 12290 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2562.0 Safari/537.36" ``` -The format value supplied is passed directly to [morgan](https://github.com/expressjs/morgan). The exception is `--log-format none` which disables all output. +The format value supplied is passed directly to [morgan](https://github.com/expressjs/morgan). The exception is `--log.format none` which disables all output. # Visualisation @@ -17,7 +17,7 @@ To get live statistics in [goaccess](http://goaccess.io/), first create this con ``` time-format %T date-format %d/%b/%Y -log-format %h %^[%d:%t %^] "%r" %s %b "%R" "%u" +log.format %h %^[%d:%t %^] "%r" %s %b "%R" "%u" ``` Then, start the server, outputting `combined` format logs to disk: diff --git a/doc/visualisation.md b/doc/visualisation.md index f143719..c621023 100644 --- a/doc/visualisation.md +++ b/doc/visualisation.md @@ -4,7 +4,7 @@ To get live statistics in [goaccess](http://goaccess.io/), first create this con ``` time-format %T date-format %d/%b/%Y -log-format %h %^[%d:%t %^] "%r" %s %b "%R" "%u" +log.format %h %^[%d:%t %^] "%r" %s %b "%R" "%u" ``` Then, start the server, outputting `combined` format logs to disk: diff --git a/lib/local-web-server.js b/lib/local-web-server.js index dabf476..a61b5f9 100644 --- a/lib/local-web-server.js +++ b/lib/local-web-server.js @@ -77,11 +77,16 @@ class LocalWebServer { const usage = commandLineUsage(cli.usage(middlewareOptionDefinitions)) let options = {} + const allOptionDefinitions = cli.optionDefinitions.concat(middlewareOptionDefinitions) try { - options = commandLineArgs(cli.optionDefinitions.concat(middlewareOptionDefinitions)) + options = commandLineArgs(allOptionDefinitions) } catch (err) { + tool.printError(err) + tool.printError(allOptionDefinitions.map(def => { + return `name: ${def.name}${def.alias ? ', alias: ' + def.alias : ''}` + }).join('\n')) console.error(usage) - tool.halt(err) + tool.halt() } /* combine in stored config */ @@ -125,7 +130,7 @@ class LocalWebServer { const app = new Koa() app.use(this.stack) app.on('error', err => { - if (this.options['log-format']) { + if (this.options['log.format']) { console.error(ansi.format(err.stack, 'red')) } }) @@ -189,7 +194,6 @@ function onServerUp (port, directory, isHttps) { )) } - function getIPList () { const flatten = require('reduce-flatten') const os = require('os') @@ -227,25 +231,36 @@ function collectUserOptions (mwOptionDefinitions) { */ function loadStack (modulePath) { let module + const tried = [] if (modulePath) { const fs = require('fs') try { + tried.push(path.resolve(modulePath)) module = require(path.resolve(modulePath)) } catch (err) { const walkBack = require('walk-back') const foundPath = walkBack(process.cwd(), path.join('node_modules', 'local-web-server-' + modulePath)) + tried.push('local-web-server-' + modulePath) if (foundPath) { module = require(foundPath) } else { const foundPath2 = walkBack(process.cwd(), path.join('node_modules', modulePath)) + tried.push(modulePath) if (foundPath2) { module = require(foundPath2) } } } } - if (!(module && (module.prototype.middleware || module.prototype.stack))) { - tool.halt(new Error('Not valid Middleware: ' + modulePath)) + if (module) { + if (!(module.prototype.middleware || module.prototype.stack)) { + const insp = require('util').inspect(module, { depth: 3, colors: true }) + const msg = `Not valid Middleware at: ${insp}` + tool.halt(new Error(msg)) + } + } else { + const msg = `No module found at: \n${tried.join('\n')}` + tool.halt(new Error(msg)) } return module } diff --git a/package.json b/package.json index 1439c92..e47ebf2 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "dependencies": { "ansi-escape-sequences": "^2.2.2", "array-back": "^1.0.3", - "command-line-tool": "~0.3.1", + "command-line-tool": "75lb/command-line-tool", "config-master": "^2.0.3", "koa": "^2.0.0", "local-web-server-default-stack": "github:local-web-server/default-stack", diff --git a/test/compress/big-file.txt b/test/compress/big-file.txt index d5b9685..e837549 100644 --- a/test/compress/big-file.txt +++ b/test/compress/big-file.txt @@ -54,7 +54,7 @@ $ ws --help Server -p, --port Web server port --f, --log-format If a format is supplied an access log is written to stdout. If not, a statistics view is displayed. Use a +-f, --log.format If a format is supplied an access log is written to stdout. If not, a statistics view is displayed. Use a preset ('none', 'dev','combined', 'short', 'tiny' or 'logstalgia') or supply a custom format (e.g. ':method -> :url'). -d, --directory Root directory, defaults to the current directory @@ -90,11 +90,11 @@ $ ws --compress ``` ### Logging -Passing a value to `--log-format` will write an access log to `stdout`. +Passing a value to `--log.format` will write an access log to `stdout`. Either use a built-in [morgan](https://github.com/expressjs/morgan) logger preset: ```sh -$ ws --log-format short +$ ws --log.format short ``` Or a custom [morgan](https://github.com/expressjs/morgan) log format: @@ -123,7 +123,7 @@ Or in a `.local-web-server.json` file stored in the directory you want to serve ```json { "port": 8100, - "log-format": "tiny" + "log.format": "tiny" } ```