-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Migrate server on infrastructure logger #2614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ const Server = require('../lib/Server'); | |
const setupExitSignals = require('../lib/utils/setupExitSignals'); | ||
const colors = require('../lib/utils/colors'); | ||
const processOptions = require('../lib/utils/processOptions'); | ||
const createLogger = require('../lib/utils/createLogger'); | ||
const getVersions = require('../lib/utils/getVersions'); | ||
const options = require('./options'); | ||
|
||
|
@@ -86,15 +85,13 @@ const config = require(convertArgvPath)(yargs, argv, { | |
}); | ||
|
||
function startDevServer(config, options) { | ||
const log = createLogger(options); | ||
|
||
let compiler; | ||
|
||
try { | ||
compiler = webpack(config); | ||
} catch (err) { | ||
if (err instanceof webpack.WebpackOptionsValidationError) { | ||
log.error(colors.error(options.stats.colors, err.message)); | ||
console.error(colors.error(options.stats.colors, err.message)); | ||
// eslint-disable-next-line no-process-exit | ||
process.exit(1); | ||
} | ||
|
@@ -103,11 +100,11 @@ function startDevServer(config, options) { | |
} | ||
|
||
try { | ||
server = new Server(compiler, options, log); | ||
server = new Server(compiler, options); | ||
serverData.server = server; | ||
} catch (err) { | ||
if (err.name === 'ValidationError') { | ||
log.error(colors.error(options.stats.colors, err.message)); | ||
console.error(colors.error(options.stats.colors, err.message)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's use console |
||
// eslint-disable-next-line no-process-exit | ||
process.exit(1); | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,6 @@ const validateOptions = require('schema-utils'); | |
const isAbsoluteUrl = require('is-absolute-url'); | ||
const normalizeOptions = require('./utils/normalizeOptions'); | ||
const updateCompiler = require('./utils/updateCompiler'); | ||
const createLogger = require('./utils/createLogger'); | ||
const getCertificate = require('./utils/getCertificate'); | ||
const status = require('./utils/status'); | ||
const createDomain = require('./utils/createDomain'); | ||
|
@@ -38,16 +37,16 @@ if (!process.env.WEBPACK_DEV_SERVER) { | |
} | ||
|
||
class Server { | ||
constructor(compiler, options = {}, _log) { | ||
constructor(compiler, options = {}) { | ||
validateOptions(schema, options, 'webpack Dev Server'); | ||
|
||
this.compiler = compiler; | ||
this.options = options; | ||
this.logger = this.compiler.getInfrastructureLogger('webpack-dev-server'); | ||
this.sockets = []; | ||
this.contentBaseWatchers = []; | ||
// Keep track of websocket proxies for external websocket upgrade. | ||
this.websocketProxies = []; | ||
this.log = _log || createLogger(options); | ||
// this value of ws can be overwritten for tests | ||
this.wsHeartbeatInterval = 30000; | ||
|
||
|
@@ -149,7 +148,9 @@ class Server { | |
// middleware for serving webpack bundle | ||
this.middleware = webpackDevMiddleware( | ||
this.compiler, | ||
Object.assign({}, this.options, { logLevel: this.log.options.level }) | ||
Object.assign({}, this.options, { | ||
logger: this.logger, | ||
}) | ||
); | ||
} | ||
|
||
|
@@ -189,7 +190,26 @@ class Server { | |
proxyOptions.context = correctedContext; | ||
} | ||
|
||
proxyOptions.logLevel = proxyOptions.logLevel || 'warn'; | ||
const getLogLevelForProxy = (level) => { | ||
if (level === 'none') { | ||
return 'silent'; | ||
} | ||
|
||
if (level === 'log') { | ||
return 'info'; | ||
} | ||
|
||
if (level === 'verbose') { | ||
return 'debug'; | ||
} | ||
|
||
return level; | ||
}; | ||
|
||
proxyOptions.logLevel = getLogLevelForProxy( | ||
this.compiler.options.infrastructureLogging.level | ||
); | ||
proxyOptions.logProvider = () => this.logger; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improve logging for proxy |
||
|
||
return proxyOptions; | ||
}); | ||
|
@@ -302,11 +322,11 @@ class Server { | |
this.app.use(publicPath, express.static(item)); | ||
}); | ||
} else if (isAbsoluteUrl(String(contentBase))) { | ||
this.log.warn( | ||
this.logger.warn( | ||
'Using a URL as contentBase is deprecated and will be removed in the next major version. Please use the proxy option instead.' | ||
); | ||
|
||
this.log.warn( | ||
this.logger.warn( | ||
'proxy: {\n\t"*": "<your current contentBase configuration>"\n}' | ||
); | ||
|
||
|
@@ -319,11 +339,11 @@ class Server { | |
res.end(); | ||
}); | ||
} else if (typeof contentBase === 'number') { | ||
this.log.warn( | ||
this.logger.warn( | ||
'Using a number as contentBase is deprecated and will be removed in the next major version. Please use the proxy option instead.' | ||
); | ||
|
||
this.log.warn( | ||
this.logger.warn( | ||
'proxy: {\n\t"*": "//localhost:<your current contentBase configuration>"\n}' | ||
); | ||
|
||
|
@@ -548,7 +568,7 @@ class Server { | |
let fakeCert; | ||
|
||
if (!this.options.https.key || !this.options.https.cert) { | ||
fakeCert = getCertificate(this.log); | ||
fakeCert = getCertificate(this.logger); | ||
} | ||
|
||
this.options.https.key = this.options.https.key || fakeCert; | ||
|
@@ -577,7 +597,7 @@ class Server { | |
} | ||
|
||
this.listeningApp.on('error', (err) => { | ||
this.log.error(err); | ||
this.logger.error(err); | ||
}); | ||
} | ||
|
||
|
@@ -590,7 +610,7 @@ class Server { | |
} | ||
|
||
if (!headers) { | ||
this.log.warn( | ||
this.logger.warn( | ||
'transportMode.server implementation must pass headers to the callback of onConnection(f) ' + | ||
'via f(connection, headers) in order for clients to pass a headers security check' | ||
); | ||
|
@@ -650,7 +670,7 @@ class Server { | |
status( | ||
uri, | ||
this.options, | ||
this.log, | ||
this.logger, | ||
this.options.stats && this.options.stats.colors | ||
); | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's use console