lite-server icon indicating copy to clipboard operation
lite-server copied to clipboard

How to stop verbose output to the console

Open areijngoudt opened this issue 8 years ago • 8 comments

I have lite-server setup in package.json:

"scripts": {
    "start": "concurrently \"npm run tsc:w\" \"npm run scss:w\" \"npm run lite\" ",
    "tsc": "tsc --inlineSourceMap --allowSyntheticDefaultImports -outDir .build/js",
    "tsc:w": "tsc -w --inlineSourceMap --allowSyntheticDefaultImports -outDir .build/js",
    "scss": "node-sass --include-path styles/app.scss .build/css/app.css",
    "scss:w": "node-sass -w --include-path styles styles/app.scss .build/css/app.css",
    "lite": "lite-server -c bs-config.json",
    "typings": "typings",
    "postinstall": "typings install"
  },

with the following bs-config.json file:

{
    "notify": false,
    "files": ["./.build/css/*.css", "./.build/js/**/*.js", "./app/**/*.{html,css}", "index.html"],
    "injectChanges": true,
    "logLevel": "silent",
    "debugInfo": false,
    "ghostMode": false,
     "server": { "baseDir": "." }
}

Upon starting I see that the bs-config.json configuration is written to te console:

** browser-sync config **
[2] { injectChanges: true,
[2]   files: 
[2]    [ './.build/css/*.css',
[2]      './.build/js/**/*.js',
[2]      './app/**/*.{html,css}',
[2]      'index.html' ],
[2]   watchOptions: { ignored: 'node_modules' },
[2]   server: { baseDir: '.', middleware: [ [Function], [Function] ] },
[2]   notify: false,
[2]   logLevel: 'silent',
[2]   debugInfo: false,
[2]   ghostMode: false }
[0] 8:02:46 AM - Compilation complete. Watching for file changes.

Since the logLevel is set to silent, I expect to see very little info in the console. However, each and every get is displayed:

[2] 16.04.23 08:02:50 200 GET /index.html
[2] 16.04.23 08:02:50 304 GET /node_modules/bootstrap/dist/css/bootstrap.min.css
[2] 16.04.23 08:02:50 304 GET /node_modules/font-awesome/css/font-awesome.min.css
[2] 16.04.23 08:02:50 304 GET /node_modules/ng2-notify/dist/css/ng2notify.css
[2] 16.04.23 08:02:50 304 GET /.build/css/app.css
[2] 16.04.23 08:02:50 304 GET /node_modules/es6-shim/es6-shim.min.js
[2] 16.04.23 08:02:50 304 GET /node_modules/angular2/bundles/angular2-polyfills.js
[2] 16.04.23 08:02:50 304 GET /node_modules/systemjs/dist/system-polyfills.js
[2] 16.04.23 08:02:50 304 GET /node_modules/angular2/es6/dev/src/testing/shims_for_IE.js
[2] 16.04.23 08:02:50 304 GET /node_modules/systemjs/dist/system.src.js
[2] 16.04.23 08:02:50 304 GET /node_modules/rxjs/bundles/Rx.js
[2] 16.04.23 08:02:50 304 GET /node_modules/angular2/bundles/angular2.dev.js
etc...

Environment

  • lite-server version: 2.2.0
  • nodejs version: 5.7.1
  • npm version: 3.8.0
  • OS type/version: OSX

areijngoudt avatar Apr 23 '16 06:04 areijngoudt

:+1: would love to have a way to hide those logs.

raphaelparent avatar May 05 '16 20:05 raphaelparent

I'd recommend to write your "lite" script like that: "lite": "lite-server -c bs-config.json > /dev/null", It works fine to me

terciodemelo avatar May 09 '16 03:05 terciodemelo

If you do not want to see all HTTP requests, you will need to disable the logging middleware as described in README.md.

So in stead of a bs-config.json , use a bs-config.js file like this one:

module.exports = {
  logLevel: "silent",
  server: {
    middleware: {
      0: null
    }
  }
};

the 0:null clears out the first middleware, which is the logger. You might still want to set the logLevel to "silent" or "debug" as well, since browsersync by itself can be quite verbose as well

houbenbert avatar Jun 14 '16 19:06 houbenbert

Personally I wanted to keep the middleware logger, but hide the success response. So I finally use npm start |grep -v "200" |grep -v "304"

GabrielDelepine avatar Jul 13 '16 12:07 GabrielDelepine

Thanks @houbenbert ! works like a charm!

lasanthabandara avatar Sep 18 '16 13:09 lasanthabandara

Thanks @GabrielDelepine, exactly what I needed!

rbosneag avatar Oct 08 '16 09:10 rbosneag

Any change to remove 200 and 304 code natively?

I have the same behaviour and I wish to made via bs-config.

Thanks

fromcouch avatar Feb 21 '17 14:02 fromcouch

A quick hack: lite-server configures the http request logger in lib\config-defaults.js which in turn uses the module 'connect-logger'

var log = require('connect-logger')

Intercept log messages by putting a wrapper around the log function:

var proxy = function(options) {

    console.log('Proxy logger');
    var targetLog = log(options);

    return function(req, res, next) {
        var originalEnd = res.end;
        var targetNext = targetLog(req, res, next);

        //res.end is now a new function
        var targetEnd = res.end;

        res.end = function(chunk, encoding) {
            if (res.statusCode === 200 || res.statusCode === 304) {
                res.end = originalEnd;
                res.end(chunk, encoding);
                return undefined;
            } else {
                return targetEnd(chunk, encoding);
            }
        };
        return targetNext;
    };
}

And in the middleware config replace log() with proxy():

proxy({ format: '%date %status %method %url' })

A bit painful because of the nesting hell. Probably a simpler solution but works for me

hamioraz avatar Mar 22 '17 06:03 hamioraz