@@ -21,15 +21,16 @@ const sockjs = require('sockjs');
21
21
const spdy = require ( 'spdy' ) ;
22
22
const webpack = require ( 'webpack' ) ;
23
23
const webpackDevMiddleware = require ( 'webpack-dev-middleware' ) ;
24
+ const createLog = require ( './createLog' ) ;
24
25
const OptionsValidationError = require ( './OptionsValidationError' ) ;
25
26
const optionsSchema = require ( './optionsSchema.json' ) ;
26
27
27
28
const clientStats = { errorDetails : false } ;
28
- const log = console . log ; // eslint-disable-line no-console
29
29
30
- function Server ( compiler , options ) {
30
+ function Server ( compiler , options , _log ) {
31
31
// Default options
32
32
if ( ! options ) options = { } ;
33
+ this . log = _log || createLog ( options ) ;
33
34
34
35
const validationErrors = webpack . validateSchema ( optionsSchema , options ) ;
35
36
if ( validationErrors . length ) {
@@ -88,14 +89,8 @@ function Server(compiler, options) {
88
89
res . send ( 'Invalid Host header' ) ;
89
90
} ) ;
90
91
91
- const wdmOptions = { } ;
92
+ const wdmOptions = { logLevel : this . log . options . level } ;
92
93
93
- if ( options . quiet === true ) {
94
- wdmOptions . logLevel = 'silent' ;
95
- }
96
- if ( options . noInfo === true ) {
97
- wdmOptions . logLevel = 'warn' ;
98
- }
99
94
// middleware for serving webpack bundle
100
95
this . middleware = webpackDevMiddleware ( compiler , Object . assign ( { } , options , wdmOptions ) ) ;
101
96
@@ -286,14 +281,14 @@ function Server(compiler, options) {
286
281
}
287
282
} ,
288
283
289
- contentBaseFiles ( ) {
284
+ contentBaseFiles : ( ) => {
290
285
if ( Array . isArray ( contentBase ) ) {
291
286
contentBase . forEach ( ( item ) => {
292
287
app . get ( '*' , express . static ( item ) ) ;
293
288
} ) ;
294
289
} else if ( / ^ ( h t t p s ? : ) ? \/ \/ / . test ( contentBase ) ) {
295
- log ( 'Using a URL as contentBase is deprecated and will be removed in the next major version. Please use the proxy option instead.' ) ;
296
- log ( 'proxy: {\n\t"*": "<your current contentBase configuration>"\n}' ) ; // eslint-disable-line quotes
290
+ this . log . warn ( 'Using a URL as contentBase is deprecated and will be removed in the next major version. Please use the proxy option instead.' ) ;
291
+ this . log . warn ( 'proxy: {\n\t"*": "<your current contentBase configuration>"\n}' ) ; // eslint-disable-line quotes
297
292
// Redirect every request to contentBase
298
293
app . get ( '*' , ( req , res ) => {
299
294
res . writeHead ( 302 , {
@@ -302,8 +297,8 @@ function Server(compiler, options) {
302
297
res . end ( ) ;
303
298
} ) ;
304
299
} else if ( typeof contentBase === 'number' ) {
305
- log ( 'Using a number as contentBase is deprecated and will be removed in the next major version. Please use the proxy option instead.' ) ;
306
- log ( 'proxy: {\n\t"*": "//localhost:<your current contentBase configuration>"\n}' ) ; // eslint-disable-line quotes
300
+ this . log . warn ( 'Using a number as contentBase is deprecated and will be removed in the next major version. Please use the proxy option instead.' ) ;
301
+ this . log . warn ( 'proxy: {\n\t"*": "//localhost:<your current contentBase configuration>"\n}' ) ; // eslint-disable-line quotes
307
302
// Redirect every request to the port contentBase
308
303
app . get ( '*' , ( req , res ) => {
309
304
res . writeHead ( 302 , {
@@ -364,7 +359,7 @@ function Server(compiler, options) {
364
359
365
360
setup : ( ) => {
366
361
if ( typeof options . setup === 'function' ) {
367
- log ( 'The `setup` option is deprecated and will be removed in v3. Please update your config to use `before`' ) ;
362
+ this . log . warn ( 'The `setup` option is deprecated and will be removed in v3. Please update your config to use `before`' ) ;
368
363
options . setup ( app , this ) ;
369
364
}
370
365
}
@@ -415,14 +410,14 @@ function Server(compiler, options) {
415
410
416
411
// cert is more than 30 days old, kill it with fire
417
412
if ( ( now - certStat . ctime ) / certTtl > 30 ) {
418
- log ( 'SSL Certificate is more than 30 days old. Removing.' ) ;
413
+ this . log . info ( 'SSL Certificate is more than 30 days old. Removing.' ) ;
419
414
del . sync ( [ certPath ] , { force : true } ) ;
420
415
certExists = false ;
421
416
}
422
417
}
423
418
424
419
if ( ! certExists ) {
425
- log ( 'Generating SSL Certificate' ) ;
420
+ this . log . info ( 'Generating SSL Certificate' ) ;
426
421
const attrs = [ { name : 'commonName' , value : 'localhost' } ] ;
427
422
const pems = selfsigned . generate ( attrs , {
428
423
algorithm : 'sha256' ,
@@ -573,16 +568,16 @@ Server.prototype.checkHost = function (headers) {
573
568
// delegate listen call and init sockjs
574
569
Server . prototype . listen = function ( port , hostname , fn ) {
575
570
this . listenHostname = hostname ;
576
- // eslint-disable-next-line
577
-
578
571
const returnValue = this . listeningApp . listen ( port , hostname , ( err ) => {
579
572
const sockServer = sockjs . createServer ( {
580
573
// Use provided up-to-date sockjs-client
581
574
sockjs_url : '/__webpack_dev_server__/sockjs.bundle.js' ,
582
575
// Limit useless logs
583
- log ( severity , line ) {
576
+ log : ( severity , line ) => {
584
577
if ( severity === 'error' ) {
585
- log ( line ) ;
578
+ this . log . error ( line ) ;
579
+ } else {
580
+ this . log . debug ( line ) ;
586
581
}
587
582
}
588
583
} ) ;
0 commit comments