forked from winstonjs/logform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
161 lines (143 loc) · 4.47 KB
/
index.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
159
160
161
// Type definitions for logform 1.2
// Project: https://github.com/winstonjs/logform
// Definitions by: DABH <https://github.com/DABH>
// Definitions: https://github.com/winstonjs/logform
// TypeScript Version: 2.2
export interface TransformableInfo {
level: string;
message: string;
[key: string]: any;
}
export type TransformFunction = (info: TransformableInfo, opts?: any) => TransformableInfo | boolean;
export type Colors = { [key: string]: string | string[] }; // tslint:disable-line interface-over-type-literal
export type FormatWrap = (opts?: any) => Format;
export class Format {
constructor(opts?: object);
options?: object;
transform: TransformFunction;
}
export class Colorizer extends Format {
constructor(opts?: object);
createColorize: (opts?: object) => Colorizer;
addColors: (colors: Colors) => Colors;
colorize: (level: string, message: string) => string;
}
export function format(transform: TransformFunction): FormatWrap;
export function levels(config: object): object;
export namespace format {
function align(): Format;
function cli(opts?: CliOptions): Format;
function colorize(opts?: ColorizeOptions): Colorizer;
function combine(...formats: Format[]): Format;
function errors(opts?: object): Format;
function json(opts?: JsonOptions): Format;
function label(opts?: LabelOptions): Format;
function logstash(): Format;
function metadata(opts?: MetadataOptions): Format;
function ms(): Format;
function padLevels(opts?: PadLevelsOptions): Format;
function prettyPrint(opts?: PrettyPrintOptions): Format;
function printf(templateFunction: (info: TransformableInfo) => string): Format;
function simple(): Format;
function splat(): Format;
function timestamp(opts?: TimestampOptions): Format;
function uncolorize(opts?: UncolorizeOptions): Format;
}
export interface CliOptions extends ColorizeOptions, PadLevelsOptions {}
export interface ColorizeOptions {
/**
* If set to `true` the color will be applied to the `level`.
*/
level?: boolean;
/**
* If set to `true` the color will be applied to the `message` and `level`.
*/
all?: boolean;
/**
* If set to `true` the color will be applied to the `message`.
*/
message?: boolean;
/**
* An object containing the colors for the log levels. For example: `{ info: 'blue', error: 'red' }`.
*/
colors?: Record<string, string>;
}
export interface JsonOptions {
/**
* A function that influences how the `info` is stringified.
*/
replacer?: (this: any, key: string, value: any) => any;
/**
* The number of white space used to format the json.
*/
space?: number;
}
export interface LabelOptions {
/**
* A label to be added before the message.
*/
label?: string;
/**
* If set to `true` the `label` will be added to `info.message`. If set to `false` the `label`
* will be added as `info.label`.
*/
message?: boolean;
}
export interface MetadataOptions {
/**
* The name of the key used for the metadata object. Defaults to `metadata`.
*/
key?: string;
/**
* An array of keys that should not be added to the metadata object.
*/
fillExcept?: string[];
/**
* An array of keys that will be added to the metadata object.
*/
fillWith?: string[];
}
export interface PadLevelsOptions {
/**
* Log levels. Defaults to `configs.npm.levels` from [triple-beam](https://github.com/winstonjs/triple-beam)
* module.
*/
levels?: Record<string, number>;
}
export interface PrettyPrintOptions {
/**
* A `number` that specifies the maximum depth of the `info` object being stringified by
* `util.inspect`. Defaults to `2`.
*/
depth?: number;
/**
* Colorizes the message if set to `true`. Defaults to `false`.
*/
colorize?: boolean;
}
export interface TimestampOptions {
/**
* Either the format as a string accepted by the [fecha](https://github.com/taylorhakes/fecha)
* module or a function that returns a formatted date. If no format is provided `new
* Date().toISOString()` will be used.
*/
format?: string | (() => string);
/**
* The name of an alias for the timestamp property, that will be added to the `info` object.
*/
alias?: string;
}
export interface UncolorizeOptions {
/**
* Disables the uncolorize format for `info.level` if set to `false`.
*/
level?: boolean;
/**
* Disables the uncolorize format for `info.message` if set to `false`.
*/
message?: boolean;
/**
* Disables the uncolorize format for `info[MESSAGE]` if set to `false`.
*/
raw?: boolean;
}