forked from kubernetes-sigs/release-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kubernetes-sigs#17 from openSUSE/logger-service
Add shared logger service
- Loading branch information
Showing
6 changed files
with
75 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { environment } from '@environment'; | ||
|
||
/** | ||
* The logger service implementation | ||
*/ | ||
@Injectable() | ||
export class LoggerService { | ||
/** | ||
* Gets the current time as prefix | ||
* | ||
* @returns The time prefix. | ||
*/ | ||
private date(): string { | ||
const date = new Date(); | ||
return date.toLocaleString(); | ||
} | ||
|
||
/** | ||
* Logs a debug message to the console when log level >= 3 | ||
* | ||
* @param msg The log message | ||
*/ | ||
public debug(msg: string) { | ||
if (environment.logLevel >= 3) { | ||
console.log(`[DEBUG]\t${this.date()}: ${msg}`); | ||
} | ||
} | ||
|
||
/** | ||
* Logs an info message to the console when log level >= 2 | ||
* | ||
* @param msg The info log message | ||
*/ | ||
public info(msg: string) { | ||
if (environment.logLevel >= 2) { | ||
console.log(`[INFO]\t${this.date()}: ${msg}`); | ||
} | ||
} | ||
|
||
/** | ||
* Logs a warning to the console when log level >= 1 | ||
* | ||
* @param msg The warning log message | ||
*/ | ||
public warn(msg: string) { | ||
if (environment.logLevel >= 1) { | ||
console.log(`[WARN]\t${this.date()}: ${msg}`); | ||
} | ||
} | ||
|
||
/** | ||
* Always logs an error message to the console | ||
* | ||
* @param msg The error log message | ||
*/ | ||
public error(msg: string) { | ||
console.log(`[ERROR]\t${this.date()}: ${msg}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export const environment = { | ||
production: true, | ||
logLevel: 0 // 0 - 3 verbosity | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
export const environment = { | ||
production: false, | ||
logLevel: 3 // 0 - 3 verbosity | ||
}; | ||
|
||
/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters