LoginSignup
0
0

More than 5 years have passed since last update.

lite-server(Browsersync)のアクセスログフォーマットを変更する

Posted at

lite-serverとは

lite-serverBrowsersyncのラッパーで、軽量な開発用WebServerとして使われています。
https://github.com/johnpapa/lite-server

ログの仕組み

標準ではページ表示時に下記のようなログが出ます。

[0] 19.02.17 01:26:53 200 GET /index.html
[0] 19.02.17 01:26:53 200 GET /index.html
[0] 19.02.17 01:26:54 200 GET /index.html

物足りないのでApacheのアクセスログと同じフォーマットにしてみましょう。

以下を参照すると、connect-loggerを使っているようです。
https://github.com/johnpapa/lite-server/blob/master/lib/config-defaults.js

config-defaults.js
var log = require('connect-logger');
 :
 log({ format: '%date %status %method %url' }),

connect-logger

connect-loggerで使えるフォーマットは下記だけのようです。

%date, %status, %method, %url, %route, %time

morgan

Express.jsで使っているmorganに変更します。
https://github.com/expressjs/morgan

変更手順

bs-config.jsmiddlewareを変更します。他の項目は各自で自由にどうぞ。
morganをインストールしていない場合は、npm install --save-dev morganで入れて下さい。

bs-config.js
//var log = require('connect-logger');
var log = require('morgan');

module.exports = {
  "injectChanges": "true",
  "files": ["./app/**/*.{html,htm,css,js}"],
  "watchOptions": { "ignored": "node_modules" },
  "server": {
    "baseDir": "./app",
    "middleware": [
      //log({ format: '%date %status %method %url %route %time' })
      log("combined")
    ]
  },
  "notify": false
};

変更完了

lite-serverを再起動して完了。

[0] ::ffff:127.0.0.1 - - [17/Sun/2019:04:13:26 +0000] "GET /favicon.ico HTTP/1.1" 200 24358 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0"
[0] ::ffff:127.0.0.1 - - [17/Sun/2019:04:13:27 +0000] "GET /favicon.ico HTTP/1.1" 200 24358 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0"
[0] ::ffff:127.0.0.1 - - [17/Sun/2019:04:47:11 +0000] "GET /index.html HTTP/1.1" 200 7081 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0"

morganのログフォーマット形式については、公式にあるのでそちらを参照してください。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0