1 | import {GridOptionsWrapper} from "./gridOptionsWrapper";
|
2 | import {Bean} from "./context/context";
|
3 | import {Qualifier} from "./context/context";
|
4 |
|
5 | @Bean('loggerFactory')
|
6 | export class LoggerFactory {
|
7 |
|
8 | private logging: boolean;
|
9 |
|
10 | private setBeans(@Qualifier('gridOptionsWrapper') gridOptionsWrapper: GridOptionsWrapper): void {
|
11 | this.logging = gridOptionsWrapper.isDebug();
|
12 | }
|
13 |
|
14 | public create(name: string) {
|
15 | return new Logger(name, this.isLogging.bind(this));
|
16 | }
|
17 |
|
18 | public isLogging(): boolean {
|
19 | return this.logging;
|
20 | }
|
21 | }
|
22 |
|
23 | export class Logger {
|
24 |
|
25 | private isLoggingFunc: ()=>boolean;
|
26 | private name: string;
|
27 |
|
28 | constructor(name: string, isLoggingFunc: ()=>boolean) {
|
29 | this.name = name;
|
30 | this.isLoggingFunc = isLoggingFunc;
|
31 | }
|
32 |
|
33 | public isLogging(): boolean {
|
34 | return this.isLoggingFunc();
|
35 | }
|
36 |
|
37 | public log(message: string) {
|
38 | if (this.isLoggingFunc()) {
|
39 | console.log('ag-Grid.' + this.name + ': ' + message);
|
40 | }
|
41 | }
|
42 |
|
43 | }
|