Revert public API changes to logger (#17899)
This commit is contained in:
Родитель
eef7d8bd3d
Коммит
ade3b565ae
|
@ -686,7 +686,7 @@ namespace Harness.LanguageService {
|
|||
this.host.log(message);
|
||||
}
|
||||
|
||||
err(message: string): void {
|
||||
msg(message: string): void {
|
||||
this.host.log(message);
|
||||
}
|
||||
|
||||
|
@ -702,7 +702,8 @@ namespace Harness.LanguageService {
|
|||
return false;
|
||||
}
|
||||
|
||||
group() { throw ts.notImplemented(); }
|
||||
startGroup() { throw ts.notImplemented(); }
|
||||
endGroup() { throw ts.notImplemented(); }
|
||||
|
||||
perftrc(message: string): void {
|
||||
return this.host.log(message);
|
||||
|
|
|
@ -39,8 +39,9 @@ namespace ts.projectSystem {
|
|||
loggingEnabled: () => false,
|
||||
perftrc: noop,
|
||||
info: noop,
|
||||
err: noop,
|
||||
group: noop,
|
||||
msg: noop,
|
||||
startGroup: noop,
|
||||
endGroup: noop,
|
||||
getLogFileName: (): string => undefined
|
||||
};
|
||||
|
||||
|
|
|
@ -958,28 +958,28 @@ namespace ts.server {
|
|||
return;
|
||||
}
|
||||
|
||||
this.logger.group(info => {
|
||||
let counter = 0;
|
||||
counter = printProjects(this.externalProjects, info, counter);
|
||||
counter = printProjects(this.configuredProjects, info, counter);
|
||||
printProjects(this.inferredProjects, info, counter);
|
||||
|
||||
info("Open files: ");
|
||||
for (const rootFile of this.openFiles) {
|
||||
info(`\t${rootFile.fileName}`);
|
||||
}
|
||||
});
|
||||
|
||||
function printProjects(projects: Project[], info: (msg: string) => void, counter: number): number {
|
||||
this.logger.startGroup();
|
||||
let counter = 0;
|
||||
const printProjects = (projects: Project[], counter: number): number => {
|
||||
for (const project of projects) {
|
||||
project.updateGraph();
|
||||
info(`Project '${project.getProjectName()}' (${ProjectKind[project.projectKind]}) ${counter}`);
|
||||
info(project.filesToString());
|
||||
info("-----------------------------------------------");
|
||||
this.logger.info(`Project '${project.getProjectName()}' (${ProjectKind[project.projectKind]}) ${counter}`);
|
||||
this.logger.info(project.filesToString());
|
||||
this.logger.info("-----------------------------------------------");
|
||||
counter++;
|
||||
}
|
||||
return counter;
|
||||
};
|
||||
counter = printProjects(this.externalProjects, counter);
|
||||
counter = printProjects(this.configuredProjects, counter);
|
||||
printProjects(this.inferredProjects, counter);
|
||||
|
||||
this.logger.info("Open files: ");
|
||||
for (const rootFile of this.openFiles) {
|
||||
this.logger.info(`\t${rootFile.fileName}`);
|
||||
}
|
||||
|
||||
this.logger.endGroup();
|
||||
}
|
||||
|
||||
private findConfiguredProjectByProjectName(configFileName: NormalizedPath) {
|
||||
|
|
|
@ -140,6 +140,8 @@ namespace ts.server {
|
|||
class Logger implements server.Logger {
|
||||
private fd = -1;
|
||||
private seq = 0;
|
||||
private inGroup = false;
|
||||
private firstInGroup = true;
|
||||
|
||||
constructor(private readonly logFilename: string,
|
||||
private readonly traceToConsole: boolean,
|
||||
|
@ -169,24 +171,24 @@ namespace ts.server {
|
|||
}
|
||||
|
||||
perftrc(s: string) {
|
||||
this.msg(s, "Perf");
|
||||
this.msg(s, Msg.Perf);
|
||||
}
|
||||
|
||||
info(s: string) {
|
||||
this.msg(s, "Info");
|
||||
this.msg(s, Msg.Info);
|
||||
}
|
||||
|
||||
err(s: string) {
|
||||
this.msg(s, "Err");
|
||||
this.msg(s, Msg.Err);
|
||||
}
|
||||
|
||||
group(logGroupEntries: (log: (msg: string) => void) => void) {
|
||||
let firstInGroup = false;
|
||||
logGroupEntries(s => {
|
||||
this.msg(s, "Info", /*inGroup*/ true, firstInGroup);
|
||||
firstInGroup = false;
|
||||
});
|
||||
this.seq++;
|
||||
startGroup() {
|
||||
this.inGroup = true;
|
||||
this.firstInGroup = true;
|
||||
}
|
||||
|
||||
endGroup() {
|
||||
this.inGroup = false;
|
||||
}
|
||||
|
||||
loggingEnabled() {
|
||||
|
@ -197,16 +199,16 @@ namespace ts.server {
|
|||
return this.loggingEnabled() && this.level >= level;
|
||||
}
|
||||
|
||||
private msg(s: string, type: string, inGroup = false, firstInGroup = false) {
|
||||
msg(s: string, type: Msg.Types = Msg.Err) {
|
||||
if (!this.canWrite) return;
|
||||
|
||||
s = `[${nowString()}] ${s}\n`;
|
||||
if (!inGroup || firstInGroup) {
|
||||
if (!this.inGroup || this.firstInGroup) {
|
||||
const prefix = Logger.padStringRight(type + " " + this.seq.toString(), " ");
|
||||
s = prefix + s;
|
||||
}
|
||||
this.write(s);
|
||||
if (!inGroup) {
|
||||
if (!this.inGroup) {
|
||||
this.seq++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -368,7 +368,7 @@ namespace ts.server {
|
|||
msg += "\n" + (<StackTraceError>err).stack;
|
||||
}
|
||||
}
|
||||
this.logger.err(msg);
|
||||
this.logger.msg(msg, Msg.Err);
|
||||
}
|
||||
|
||||
public send(msg: protocol.Message) {
|
||||
|
@ -1947,7 +1947,7 @@ namespace ts.server {
|
|||
return this.executeWithRequestId(request.seq, () => handler(request));
|
||||
}
|
||||
else {
|
||||
this.logger.err(`Unrecognized JSON command: ${JSON.stringify(request)}`);
|
||||
this.logger.msg(`Unrecognized JSON command: ${JSON.stringify(request)}`, Msg.Err);
|
||||
this.output(undefined, CommandNames.Unknown, request.seq, `Unrecognized JSON command: ${request.command}`);
|
||||
return { responseRequired: false };
|
||||
}
|
||||
|
|
|
@ -17,11 +17,22 @@ namespace ts.server {
|
|||
loggingEnabled(): boolean;
|
||||
perftrc(s: string): void;
|
||||
info(s: string): void;
|
||||
err(s: string): void;
|
||||
group(logGroupEntries: (log: (msg: string) => void) => void): void;
|
||||
startGroup(): void;
|
||||
endGroup(): void;
|
||||
msg(s: string, type?: Msg.Types): void;
|
||||
getLogFileName(): string;
|
||||
}
|
||||
|
||||
export namespace Msg {
|
||||
export type Err = "Err";
|
||||
export const Err: Err = "Err";
|
||||
export type Info = "Info";
|
||||
export const Info: Info = "Info";
|
||||
export type Perf = "Perf";
|
||||
export const Perf: Perf = "Perf";
|
||||
export type Types = Err | Info | Perf;
|
||||
}
|
||||
|
||||
function getProjectRootPath(project: Project): Path {
|
||||
switch (project.projectKind) {
|
||||
case ProjectKind.Configured:
|
||||
|
@ -115,9 +126,7 @@ namespace ts.server {
|
|||
}
|
||||
|
||||
export function createNormalizedPathMap<T>(): NormalizedPathMap<T> {
|
||||
/* tslint:disable:no-null-keyword */
|
||||
const map = createMap<T>();
|
||||
/* tslint:enable:no-null-keyword */
|
||||
return {
|
||||
get(path) {
|
||||
return map.get(path);
|
||||
|
|
Загрузка…
Ссылка в новой задаче