-
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.
- Loading branch information
1 parent
5b673b3
commit faae8be
Showing
6 changed files
with
270 additions
and
35 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
52 changes: 27 additions & 25 deletions
52
projects/virtual-repeat-angular-lib/src/lib/logger.service.ts
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,34 +1,36 @@ | ||
import { isDevMode } from '@angular/core'; | ||
import { noop } from 'rxjs'; | ||
|
||
export class LoggerService { | ||
log: any; | ||
constructor() { | ||
const forceLog = Boolean(localStorage.getItem('gcvra_force_log')); // force log even in devMode | ||
const filterLog = localStorage.getItem('gcvra_filter_log'); // filter log lines (; separated list) | ||
const bLog = Boolean(localStorage.getItem('gcvra_log')); // enable log | ||
const filterLog = localStorage.getItem('gcvra_log_filter'); // filter log lines (; separated list) | ||
let filterLogTerms: string[]; | ||
if (filterLog) { | ||
filterLogTerms = filterLog.split(';').map(term => term.trim().toLowerCase()).filter(term => !!term); | ||
filterLogTerms = filterLog | ||
.split(';') | ||
.map(term => term.trim().toLowerCase()) | ||
.filter(term => !!term); | ||
} | ||
setTimeout(() => { // hack to be able to use isDevMode() | ||
if (isDevMode() || forceLog) { | ||
if (filterLog) { | ||
this.log = function (text: string, ...args: any[]) { | ||
let done = false; | ||
filterLogTerms.forEach(term => { | ||
if (!done && text.toLowerCase().indexOf(term) !== -1) { | ||
console.log(text, ...args); | ||
done = true; | ||
} | ||
}); | ||
return; | ||
}; | ||
} else { | ||
this.log = function (text: string, ...args: any[]) { | ||
console.log(text, ...args); | ||
}; | ||
} | ||
if (bLog) { | ||
if (filterLog) { | ||
this.log = function(text: string, ...args: any[]) { | ||
let done = false; | ||
filterLogTerms.forEach(term => { | ||
if (!done && text.toLowerCase().indexOf(term) !== -1) { | ||
console.log(text, ...args); | ||
done = true; | ||
} | ||
}); | ||
return; | ||
}; | ||
} else { | ||
this.log = function(text: string, ...args: any[]) { | ||
console.log(text, ...args); | ||
}; | ||
} | ||
}, 100); | ||
} else { | ||
this.log = noop; | ||
} | ||
} | ||
|
||
log(text: string, ...args: any[]) { } | ||
} |
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