/
consola.d.ts
159 lines (124 loc) · 4.03 KB
/
consola.d.ts
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import { InspectOptions } from 'util';
export enum LogLevel {
Fatal= 0,
Error= 0,
Warn= 1,
Log= 2,
Info= 3,
Success= 3,
Debug= 4,
Trace= 5,
Silent= Infinity,
}
export interface ConsolaLogObject {
level?: LogLevel,
tag?: string,
type?: string,
message?: string,
additional?: string | string[],
args?: any[],
date?: Date,
}
type ConsolaMock = (...args: any) => void
type ConsolaMockFn = (type: string, defaults: ConsolaLogObject) => ConsolaMock
export interface ConsolaReporterArgs {
async: boolean,
stdout: NodeJS.WritableStream,
stderr: NodeJS.WritableStream,
}
export interface ConsolaReporter {
log: (logObj: ConsolaLogObject, args: ConsolaReporterArgs) => void
}
export interface ConsolaOptions {
reporters?: ConsolaReporter[],
types?: { [type: string]: ConsolaLogObject },
level?: LogLevel,
defaults?: ConsolaLogObject,
async?: boolean,
stdout?: any,
stderr?: any,
mockFn?: ConsolaMockFn,
throttle?: number,
}
export declare class Consola {
constructor(options: ConsolaOptions)
level: LogLevel
readonly stdout: any
readonly stderr: any
// Built-in log levels
fatal(message: ConsolaLogObject | any, ...args: any[]): void
error(message: ConsolaLogObject | any, ...args: any[]): void
warn(message: ConsolaLogObject | any, ...args: any[]): void
log(message: ConsolaLogObject | any, ...args: any[]): void
info(message: ConsolaLogObject | any, ...args: any[]): void
start(message: ConsolaLogObject | any, ...args: any[]): void
success(message: ConsolaLogObject | any, ...args: any[]): void
ready(message: ConsolaLogObject | any, ...args: any[]): void
debug(message: ConsolaLogObject | any, ...args: any[]): void
trace(message: ConsolaLogObject | any, ...args: any[]): void
// Create
create(options: ConsolaOptions): Consola
withDefaults(defaults: ConsolaLogObject): Consola
withTag(tag: string): Consola
withScope(tag: string): Consola
// Reporter
addReporter(reporter: ConsolaReporter): Consola
setReporters(reporters: Array<ConsolaReporter>): Consola
removeReporter(reporter?: ConsolaReporter): Consola
remove(reporter?: ConsolaReporter): Consola
clear(reporter?: ConsolaReporter): Consola
// Wrappers
wrapAll(): void
restoreAll(): void
wrapConsole(): void
restoreConsole(): void
wrapStd(): void
restoreStd(): void
// Pause/Resume
pauseLogs(): void
pause(): void
resumeLogs(): void
resume(): void
// Mock
mockTypes(mockFn: ConsolaMockFn): any
mock(mockFn: ConsolaMockFn): any
}
export interface BasicReporterOptions {
dateFormat?: string;
formatOptions?: InspectOptions;
}
export declare class BasicReporter implements ConsolaReporter {
protected options: BasicReporterOptions;
constructor(options?: BasicReporterOptions);
public log(logObj: ConsolaLogObject, args: ConsolaReporterArgs): void;
protected formatStack(stack: string): string;
protected formatArgs(args: any[]): string;
protected formatDate(date: Date): string;
protected filterAndJoin(arr: Array<string | undefined>): string;
protected formatLogObj(logObj: ConsolaLogObject): string;
}
export interface FancyReporterOptions extends BasicReporterOptions{
secondaryColor?: string;
}
export declare class FancyReporter extends BasicReporter {
constructor(options?: FancyReporterOptions);
protected formatType(logObj: ConsolaLogObject): void;
}
export type BrowserReporterOptions = {};
export declare class BrowserReporter implements ConsolaReporter {
public log(logObj: ConsolaLogObject, args: ConsolaReporterArgs): void;
}
export type JSONReporterOptions = {
stream?: NodeJS.WritableStream;
};
export declare class JSONReporter implements ConsolaReporter {
constructor(options?: JSONReporterOptions);
public log(logObj: ConsolaLogObject, args: ConsolaReporterArgs): void;
}
export type Winston = any;
export declare class WinstonReporter implements ConsolaReporter {
constructor(logger?: Winston);
public log(logObj: ConsolaLogObject, args: ConsolaReporterArgs): void;
}
declare const consolaGlobalInstance: Consola;
export default consolaGlobalInstance