From c75df1c6a0d19aca71946a732ed834b43e69a761 Mon Sep 17 00:00:00 2001 From: Robin Stevens Date: Sat, 15 Feb 2020 21:22:30 +0100 Subject: [PATCH] feat(logger): Count warnings (#1205) If you want to make your build fail on error messages, you currently can do ``` const result = app.generateDocs(project, OUTPUT_DIR); if (!result || app.logger.hasErrors() ) { console.log("Errors were logged during the generation of the documentation. Check the log for more information"); process.exit(1); } ``` However, warning messages typically indicate a problem as well. If you want to make your build fail on those as well, you need a custom logger to keep track of the warning messages yourself. This PR makes this easier by counting the warning messages in a similar fashion as the error messages. --- src/lib/utils/loggers.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/lib/utils/loggers.ts b/src/lib/utils/loggers.ts index f5312e0cc..38057d31c 100644 --- a/src/lib/utils/loggers.ts +++ b/src/lib/utils/loggers.ts @@ -24,6 +24,11 @@ export class Logger { */ errorCount = 0; + /** + * How many warning messages have been logged? + */ + warningCount = 0; + /** * Has an error been raised through the log method? */ @@ -31,6 +36,13 @@ export class Logger { return this.errorCount > 0; } + /** + * Has a warning been raised through the log method? + */ + public hasWarnings(): boolean { + return this.warningCount > 0; + } + /** * Reset the error counter. */ @@ -38,6 +50,13 @@ export class Logger { this.errorCount = 0; } + /** + * Reset the warning counter. + */ + public resetWarnings() { + this.warningCount = 0; + } + /** * Log the given message. * @@ -109,6 +128,9 @@ export class Logger { if (level === LogLevel.Error) { this.errorCount += 1; } + if (level === LogLevel.Warn) { + this.warningCount += 1; + } } /**