Skip to content

Commit 4b9e83e

Browse files
committed
Add clientLogLevel option and --client-log-level flag.
This option can be `error`, `warning`, `info` or `none`. It defaults to `info`. It controls the log messages shown in the browser.
1 parent 4e1a7ed commit 4b9e83e

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

bin/webpack-dev-server.js

+9
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ yargs.options({
6363
group: DISPLAY_GROUP,
6464
describe: "Quiet"
6565
},
66+
"client-log-level": {
67+
type: "string",
68+
group: DISPLAY_GROUP,
69+
default: "info",
70+
describe: "Log level in the browser (info, warning, error or none)"
71+
},
6672
"https": {
6773
type: "boolean",
6874
group: SSL_GROUP,
@@ -178,6 +184,9 @@ function processOptions(wpOpt) {
178184
if(!options.hotOnly)
179185
options.hotOnly = argv["hot-only"];
180186

187+
if(!options.clientLogLevel)
188+
options.clientLogLevel = argv["client-log-level"];
189+
181190
if(argv["content-base"]) {
182191
options.contentBase = argv["content-base"];
183192
if(/^[0-9]$/.test(options.contentBase))

client/index.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,14 @@ var sock = null;
1717
var hot = false;
1818
var initial = true;
1919
var currentHash = "";
20-
var quiet = false;
21-
var noInfo = true;
22-
var logLevel = 3; // 3 = all, 2 = warnings and errors, 1 = only errors, 0 = quiet
20+
var logLevel = "info";
2321

2422
function log(level, msg) {
25-
if(logLevel >= 3 && level === "info")
23+
if(logLevel === "info" && level === "info")
2624
return console.log(msg);
27-
if(logLevel >= 2 && level === "warning")
25+
if(["info", "warning"].indexOf(logLevel) >= 0 && level === "warning")
2826
return console.warn(msg);
29-
if(logLevel >= 1 && level === "error")
27+
if(["info", "warning", "error"].indexOf(logLevel) >= 0 && level === "error")
3028
return console.error(msg);
3129
}
3230

@@ -54,14 +52,14 @@ var onSocketMsg = {
5452
warnings: function(warnings) {
5553
log("info", "[WDS] Warnings while compiling.");
5654
for(var i = 0; i < warnings.length; i++)
57-
log("warn", stripAnsi(warnings[i]));
55+
console.warn(stripAnsi(warnings[i]));
5856
if(initial) return initial = false;
5957
reloadApp();
6058
},
6159
errors: function(errors) {
6260
log("info", "[WDS] Errors while compiling.");
6361
for(var i = 0; i < errors.length; i++)
64-
log("error", stripAnsi(errors[i]));
62+
console.error(stripAnsi(errors[i]));
6563
if(initial) return initial = false;
6664
reloadApp();
6765
},

lib/Server.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ function Server(compiler, options) {
2121

2222
this.hot = options.hot || options.hotOnly;
2323
this.headers = options.headers;
24-
this.noInfo = options.noInfo;
25-
this.quiet = options.quiet;
24+
this.clientLogLevel = options.clientLogLevel;
2625
this.sockets = [];
2726

2827
// Listening for events
@@ -342,8 +341,8 @@ Server.prototype.listen = function() {
342341

343342
if(this.hot) this.sockWrite([conn], "hot");
344343

345-
if(this.quiet || this.noInfo)
346-
this.sockWrite([conn], "log-level", this.quiet ? 0 : 2);
344+
if(this.clientLogLevel)
345+
this.sockWrite([conn], "log-level", this.clientLogLevel);
347346
if(!this._stats) return;
348347
this._sendStats([conn], this._stats.toJson(), true);
349348
}.bind(this));

0 commit comments

Comments
 (0)