|
3 | 3 | 'use strict'; |
4 | 4 |
|
5 | 5 | import * as winston from 'winston'; |
6 | | -import { isCI } from '../common/constants'; |
7 | 6 | import { IOutputChannel } from '../common/types'; |
8 | 7 | import { CallInfo } from '../common/utils/decorators'; |
9 | 8 | import { getFormatter } from './formatters'; |
10 | 9 | import { LogLevel, resolveLevelName } from './levels'; |
11 | | -import { configureLogger, createLogger, ILogger, LoggerConfig, logToAll } from './logger'; |
| 10 | +import { configureLogger, createLogger, getPreDefinedConfiguration, logToAll } from './logger'; |
12 | 11 | import { createTracingDecorator, LogInfo, TraceOptions, tracing as _tracing } from './trace'; |
13 | 12 | import { getPythonOutputChannelTransport } from './transports'; |
14 | 13 | import { Arguments } from './util'; |
@@ -40,35 +39,7 @@ initialize(); |
40 | 39 | * this is setup on CI servers. |
41 | 40 | */ |
42 | 41 | function initialize() { |
43 | | - const config: LoggerConfig = {}; |
44 | | - let nonConsole = false; |
45 | | - |
46 | | - // Do not log to console if running tests and we're not |
47 | | - // asked to do so. |
48 | | - if (process.env.VSC_PYTHON_FORCE_LOGGING) { |
49 | | - config.console = {}; |
50 | | - // In CI there's no need for the label. |
51 | | - if (!isCI) { |
52 | | - config.console.label = 'Python Extension:'; |
53 | | - } |
54 | | - } |
55 | | - if (process.env.VSC_PYTHON_LOG_FILE) { |
56 | | - config.file = { |
57 | | - logfile: process.env.VSC_PYTHON_LOG_FILE |
58 | | - }; |
59 | | - nonConsole = true; |
60 | | - } |
61 | | - configureLogger(globalLogger, config); |
62 | | - |
63 | | - if (isCI && nonConsole) { |
64 | | - delete config.console; |
65 | | - // Send console.*() to the non-console loggers. |
66 | | - monkeypatchConsole( |
67 | | - // This is a separate logger that matches our config but |
68 | | - // does not do any console logging. |
69 | | - createLogger(config) |
70 | | - ); |
71 | | - } |
| 42 | + configureLogger(globalLogger, getPreDefinedConfiguration()); |
72 | 43 | } |
73 | 44 |
|
74 | 45 | // Set the logging level the extension logs at. |
@@ -144,37 +115,3 @@ export namespace traceDecorators { |
144 | 115 | return createTracingDecorator([globalLogger], { message, opts, level }); |
145 | 116 | } |
146 | 117 | } |
147 | | - |
148 | | -/** |
149 | | - * What we're doing here is monkey patching the console.log so we can |
150 | | - * send everything sent to console window into our logs. This is only |
151 | | - * required when we're directly writing to `console.log` or not using |
152 | | - * our `winston logger`. This is something we'd generally turn on, only |
153 | | - * on CI so we can see everything logged to the console window |
154 | | - * (via the logs). |
155 | | - */ |
156 | | -function monkeypatchConsole(logger: ILogger) { |
157 | | - // The logging "streams" (methods) of the node console. |
158 | | - const streams = ['log', 'error', 'warn', 'info', 'debug', 'trace']; |
159 | | - const levels: { [key: string]: LogLevel } = { |
160 | | - error: LogLevel.Error, |
161 | | - warn: LogLevel.Warn |
162 | | - }; |
163 | | - // tslint:disable-next-line:no-any |
164 | | - const consoleAny: any = console; |
165 | | - for (const stream of streams) { |
166 | | - // Using symbols guarantee the properties will be unique & prevents |
167 | | - // clashing with names other code/library may create or have created. |
168 | | - // We could use a closure but it's a bit trickier. |
169 | | - const sym = Symbol.for(stream); |
170 | | - consoleAny[sym] = consoleAny[stream]; |
171 | | - // tslint:disable-next-line: no-function-expression |
172 | | - consoleAny[stream] = function () { |
173 | | - const args = Array.prototype.slice.call(arguments); |
174 | | - const fn = consoleAny[sym]; |
175 | | - fn(...args); |
176 | | - const level = levels[stream] || LogLevel.Info; |
177 | | - logToAll([logger], level, args); |
178 | | - }; |
179 | | - } |
180 | | -} |
0 commit comments