-
Notifications
You must be signed in to change notification settings - Fork 208
/
LoggingDiagnosticReporter.ts
40 lines (36 loc) · 1.7 KB
/
LoggingDiagnosticReporter.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Diagnostic
*/
import { Logger } from "@itwin/core-bentley";
import { AnyDiagnostic, DiagnosticCategory } from "./Diagnostic";
import { FormatDiagnosticReporter } from "./DiagnosticReporter";
const loggingCategory = "ecschema-metadata";
/**
* An [[IDiagnosticReporter]] for logging [[IDiagnostic]] objects.
* @beta
*/
export class LoggingDiagnosticReporter extends FormatDiagnosticReporter {
public reportDiagnostic(diagnostic: AnyDiagnostic, messageText: string) {
switch (diagnostic.category) {
case DiagnosticCategory.Error:
Logger.logError(loggingCategory, messageText, () => this.getLogMetaData(diagnostic));
return;
case DiagnosticCategory.Warning:
Logger.logWarning(loggingCategory, messageText, () => this.getLogMetaData(diagnostic));
return;
case DiagnosticCategory.Message:
case DiagnosticCategory.Suggestion:
Logger.logInfo(loggingCategory, messageText, () => this.getLogMetaData(diagnostic));
return;
default:
Logger.logTrace(loggingCategory, messageText, () => this.getLogMetaData(diagnostic));
}
}
private getLogMetaData(diagnostic: AnyDiagnostic) {
return { ...diagnostic, ...{ code: diagnostic.code, category: diagnostic.category, diagnosticType: diagnostic.diagnosticType, messageText: undefined, messageArgs: undefined } };
}
}