@spinajs/log-common 2.0.179 → 2.0.181

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,209 +1,209 @@
1
- import { Container, SyncService } from "@spinajs/di";
2
- export declare enum LogLevel {
3
- Security = 999,
4
- Fatal = 6,
5
- Error = 5,
6
- Warn = 4,
7
- Success = 3,
8
- Info = 2,
9
- Debug = 1,
10
- Trace = 0
11
- }
12
- export declare const StrToLogLevel: {
13
- trace: LogLevel;
14
- debug: LogLevel;
15
- info: LogLevel;
16
- success: LogLevel;
17
- warn: LogLevel;
18
- error: LogLevel;
19
- fatal: LogLevel;
20
- security: LogLevel;
21
- };
22
- export declare const LogLevelStrings: {
23
- 1: string;
24
- 5: string;
25
- 6: string;
26
- 2: string;
27
- 999: string;
28
- 3: string;
29
- 0: string;
30
- 4: string;
31
- };
32
- export interface ILogRule {
33
- name: string;
34
- level: "trace" | "debug" | "info" | "warn" | "error" | "fatal" | "security" | "success";
35
- target: string | string[];
36
- }
37
- export interface ITargetsOption {
38
- name: string;
39
- type: string;
40
- options?: ICommonTargetOptions;
41
- }
42
- export interface ILogOptions {
43
- targets: ITargetsOption[];
44
- rules: ILogRule[];
45
- variables?: Record<string, unknown>;
46
- }
47
- export interface ICommonTargetOptions {
48
- /**
49
- * Message layout. You can use variables
50
- *
51
- * Default message layout is: datetime level message (logger)
52
- */
53
- layout: string;
54
- /**
55
- * Target name
56
- */
57
- name: string;
58
- /**
59
- * Target type
60
- */
61
- type: string;
62
- /**
63
- * Is logger enabled
64
- */
65
- enabled: boolean;
66
- }
67
- export interface IColoredConsoleTargetOptions extends ICommonTargetOptions {
68
- /**
69
- * Color theme for console message. Best leave it for default.
70
- */
71
- theme: {
72
- security: string | string[];
73
- fatal: string | string[];
74
- error: string | string[];
75
- warn: string | string[];
76
- success: string | string[];
77
- info: string | string[];
78
- debug: string | string[];
79
- trace: string | string[];
80
- };
81
- }
82
- export interface IFileTargetOptions extends ICommonTargetOptions {
83
- options: {
84
- /**
85
- * path whre log is stored. It is allowed to use variables to create path eg. date / time etc.
86
- */
87
- path: string;
88
- /**
89
- * Archive path for logs eg. when size is exceeded. Is is allowed to use variables eg. date / time etc.
90
- *
91
- * Default is none. When not set archive files are stored in same folder as logs.
92
- */
93
- archivePath: string;
94
- /**
95
- * Maximum log file size, if exceeded it is moved to archive, and new log file is created
96
- *
97
- * Default is 1mb
98
- */
99
- maxSize: number;
100
- /**
101
- * Should compress log file when moved to archive
102
- *
103
- * Default is false
104
- */
105
- compress: boolean;
106
- /**
107
- * Should rotate log file eg. new file every new day.
108
- * You should use cron like definition eg. at 1am every day: 0 1 * * *
109
- * When rotate event occurs, old file is moved to archive, and new one is created
110
- *
111
- * Default is not set
112
- */
113
- rotate: string;
114
- /**
115
- * Max internal message buffer size before writting to file
116
- * If bigger the number - less writes to disk.
117
- *
118
- * Set it big when logging very frequently to avoid disk writes
119
- * Defaults to 100 messages
120
- */
121
- maxBufferSize: number;
122
- /**
123
- * How mutch archive files should be preserved before deletion. Default is 0
124
- * Eg. to store max 5 archive files, set it to 5. Oldest by modification time are deleted.
125
- */
126
- maxArchiveFiles: number;
127
- /**
128
- * Log archive interval at whitch process should check if log files need archiving, in seconds.
129
- * Default is 3 minutes
130
- */
131
- archiveInterval: number;
132
- };
133
- }
134
- export interface ILogStaticVariables {
135
- error: Error | undefined;
136
- level: string;
137
- logger: string;
138
- message: string;
139
- }
140
- export interface ILogVariable {
141
- [key: string]: unknown | (() => unknown);
142
- }
143
- export interface ILogEntry {
144
- Level: LogLevel;
145
- Variables: LogVariables;
146
- }
147
- export declare abstract class LogTarget<T extends ICommonTargetOptions> extends SyncService {
148
- HasError: boolean;
149
- Error: Error | null | unknown;
150
- Options: T;
151
- constructor(options: T);
152
- abstract write(data: ILogEntry): void;
153
- }
154
- export interface ILogTargetDesc {
155
- instance: LogTarget<ICommonTargetOptions>;
156
- options?: ITargetsOption;
157
- rule: ILogRule;
158
- }
159
- export declare function createLogMessageObject(err: Error | string, message: string | any[], level: LogLevel, logger: string, variables: any, ...args: any[]): ILogEntry;
160
- export declare abstract class Log extends SyncService {
161
- static Loggers: Map<string, Log>;
162
- static InternalLoggers: Map<string, Log>;
163
- Timers: Map<string, Date>;
164
- protected Targets: ILogTargetDesc[];
165
- Name: string;
166
- protected static AttachedToExitEvents: boolean;
167
- protected Options: ILogOptions;
168
- protected Rules: ILogRule[];
169
- protected Container: Container;
170
- protected Variables: Record<string, any>;
171
- static clearLoggers(): Promise<Promise<void>[]>;
172
- addVariable(name: string, value: unknown): void;
173
- timeStart(name: string): void;
174
- timeEnd(name: string): number;
175
- child(name: string, variables?: LogVariables): Log;
176
- abstract trace(message: string, ...args: any[]): void;
177
- abstract trace(err: Error, message: string, ...args: any[]): void;
178
- abstract trace(err: Error | string, message: string | any[], ...args: any[]): void;
179
- abstract debug(message: string, ...args: any[]): void;
180
- abstract debug(err: Error, message: string, ...args: any[]): void;
181
- abstract debug(err: Error | string, message: string | any[], ...args: any[]): void;
182
- abstract info(message: string, ...args: any[]): void;
183
- abstract info(err: Error, message: string, ...args: any[]): void;
184
- abstract info(err: Error | string, message: string | any[], ...args: any[]): void;
185
- abstract warn(message: string, ...args: any[]): void;
186
- abstract warn(err: Error, message: string, ...args: any[]): void;
187
- abstract warn(err: Error | string, message: string | any[], ...args: any[]): void;
188
- abstract error(message: string, ...args: any[]): void;
189
- abstract error(err: Error, message: string, ...args: any[]): void;
190
- abstract error(err: Error | string, message: string | any[], ...args: any[]): void;
191
- abstract fatal(message: string, ...args: any[]): void;
192
- abstract fatal(err: Error, message: string, ...args: any[]): void;
193
- abstract fatal(err: Error | string, message: string | any[], ...args: any[]): void;
194
- abstract security(message: string, ...args: any[]): void;
195
- abstract security(err: Error, message: string, ...args: any[]): void;
196
- abstract security(err: Error | string, message: string | any[], ...args: any[]): void;
197
- abstract success(message: string, ...args: any[]): void;
198
- abstract success(err: Error, message: string, ...args: any[]): void;
199
- abstract success(err: Error | string, message: string | any[], ...args: any[]): void;
200
- abstract write(entry: ILogEntry): Promise<PromiseSettledResult<void>[]>;
201
- }
202
- /**
203
- * Creates ( if not exists ) new logger instance with given name and optional variables
204
- * @param name - name of logger
205
- * @param variables - optional log variables
206
- */
207
- export declare function Logger(name: string, variables?: Record<string, unknown>): (target: any, key: string) => any;
208
- export type LogVariables = ILogStaticVariables & ILogVariable;
1
+ import { Container, SyncService } from "@spinajs/di";
2
+ export declare enum LogLevel {
3
+ Security = 999,
4
+ Fatal = 6,
5
+ Error = 5,
6
+ Warn = 4,
7
+ Success = 3,
8
+ Info = 2,
9
+ Debug = 1,
10
+ Trace = 0
11
+ }
12
+ export declare const StrToLogLevel: {
13
+ trace: LogLevel;
14
+ debug: LogLevel;
15
+ info: LogLevel;
16
+ success: LogLevel;
17
+ warn: LogLevel;
18
+ error: LogLevel;
19
+ fatal: LogLevel;
20
+ security: LogLevel;
21
+ };
22
+ export declare const LogLevelStrings: {
23
+ 1: string;
24
+ 5: string;
25
+ 6: string;
26
+ 2: string;
27
+ 999: string;
28
+ 3: string;
29
+ 0: string;
30
+ 4: string;
31
+ };
32
+ export interface ILogRule {
33
+ name: string;
34
+ level: "trace" | "debug" | "info" | "warn" | "error" | "fatal" | "security" | "success";
35
+ target: string | string[];
36
+ }
37
+ export interface ITargetsOption {
38
+ name: string;
39
+ type: string;
40
+ options?: ICommonTargetOptions;
41
+ }
42
+ export interface ILogOptions {
43
+ targets: ITargetsOption[];
44
+ rules: ILogRule[];
45
+ variables?: Record<string, unknown>;
46
+ }
47
+ export interface ICommonTargetOptions {
48
+ /**
49
+ * Message layout. You can use variables
50
+ *
51
+ * Default message layout is: datetime level message (logger)
52
+ */
53
+ layout: string;
54
+ /**
55
+ * Target name
56
+ */
57
+ name: string;
58
+ /**
59
+ * Target type
60
+ */
61
+ type: string;
62
+ /**
63
+ * Is logger enabled
64
+ */
65
+ enabled: boolean;
66
+ }
67
+ export interface IColoredConsoleTargetOptions extends ICommonTargetOptions {
68
+ /**
69
+ * Color theme for console message. Best leave it for default.
70
+ */
71
+ theme: {
72
+ security: string | string[];
73
+ fatal: string | string[];
74
+ error: string | string[];
75
+ warn: string | string[];
76
+ success: string | string[];
77
+ info: string | string[];
78
+ debug: string | string[];
79
+ trace: string | string[];
80
+ };
81
+ }
82
+ export interface IFileTargetOptions extends ICommonTargetOptions {
83
+ options: {
84
+ /**
85
+ * path whre log is stored. It is allowed to use variables to create path eg. date / time etc.
86
+ */
87
+ path: string;
88
+ /**
89
+ * Archive path for logs eg. when size is exceeded. Is is allowed to use variables eg. date / time etc.
90
+ *
91
+ * Default is none. When not set archive files are stored in same folder as logs.
92
+ */
93
+ archivePath: string;
94
+ /**
95
+ * Maximum log file size, if exceeded it is moved to archive, and new log file is created
96
+ *
97
+ * Default is 1mb
98
+ */
99
+ maxSize: number;
100
+ /**
101
+ * Should compress log file when moved to archive
102
+ *
103
+ * Default is false
104
+ */
105
+ compress: boolean;
106
+ /**
107
+ * Should rotate log file eg. new file every new day.
108
+ * You should use cron like definition eg. at 1am every day: 0 1 * * *
109
+ * When rotate event occurs, old file is moved to archive, and new one is created
110
+ *
111
+ * Default is not set
112
+ */
113
+ rotate: string;
114
+ /**
115
+ * Max internal message buffer size before writting to file
116
+ * If bigger the number - less writes to disk.
117
+ *
118
+ * Set it big when logging very frequently to avoid disk writes
119
+ * Defaults to 100 messages
120
+ */
121
+ maxBufferSize: number;
122
+ /**
123
+ * How mutch archive files should be preserved before deletion. Default is 0
124
+ * Eg. to store max 5 archive files, set it to 5. Oldest by modification time are deleted.
125
+ */
126
+ maxArchiveFiles: number;
127
+ /**
128
+ * Log archive interval at whitch process should check if log files need archiving, in seconds.
129
+ * Default is 3 minutes
130
+ */
131
+ archiveInterval: number;
132
+ };
133
+ }
134
+ export interface ILogStaticVariables {
135
+ error: Error | undefined;
136
+ level: string;
137
+ logger: string;
138
+ message: string;
139
+ }
140
+ export interface ILogVariable {
141
+ [key: string]: unknown | (() => unknown);
142
+ }
143
+ export interface ILogEntry {
144
+ Level: LogLevel;
145
+ Variables: LogVariables;
146
+ }
147
+ export declare abstract class LogTarget<T extends ICommonTargetOptions> extends SyncService {
148
+ HasError: boolean;
149
+ Error: Error | null | unknown;
150
+ Options: T;
151
+ constructor(options: T);
152
+ abstract write(data: ILogEntry): void;
153
+ }
154
+ export interface ILogTargetDesc {
155
+ instance: LogTarget<ICommonTargetOptions>;
156
+ options?: ITargetsOption;
157
+ rule: ILogRule;
158
+ }
159
+ export declare function createLogMessageObject(err: Error | string, message: string | any[], level: LogLevel, logger: string, variables: any, ...args: any[]): ILogEntry;
160
+ export declare abstract class Log extends SyncService {
161
+ static Loggers: Map<string, Log>;
162
+ static InternalLoggers: Map<string, Log>;
163
+ Timers: Map<string, Date>;
164
+ protected Targets: ILogTargetDesc[];
165
+ Name: string;
166
+ protected static AttachedToExitEvents: boolean;
167
+ protected Options: ILogOptions;
168
+ protected Rules: ILogRule[];
169
+ protected Container: Container;
170
+ protected Variables: Record<string, any>;
171
+ static clearLoggers(): Promise<Promise<void>[]>;
172
+ addVariable(name: string, value: unknown): void;
173
+ timeStart(name: string): void;
174
+ timeEnd(name: string): number;
175
+ child(name: string, variables?: LogVariables): Log;
176
+ abstract trace(message: string, ...args: any[]): void;
177
+ abstract trace(err: Error, message: string, ...args: any[]): void;
178
+ abstract trace(err: Error | string, message: string | any[], ...args: any[]): void;
179
+ abstract debug(message: string, ...args: any[]): void;
180
+ abstract debug(err: Error, message: string, ...args: any[]): void;
181
+ abstract debug(err: Error | string, message: string | any[], ...args: any[]): void;
182
+ abstract info(message: string, ...args: any[]): void;
183
+ abstract info(err: Error, message: string, ...args: any[]): void;
184
+ abstract info(err: Error | string, message: string | any[], ...args: any[]): void;
185
+ abstract warn(message: string, ...args: any[]): void;
186
+ abstract warn(err: Error, message: string, ...args: any[]): void;
187
+ abstract warn(err: Error | string, message: string | any[], ...args: any[]): void;
188
+ abstract error(message: string, ...args: any[]): void;
189
+ abstract error(err: Error, message: string, ...args: any[]): void;
190
+ abstract error(err: Error | string, message: string | any[], ...args: any[]): void;
191
+ abstract fatal(message: string, ...args: any[]): void;
192
+ abstract fatal(err: Error, message: string, ...args: any[]): void;
193
+ abstract fatal(err: Error | string, message: string | any[], ...args: any[]): void;
194
+ abstract security(message: string, ...args: any[]): void;
195
+ abstract security(err: Error, message: string, ...args: any[]): void;
196
+ abstract security(err: Error | string, message: string | any[], ...args: any[]): void;
197
+ abstract success(message: string, ...args: any[]): void;
198
+ abstract success(err: Error, message: string, ...args: any[]): void;
199
+ abstract success(err: Error | string, message: string | any[], ...args: any[]): void;
200
+ abstract write(entry: ILogEntry): Promise<PromiseSettledResult<void>[]>;
201
+ }
202
+ /**
203
+ * Creates ( if not exists ) new logger instance with given name and optional variables
204
+ * @param name - name of logger
205
+ * @param variables - optional log variables
206
+ */
207
+ export declare function Logger(name: string, variables?: Record<string, unknown>): (target: any, key: string) => any;
208
+ export type LogVariables = ILogStaticVariables & ILogVariable;
209
209
  //# sourceMappingURL=index.d.ts.map