forked from javascript-obfuscator/javascript-obfuscator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogger.ts
More file actions
99 lines (82 loc) · 2.58 KB
/
Copy pathLogger.ts
File metadata and controls
99 lines (82 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { inject, injectable, postConstruct } from 'inversify';
import { ServiceIdentifiers } from '../container/ServiceIdentifiers';
import chalk, { Chalk } from 'chalk';
import { IInitializable } from '../interfaces/IInitializable';
import { ILogger } from '../interfaces/logger/ILogger';
import { IOptions } from '../interfaces/options/IOptions';
import { LoggingMessage } from '../enums/logger/LoggingMessage';
import { initializable } from '../decorators/Initializable';
@injectable()
export class Logger implements ILogger, IInitializable {
/**
* @type {string}
*/
private static readonly loggingPrefix: string = '[javascript-obfuscator]';
/**
* @type {Chalk}
*/
@initializable()
private colorInfo: Chalk;
/**
* @type {Chalk}
*/
@initializable()
private colorSuccess: Chalk;
/**
* @type {Chalk}
*/
@initializable()
private colorWarn: Chalk;
/**
* @type {IOptions}
*/
private readonly options: IOptions;
/**
* @param {IOptions} options
*/
constructor (
@inject(ServiceIdentifiers.IOptions) options: IOptions
) {
this.options = options;
}
@postConstruct()
public initialize (): void {
this.colorInfo = chalk.cyan;
this.colorSuccess = chalk.green;
this.colorWarn = chalk.yellow;
}
/**
* @param {LoggingMessage} loggingMessage
* @param {string | number} value
*/
public info (loggingMessage: LoggingMessage, value?: string | number): void {
this.log(this.colorInfo, loggingMessage, value);
}
/**
* @param {LoggingMessage} loggingMessage
* @param {string | number} value
*/
public success (loggingMessage: LoggingMessage, value?: string | number): void {
this.log(this.colorSuccess, loggingMessage, value);
}
/**
* @param {LoggingMessage} loggingMessage
* @param {string | number} value
*/
public warn (loggingMessage: LoggingMessage, value?: string | number): void {
this.log(this.colorWarn, loggingMessage, value);
}
/**
*
* @param {Chalk} loggingLevelColor
* @param {LoggingMessage} loggingMessage
* @param {string | number} value
*/
private log (loggingLevelColor: Chalk, loggingMessage: LoggingMessage, value?: string | number): void {
if (!this.options.log) {
return;
}
const processedMessage: string = loggingLevelColor(`\n${Logger.loggingPrefix} ${loggingMessage}`);
!value ? console.log(processedMessage) : console.log(processedMessage, value);
}
}