-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Monkeypatch console.* calls on CI if we are asked to #11897
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
Changes from all commits
6e1ef62
ec56ade
194e78c
c50d3c0
0be67ed
ba21931
564491e
3295936
536919a
937dde3
d795c10
e245f0e
db4ef57
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Monkeypatch `console.*` calls to the logger only in CI. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| 'use strict'; | ||
|
|
||
| // IMPORTANT: This file should only be importing from the '../client/logging' directory, as we | ||
| // delete everything in '../client' except for '../client/logging' before running smoke tests. | ||
|
|
||
| import { LogLevel } from '../client/logging/levels'; | ||
| import { configureLogger, createLogger, getPreDefinedConfiguration, logToAll } from '../client/logging/logger'; | ||
|
|
||
| const isCI = process.env.TRAVIS === 'true' || process.env.TF_BUILD !== undefined; | ||
| const monkeyPatchLogger = createLogger(); | ||
|
karrtikr marked this conversation as resolved.
|
||
|
|
||
| export function initializeLogger() { | ||
| const config = getPreDefinedConfiguration(); | ||
|
karrtikr marked this conversation as resolved.
|
||
| if (isCI && process.env.VSC_PYTHON_LOG_FILE) { | ||
| delete config.console; | ||
| // This is a separate logger that matches our config but | ||
| // does not do any console logging. | ||
| configureLogger(monkeyPatchLogger, config); | ||
|
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. This means
Author
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. We use 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. As long as we're sure about FWIW, my only objective was to make sure this had been considered and wasn't a problem (rather than to say there was a problem). 🙂 |
||
| // Send console.*() to the non-console loggers. | ||
| monkeypatchConsole(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * What we're doing here is monkey patching the console.log so we can | ||
| * send everything sent to console window into our logs. This is only | ||
| * required when we're directly writing to `console.log` or not using | ||
| * our `winston logger`. This is something we'd generally turn on only | ||
| * on CI so we can see everything logged to the console window | ||
| * (via the logs). | ||
| */ | ||
| function monkeypatchConsole() { | ||
| // The logging "streams" (methods) of the node console. | ||
| const streams = ['log', 'error', 'warn', 'info', 'debug', 'trace']; | ||
| const levels: { [key: string]: LogLevel } = { | ||
| error: LogLevel.Error, | ||
| warn: LogLevel.Warn | ||
| }; | ||
| // tslint:disable-next-line:no-any | ||
| const consoleAny: any = console; | ||
| for (const stream of streams) { | ||
| // Using symbols guarantee the properties will be unique & prevents | ||
| // clashing with names other code/library may create or have created. | ||
| // We could use a closure but it's a bit trickier. | ||
| const sym = Symbol.for(stream); | ||
| consoleAny[sym] = consoleAny[stream]; | ||
| // tslint:disable-next-line: no-function-expression | ||
| consoleAny[stream] = function () { | ||
| const args = Array.prototype.slice.call(arguments); | ||
| const fn = consoleAny[sym]; | ||
| fn(...args); | ||
| const level = levels[stream] || LogLevel.Info; | ||
| logToAll([monkeyPatchLogger], level, args); | ||
| }; | ||
|
ericsnowcurrently marked this conversation as resolved.
|
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.