Skip to content

Commit

Permalink
feat(language-service): enable logging on TypeScriptHost (angular#32645)
Browse files Browse the repository at this point in the history
This PR adds loggin methods to TypeScriptHost so that proper logging
to file could be done.
Three new methods are added: log(), error(), and debug().

PR Close angular#32645
  • Loading branch information
Keen Yee Liau authored and arnehoek committed Sep 26, 2019
1 parent ce731f8 commit 61d116f
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions packages/language-service/src/typescript_host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import {AotSummaryResolver, CompileDirectiveSummary, CompileMetadataResolver, CompileNgModuleMetadata, CompilePipeSummary, CompilerConfig, DirectiveNormalizer, DirectiveResolver, DomElementSchemaRegistry, FormattedError, FormattedMessageChain, HtmlParser, I18NHtmlParser, JitSummaryResolver, Lexer, NgAnalyzedModules, NgModuleResolver, ParseTreeResult, Parser, PipeResolver, ResourceLoader, StaticReflector, StaticSymbol, StaticSymbolCache, StaticSymbolResolver, TemplateParser, analyzeNgModules, createOfflineCompileUrlResolver, isFormattedError} from '@angular/compiler';
import {SchemaMetadata, ViewEncapsulation, ɵConsole as Console} from '@angular/core';
import * as ts from 'typescript';
import * as tss from 'typescript/lib/tsserverlibrary';

import {AstResult, isAstResult} from './common';
import {createLanguageService} from './language_service';
Expand Down Expand Up @@ -525,6 +526,45 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
};
}
}

/**
* Log the specified `msg` to file at INFO level. If logging is not enabled
* this method is a no-op.
* @param msg Log message
*/
log(msg: string) {
if (this.tsLsHost.log) {
this.tsLsHost.log(msg);
}
}

/**
* Log the specified `msg` to file at ERROR level. If logging is not enabled
* this method is a no-op.
* @param msg error message
*/
error(msg: string) {
if (this.tsLsHost.error) {
this.tsLsHost.error(msg);
}
}

/**
* Log debugging info to file at INFO level, only if verbose setting is turned
* on. Otherwise, this method is a no-op.
* @param msg debugging message
*/
debug(msg: string) {
const project = this.tsLsHost as tss.server.Project;
if (!project.projectService) {
// tsLsHost is not a Project
return;
}
const {logger} = project.projectService;
if (logger.hasLevel(tss.server.LogLevel.verbose)) {
logger.info(msg);
}
}
}

function findSuitableDefaultModule(modules: NgAnalyzedModules): CompileNgModuleMetadata|undefined {
Expand Down

0 comments on commit 61d116f

Please sign in to comment.