blob: 422fe0134a9cb15f0c83478a4145d1493d26ff3c (
plain)
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
|
import {isDevMode} from "@angular/core";
declare var console: any;
export interface ILogger {
assert(...args: any[]): void;
error(...args: any[]): void;
group(...args: any[]): void;
groupEnd(...args: any[]): void;
info(...args: any[]): void;
log(...args: any[]): void;
warn(...args: any[]): void;
}
export class LogService implements ILogger {
isProduction : boolean = !isDevMode();
public assert(...args: any[]): void {
console.assert(LogService.getPrefixLog(...args));
}
public error(...args: any[]): void {
console.error(LogService.getPrefixLog(...args));
}
public group(...args: any[]): void {
console.group(LogService.getPrefixLog(...args));
}
public groupEnd(...args: any[]): void {
console.groupEnd(LogService.getPrefixLog(...args));
}
public info(...args: any[]): void {
console.info(LogService.getPrefixLog(...args));
}
public log(...args: any[]): void {
if(!this.isProduction){
console.log(LogService.getPrefixLog(...args));
}
}
public warn(...args: any[]): void {
console.warn(LogService.getPrefixLog(...args));
}
static getPrefixLog(...args :any[]){
return {
time : new Date(),
message : args[0],
data : args.length > 0 ? args[1] : ''
};
}
}
|