From c006ba58ec446aa86ba57e04002a69fabcaa8b51 Mon Sep 17 00:00:00 2001 From: Dustin Campbell Date: Fri, 27 Jan 2017 10:12:46 -0800 Subject: [PATCH] Don't add unnecessary noise to the OmniSharp log --- src/omnisharp/server.ts | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/omnisharp/server.ts b/src/omnisharp/server.ts index cf4f886a2..f367f2c45 100644 --- a/src/omnisharp/server.ts +++ b/src/omnisharp/server.ts @@ -13,6 +13,7 @@ import { DelayTracker } from './delayTracker'; import { LaunchTarget, findLaunchTargets } from './launcher'; import { Request, RequestQueueCollection } from './requestQueue'; import TelemetryReporter from 'vscode-extension-telemetry'; +import * as os from 'os'; import * as path from 'path'; import * as protocol from './protocol'; import * as vscode from 'vscode'; @@ -539,7 +540,7 @@ export class OmniSharpServer { if (packet.Event === 'log') { const entry = <{ LogLevel: string; Name: string; Message: string; }>packet.Body; this._logOutput(entry.LogLevel, entry.Name, entry.Message); - } + } else { // fwd all other events this._fireEvent(packet.Event, packet.Body); @@ -569,13 +570,34 @@ export class OmniSharpServer { return id; } + private static getLogLevelPrefix(logLevel: string) { + switch (logLevel) { + case "TRACE": return "trce"; + case "DEBUG": return "dbug"; + case "INFORMATION": return "info"; + case "WARNING": return "warn"; + case "ERROR": return "fail"; + case "CRITICAL": return "crit"; + default: throw new Error(`Unknown log level value: ${logLevel}`); + } + } + + private _isFilterableOutput(logLevel: string, name: string, message: string) { + // filter messages like: /codecheck: 200 339ms + const timing200Pattern = /^\/[\/\w]+: 200 \d+ms/; + + return logLevel === "INFORMATION" + && name === "OmniSharp.Middleware.LoggingMiddleware" + && timing200Pattern.test(message); + } + private _logOutput(logLevel: string, name: string, message: string) { - const timing200Pattern = /^\[INFORMATION:OmniSharp.Middleware.LoggingMiddleware\] \/[\/\w]+: 200 \d+ms/; + if (this._debugMode || !this._isFilterableOutput(logLevel, name, message)) { + let output = `[${OmniSharpServer.getLogLevelPrefix(logLevel)}]: ${name}${os.EOL}${message}`; + + const newLinePlusPadding = os.EOL + " "; + output = output.replace(os.EOL, newLinePlusPadding); - const output = `[${logLevel}:${name}] ${message}`; - - // strip stuff like: /codecheck: 200 339ms - if (this._debugMode || !timing200Pattern.test(output)) { this._logger.appendLine(output); } }