Open areijngoudt opened 8 years ago
:+1: would love to have a way to hide those logs.
I'd recommend to write your "lite" script like that:
"lite": "lite-server -c bs-config.json > /dev/null",
It works fine to me
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
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"
Thanks @houbenbert ! works like a charm!
Thanks @GabrielDelepine, exactly what I needed!
Any change to remove 200 and 304 code natively?
I have the same behaviour and I wish to made via bs-config.
Thanks
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
I have lite-server setup in package.json:
with the following bs-config.json file:
Upon starting I see that the bs-config.json configuration is written to te console:
Since the logLevel is set to silent, I expect to see very little info in the console. However, each and every get is displayed:
Environment
lite-server
version: 2.2.0nodejs
version: 5.7.1npm
version: 3.8.0