Skip to content

Commit

Permalink
feat(logger): Count warnings (#1205)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
PissedCapslock authored Feb 15, 2020
1 parent 61a4542 commit c75df1c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/lib/utils/loggers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,39 @@ export class Logger {
*/
errorCount = 0;

/**
* How many warning messages have been logged?
*/
warningCount = 0;

/**
* Has an error been raised through the log method?
*/
public hasErrors(): boolean {
return this.errorCount > 0;
}

/**
* Has a warning been raised through the log method?
*/
public hasWarnings(): boolean {
return this.warningCount > 0;
}

/**
* Reset the error counter.
*/
public resetErrors() {
this.errorCount = 0;
}

/**
* Reset the warning counter.
*/
public resetWarnings() {
this.warningCount = 0;
}

/**
* Log the given message.
*
Expand Down Expand Up @@ -109,6 +128,9 @@ export class Logger {
if (level === LogLevel.Error) {
this.errorCount += 1;
}
if (level === LogLevel.Warn) {
this.warningCount += 1;
}
}

/**
Expand Down

0 comments on commit c75df1c

Please sign in to comment.