Skip to content

Commit

Permalink
Merge pull request #1155 from DustinCampbell/clean-up-omnisharp-log
Browse files Browse the repository at this point in the history
Don't add unnecessary noise to the OmniSharp log
  • Loading branch information
DustinCampbell authored Jan 30, 2017
2 parents eeabef3 + c006ba5 commit bae80cd
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions src/omnisharp/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit bae80cd

Please sign in to comment.