ionic-logging-service 16.0.0 → 18.0.0
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.
- package/README.md +3 -1
- package/esm2022/lib/ajax-appender.model.mjs +149 -0
- package/esm2022/lib/local-storage-appender.model.mjs +177 -0
- package/esm2022/lib/log-level.converter.mjs +92 -0
- package/esm2022/lib/logger.model.mjs +191 -0
- package/{esm2020 → esm2022}/lib/logging-service.module.mjs +5 -5
- package/esm2022/lib/logging.service.mjs +167 -0
- package/esm2022/lib/memory-appender.model.mjs +133 -0
- package/{fesm2015 → fesm2022}/ionic-logging-service.mjs +15 -15
- package/{fesm2020 → fesm2022}/ionic-logging-service.mjs.map +1 -1
- package/package.json +7 -13
- package/esm2020/lib/ajax-appender.model.mjs +0 -149
- package/esm2020/lib/local-storage-appender.model.mjs +0 -177
- package/esm2020/lib/log-level.converter.mjs +0 -92
- package/esm2020/lib/logger.model.mjs +0 -191
- package/esm2020/lib/logging.service.mjs +0 -167
- package/esm2020/lib/memory-appender.model.mjs +0 -133
- package/fesm2015/ionic-logging-service.mjs.map +0 -1
- package/fesm2020/ionic-logging-service.mjs +0 -992
- /package/{esm2020 → esm2022}/ionic-logging-service.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/ajax-appender.configuration.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/browser-console-appender.configuration.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/json-layout.model.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/local-storage-appender.configuration.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/log-level.model.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/log-message.model.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/logging-service.configuration.mjs +0 -0
- /package/{esm2020 → esm2022}/lib/memory-appender.configuration.mjs +0 -0
- /package/{esm2020 → esm2022}/public_api.mjs +0 -0
|
@@ -1,992 +0,0 @@
|
|
|
1
|
-
import * as i0 from '@angular/core';
|
|
2
|
-
import { EventEmitter, Injectable, NgModule } from '@angular/core';
|
|
3
|
-
import * as log4javascript from 'log4javascript';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Formats a logging event into JavaScript Object Notation (JSON).
|
|
7
|
-
* The implemenatation is mainly the same as with log4javascript.JsonLayout,
|
|
8
|
-
* with an improvement of serializing messages containing '\"'."
|
|
9
|
-
*/
|
|
10
|
-
class JsonLayout extends log4javascript.JsonLayout {
|
|
11
|
-
/**
|
|
12
|
-
* Formats the log message.
|
|
13
|
-
*/
|
|
14
|
-
format(loggingEvent) {
|
|
15
|
-
const eventObj = {
|
|
16
|
-
logger: loggingEvent.logger.name,
|
|
17
|
-
timestamp: loggingEvent.timeStampInMilliseconds,
|
|
18
|
-
level: loggingEvent.level.toString(),
|
|
19
|
-
url: window.location.href,
|
|
20
|
-
message: this.isCombinedMessages() ? loggingEvent.getCombinedMessages() : loggingEvent.messages
|
|
21
|
-
};
|
|
22
|
-
return JSON.stringify(eventObj);
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Gets the layout's name.
|
|
26
|
-
* Mainly for unit testing purposes.
|
|
27
|
-
*
|
|
28
|
-
* @return layout's name
|
|
29
|
-
*/
|
|
30
|
-
toString() {
|
|
31
|
-
return "Ionic.Logging.JsonLayout";
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Logging levels.
|
|
37
|
-
*/
|
|
38
|
-
var LogLevel;
|
|
39
|
-
(function (LogLevel) {
|
|
40
|
-
/**
|
|
41
|
-
* All events should be logged.
|
|
42
|
-
*/
|
|
43
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
44
|
-
LogLevel[LogLevel["ALL"] = 0] = "ALL";
|
|
45
|
-
/**
|
|
46
|
-
* A fine-grained debug message, typically capturing the flow through the application.
|
|
47
|
-
*/
|
|
48
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
49
|
-
LogLevel[LogLevel["TRACE"] = 1] = "TRACE";
|
|
50
|
-
/**
|
|
51
|
-
* A general debugging event.
|
|
52
|
-
*/
|
|
53
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
54
|
-
LogLevel[LogLevel["DEBUG"] = 2] = "DEBUG";
|
|
55
|
-
/**
|
|
56
|
-
* An event for informational purposes.
|
|
57
|
-
*/
|
|
58
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
59
|
-
LogLevel[LogLevel["INFO"] = 3] = "INFO";
|
|
60
|
-
/**
|
|
61
|
-
* An event that might possible lead to an error.
|
|
62
|
-
*/
|
|
63
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
64
|
-
LogLevel[LogLevel["WARN"] = 4] = "WARN";
|
|
65
|
-
/**
|
|
66
|
-
* An error in the application, possibly recoverable.
|
|
67
|
-
*/
|
|
68
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
69
|
-
LogLevel[LogLevel["ERROR"] = 5] = "ERROR";
|
|
70
|
-
/**
|
|
71
|
-
* A severe error that will prevent the application from continuing.
|
|
72
|
-
*/
|
|
73
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
74
|
-
LogLevel[LogLevel["FATAL"] = 6] = "FATAL";
|
|
75
|
-
/**
|
|
76
|
-
* No events will be logged.
|
|
77
|
-
*/
|
|
78
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
79
|
-
LogLevel[LogLevel["OFF"] = 7] = "OFF";
|
|
80
|
-
})(LogLevel || (LogLevel = {}));
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Helper class for converting log levels from and to different data type.
|
|
84
|
-
*/
|
|
85
|
-
class LogLevelConverter {
|
|
86
|
-
/**
|
|
87
|
-
* Converts log4javascript.Level to internal LogLevel.
|
|
88
|
-
*
|
|
89
|
-
* @param level log4javascript's data type
|
|
90
|
-
* @return internal data type.
|
|
91
|
-
*/
|
|
92
|
-
static levelFromLog4Javascript(level) {
|
|
93
|
-
switch (level) {
|
|
94
|
-
case log4javascript.Level.ALL:
|
|
95
|
-
return LogLevel.ALL;
|
|
96
|
-
case log4javascript.Level.DEBUG:
|
|
97
|
-
return LogLevel.DEBUG;
|
|
98
|
-
case log4javascript.Level.ERROR:
|
|
99
|
-
return LogLevel.ERROR;
|
|
100
|
-
case log4javascript.Level.FATAL:
|
|
101
|
-
return LogLevel.FATAL;
|
|
102
|
-
case log4javascript.Level.INFO:
|
|
103
|
-
return LogLevel.INFO;
|
|
104
|
-
case log4javascript.Level.OFF:
|
|
105
|
-
return LogLevel.OFF;
|
|
106
|
-
case log4javascript.Level.TRACE:
|
|
107
|
-
return LogLevel.TRACE;
|
|
108
|
-
case log4javascript.Level.WARN:
|
|
109
|
-
return LogLevel.WARN;
|
|
110
|
-
default:
|
|
111
|
-
throw new Error(`invalid level ${level}`);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Converts string representation to internal LogLevel.
|
|
116
|
-
*
|
|
117
|
-
* @param level string representation
|
|
118
|
-
* @return internal data type.
|
|
119
|
-
*/
|
|
120
|
-
static levelFromString(level) {
|
|
121
|
-
switch (level) {
|
|
122
|
-
case "ALL":
|
|
123
|
-
return LogLevel.ALL;
|
|
124
|
-
case "DEBUG":
|
|
125
|
-
return LogLevel.DEBUG;
|
|
126
|
-
case "ERROR":
|
|
127
|
-
return LogLevel.ERROR;
|
|
128
|
-
case "FATAL":
|
|
129
|
-
return LogLevel.FATAL;
|
|
130
|
-
case "INFO":
|
|
131
|
-
return LogLevel.INFO;
|
|
132
|
-
case "OFF":
|
|
133
|
-
return LogLevel.OFF;
|
|
134
|
-
case "TRACE":
|
|
135
|
-
return LogLevel.TRACE;
|
|
136
|
-
case "WARN":
|
|
137
|
-
return LogLevel.WARN;
|
|
138
|
-
default:
|
|
139
|
-
throw new Error(`invalid level ${level}`);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Converts internal LogLevel to log4javascript.Level.
|
|
144
|
-
*
|
|
145
|
-
* @param internal data type.
|
|
146
|
-
* @return level log4javascript's data type
|
|
147
|
-
*/
|
|
148
|
-
static levelToLog4Javascript(level) {
|
|
149
|
-
switch (level) {
|
|
150
|
-
case LogLevel.ALL:
|
|
151
|
-
return log4javascript.Level.ALL;
|
|
152
|
-
case LogLevel.DEBUG:
|
|
153
|
-
return log4javascript.Level.DEBUG;
|
|
154
|
-
case LogLevel.ERROR:
|
|
155
|
-
return log4javascript.Level.ERROR;
|
|
156
|
-
case LogLevel.FATAL:
|
|
157
|
-
return log4javascript.Level.FATAL;
|
|
158
|
-
case LogLevel.INFO:
|
|
159
|
-
return log4javascript.Level.INFO;
|
|
160
|
-
case LogLevel.OFF:
|
|
161
|
-
return log4javascript.Level.OFF;
|
|
162
|
-
case LogLevel.TRACE:
|
|
163
|
-
return log4javascript.Level.TRACE;
|
|
164
|
-
case LogLevel.WARN:
|
|
165
|
-
return log4javascript.Level.WARN;
|
|
166
|
-
default:
|
|
167
|
-
throw new Error(`invalid level ${level}`);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* An appender which sends the log messages to a server via HTTP.
|
|
174
|
-
*
|
|
175
|
-
* A typical configuration could be:
|
|
176
|
-
*
|
|
177
|
-
* ```json
|
|
178
|
-
* {
|
|
179
|
-
* "url": "https://my.backend.xy/LoggingBackend",
|
|
180
|
-
* "batchSize": 10,
|
|
181
|
-
* "timerInterval": 60000,
|
|
182
|
-
* "threshold": "INFO"
|
|
183
|
-
* }
|
|
184
|
-
* ```
|
|
185
|
-
*/
|
|
186
|
-
class AjaxAppender extends log4javascript.Appender {
|
|
187
|
-
/**
|
|
188
|
-
* Creates a new instance of the appender.
|
|
189
|
-
*
|
|
190
|
-
* @param configuration configuration for the appender.
|
|
191
|
-
*/
|
|
192
|
-
constructor(configuration) {
|
|
193
|
-
super();
|
|
194
|
-
if (!configuration) {
|
|
195
|
-
throw new Error("configuration must be not empty");
|
|
196
|
-
}
|
|
197
|
-
if (!configuration.url) {
|
|
198
|
-
throw new Error("url must be not empty");
|
|
199
|
-
}
|
|
200
|
-
this.ajaxAppender = new log4javascript.AjaxAppender(configuration.url, configuration.withCredentials);
|
|
201
|
-
this.url = configuration.url;
|
|
202
|
-
this.withCredentials = configuration.withCredentials;
|
|
203
|
-
this.ajaxAppender.setLayout(new JsonLayout(false, false));
|
|
204
|
-
this.ajaxAppender.addHeader("Content-Type", "application/json; charset=utf-8");
|
|
205
|
-
this.ajaxAppender.setSendAllOnUnload(true);
|
|
206
|
-
this.appenderFailed = new EventEmitter();
|
|
207
|
-
this.ajaxAppender.setFailCallback((message) => {
|
|
208
|
-
this.appenderFailed.emit(message);
|
|
209
|
-
});
|
|
210
|
-
// process remaining configuration
|
|
211
|
-
this.configure({
|
|
212
|
-
batchSize: configuration.batchSize || AjaxAppender.batchSizeDefault,
|
|
213
|
-
threshold: configuration.threshold || AjaxAppender.thresholdDefault,
|
|
214
|
-
timerInterval: configuration.timerInterval || AjaxAppender.timerIntervalDefault,
|
|
215
|
-
url: configuration.url,
|
|
216
|
-
withCredentials: configuration.withCredentials
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Configures the logging depending on the given configuration.
|
|
221
|
-
*
|
|
222
|
-
* Only the defined properties get overwritten.
|
|
223
|
-
* Neither url nor withCredentials can be modified.
|
|
224
|
-
*
|
|
225
|
-
* @param configuration configuration data.
|
|
226
|
-
*/
|
|
227
|
-
configure(configuration) {
|
|
228
|
-
if (configuration) {
|
|
229
|
-
if (configuration.url && configuration.url !== this.url) {
|
|
230
|
-
throw new Error("url must not be changed");
|
|
231
|
-
}
|
|
232
|
-
if (configuration.withCredentials && configuration.withCredentials !== this.withCredentials) {
|
|
233
|
-
throw new Error("withCredentials must not be changed");
|
|
234
|
-
}
|
|
235
|
-
if (configuration.batchSize) {
|
|
236
|
-
this.setBatchSize(configuration.batchSize);
|
|
237
|
-
}
|
|
238
|
-
if (typeof configuration.timerInterval === "number") {
|
|
239
|
-
this.setTimerInterval(configuration.timerInterval);
|
|
240
|
-
}
|
|
241
|
-
if (configuration.threshold) {
|
|
242
|
-
const convertedThreshold = LogLevelConverter.levelToLog4Javascript(LogLevelConverter.levelFromString(configuration.threshold));
|
|
243
|
-
this.setThreshold(convertedThreshold);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Appender-specific method to append a log message.
|
|
249
|
-
*
|
|
250
|
-
* @param loggingEvent event to be appended.
|
|
251
|
-
*/
|
|
252
|
-
append(loggingEvent) {
|
|
253
|
-
this.ajaxAppender.append(loggingEvent);
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Gets the appender's name.
|
|
257
|
-
* Mainly for unit testing purposes.
|
|
258
|
-
*
|
|
259
|
-
* @return appender's name
|
|
260
|
-
*/
|
|
261
|
-
toString() {
|
|
262
|
-
return "Ionic.Logging.AjaxAppender";
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* Get the internally used appender.
|
|
266
|
-
* Mainly for unit testing purposes.
|
|
267
|
-
*/
|
|
268
|
-
getInternalAppender() {
|
|
269
|
-
return this.ajaxAppender;
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* Returns the number of log messages sent in each request.
|
|
273
|
-
*/
|
|
274
|
-
getBatchSize() {
|
|
275
|
-
return this.ajaxAppender.getBatchSize();
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* Sets the number of log messages to send in each request.
|
|
279
|
-
*
|
|
280
|
-
* @param batchSize new batch size
|
|
281
|
-
*/
|
|
282
|
-
setBatchSize(batchSize) {
|
|
283
|
-
this.ajaxAppender.setBatchSize(batchSize);
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
* Returns the appender's layout.
|
|
287
|
-
*/
|
|
288
|
-
getLayout() {
|
|
289
|
-
return this.ajaxAppender.getLayout();
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Sets the appender's layout.
|
|
293
|
-
*/
|
|
294
|
-
setLayout(layout) {
|
|
295
|
-
this.ajaxAppender.setLayout(layout);
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Returns the length of time in milliseconds between each sending of queued log messages.
|
|
299
|
-
*/
|
|
300
|
-
getTimerInterval() {
|
|
301
|
-
return this.ajaxAppender.getTimerInterval();
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* Sets the length of time in milliseconds between each sending of queued log messages.
|
|
305
|
-
*
|
|
306
|
-
* @param timerInterval new timer interval
|
|
307
|
-
*/
|
|
308
|
-
setTimerInterval(timerInterval) {
|
|
309
|
-
this.ajaxAppender.setTimed(timerInterval > 0);
|
|
310
|
-
this.ajaxAppender.setTimerInterval(timerInterval);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
AjaxAppender.batchSizeDefault = 1;
|
|
314
|
-
AjaxAppender.timerIntervalDefault = 0;
|
|
315
|
-
AjaxAppender.thresholdDefault = "WARN";
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* An appender which stores the log messages in the browser's local storage.
|
|
319
|
-
*
|
|
320
|
-
* The messages are saved JSON-serialized.
|
|
321
|
-
* You have to configure which key is used for storing the messages.
|
|
322
|
-
*
|
|
323
|
-
* A typical configuration could be:
|
|
324
|
-
*
|
|
325
|
-
* ```json
|
|
326
|
-
* {
|
|
327
|
-
* "localStorageKey": "myLogs",
|
|
328
|
-
* "maxMessages": 500,
|
|
329
|
-
* "threshold": "INFO"
|
|
330
|
-
* }
|
|
331
|
-
* ```
|
|
332
|
-
*/
|
|
333
|
-
class LocalStorageAppender extends log4javascript.Appender {
|
|
334
|
-
/**
|
|
335
|
-
* Creates a new instance of the appender.
|
|
336
|
-
*
|
|
337
|
-
* @param configuration configuration for the appender.
|
|
338
|
-
*/
|
|
339
|
-
constructor(configuration) {
|
|
340
|
-
super();
|
|
341
|
-
if (!configuration) {
|
|
342
|
-
throw new Error("configuration must be not empty");
|
|
343
|
-
}
|
|
344
|
-
if (!configuration.localStorageKey || configuration.localStorageKey === "") {
|
|
345
|
-
throw new Error("localStorageKey must be not empty");
|
|
346
|
-
}
|
|
347
|
-
this.localStorageKey = configuration.localStorageKey;
|
|
348
|
-
// read existing logMessages
|
|
349
|
-
this.logMessages = LocalStorageAppender.loadLogMessages(this.localStorageKey);
|
|
350
|
-
// process remaining configuration
|
|
351
|
-
this.configure({
|
|
352
|
-
localStorageKey: configuration.localStorageKey,
|
|
353
|
-
maxMessages: configuration.maxMessages || LocalStorageAppender.maxMessagesDefault,
|
|
354
|
-
threshold: configuration.threshold || LocalStorageAppender.thresholdDefault,
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
/**
|
|
358
|
-
* Load log messages from local storage which are stored there under the given key.
|
|
359
|
-
*
|
|
360
|
-
* @param localStorageKey local storage key
|
|
361
|
-
* @return stored messages
|
|
362
|
-
*/
|
|
363
|
-
static loadLogMessages(localStorageKey) {
|
|
364
|
-
let logMessages;
|
|
365
|
-
if (!localStorageKey || localStorage.getItem(localStorageKey) === null) {
|
|
366
|
-
logMessages = [];
|
|
367
|
-
}
|
|
368
|
-
else {
|
|
369
|
-
logMessages = JSON.parse(localStorage.getItem(localStorageKey));
|
|
370
|
-
for (const logMessage of logMessages) {
|
|
371
|
-
// timestamps are serialized as strings
|
|
372
|
-
logMessage.timeStamp = new Date(logMessage.timeStamp);
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
return logMessages;
|
|
376
|
-
}
|
|
377
|
-
/**
|
|
378
|
-
* Remove log messages from local storage which are stored there under the given key.
|
|
379
|
-
*
|
|
380
|
-
* @param localStorageKey local storage key
|
|
381
|
-
*/
|
|
382
|
-
static removeLogMessages(localStorageKey) {
|
|
383
|
-
localStorage.removeItem(localStorageKey);
|
|
384
|
-
}
|
|
385
|
-
/**
|
|
386
|
-
* Configures the logging depending on the given configuration.
|
|
387
|
-
*
|
|
388
|
-
* Only the defined properties get overwritten.
|
|
389
|
-
* The localStorageKey cannot be modified.
|
|
390
|
-
*
|
|
391
|
-
* @param configuration configuration data.
|
|
392
|
-
*/
|
|
393
|
-
configure(configuration) {
|
|
394
|
-
if (configuration) {
|
|
395
|
-
if (configuration.localStorageKey && configuration.localStorageKey !== this.localStorageKey) {
|
|
396
|
-
throw new Error("localStorageKey must not be changed");
|
|
397
|
-
}
|
|
398
|
-
if (configuration.maxMessages) {
|
|
399
|
-
this.setMaxMessages(configuration.maxMessages);
|
|
400
|
-
}
|
|
401
|
-
if (configuration.threshold) {
|
|
402
|
-
const convertedThreshold = LogLevelConverter.levelToLog4Javascript(LogLevelConverter.levelFromString(configuration.threshold));
|
|
403
|
-
this.setThreshold(convertedThreshold);
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
/**
|
|
408
|
-
* Appender-specific method to append a log message.
|
|
409
|
-
*
|
|
410
|
-
* @param loggingEvent event to be appended.
|
|
411
|
-
*/
|
|
412
|
-
append(loggingEvent) {
|
|
413
|
-
// if logMessages is already full, remove oldest element
|
|
414
|
-
while (this.logMessages.length >= this.maxMessages) {
|
|
415
|
-
this.logMessages.shift();
|
|
416
|
-
}
|
|
417
|
-
// add event to logMessages
|
|
418
|
-
const message = {
|
|
419
|
-
level: LogLevel[LogLevelConverter.levelFromLog4Javascript(loggingEvent.level)],
|
|
420
|
-
logger: typeof loggingEvent.logger !== "undefined" ? loggingEvent.logger.name : undefined,
|
|
421
|
-
message: loggingEvent.messages.slice(1),
|
|
422
|
-
methodName: loggingEvent.messages[0],
|
|
423
|
-
timeStamp: loggingEvent.timeStamp,
|
|
424
|
-
};
|
|
425
|
-
this.logMessages.push(message);
|
|
426
|
-
// write values to localStorage
|
|
427
|
-
localStorage.setItem(this.localStorageKey, JSON.stringify(this.logMessages));
|
|
428
|
-
}
|
|
429
|
-
/**
|
|
430
|
-
* Gets the appender's name.
|
|
431
|
-
* Mainly for unit testing purposes.
|
|
432
|
-
*
|
|
433
|
-
* @return appender's name
|
|
434
|
-
*/
|
|
435
|
-
toString() {
|
|
436
|
-
return "Ionic.Logging.LocalStorageAppender";
|
|
437
|
-
}
|
|
438
|
-
/**
|
|
439
|
-
* Get the key which is used to store the messages in the local storage.
|
|
440
|
-
*/
|
|
441
|
-
getLocalStorageKey() {
|
|
442
|
-
return this.localStorageKey;
|
|
443
|
-
}
|
|
444
|
-
/**
|
|
445
|
-
* Get the maximum number of messages which will be stored in local storage.
|
|
446
|
-
*/
|
|
447
|
-
getMaxMessages() {
|
|
448
|
-
return this.maxMessages;
|
|
449
|
-
}
|
|
450
|
-
/**
|
|
451
|
-
* Set the maximum number of messages which will be stored in local storage.
|
|
452
|
-
*
|
|
453
|
-
* If the appender stores currently more messages than the new value allows, the oldest messages get removed.
|
|
454
|
-
*
|
|
455
|
-
* @param value new maximum number
|
|
456
|
-
*/
|
|
457
|
-
setMaxMessages(value) {
|
|
458
|
-
if (this.maxMessages !== value) {
|
|
459
|
-
this.maxMessages = value;
|
|
460
|
-
if (this.logMessages.length > this.maxMessages) {
|
|
461
|
-
// there are too much logMessages for the new value, therefore remove oldest messages
|
|
462
|
-
while (this.logMessages.length > this.maxMessages) {
|
|
463
|
-
this.logMessages.shift();
|
|
464
|
-
}
|
|
465
|
-
// write values to localStorage
|
|
466
|
-
localStorage.setItem(this.localStorageKey, JSON.stringify(this.logMessages));
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
/**
|
|
471
|
-
* Gets all messages stored in local storage.
|
|
472
|
-
* Mainly for unit testing purposes.
|
|
473
|
-
*
|
|
474
|
-
* @return stored messages
|
|
475
|
-
*/
|
|
476
|
-
getLogMessages() {
|
|
477
|
-
return this.logMessages;
|
|
478
|
-
}
|
|
479
|
-
/**
|
|
480
|
-
* Removes all messages from local storage.
|
|
481
|
-
* Mainly for unit testing purposes.
|
|
482
|
-
*/
|
|
483
|
-
clearLog() {
|
|
484
|
-
this.logMessages = [];
|
|
485
|
-
localStorage.removeItem(this.localStorageKey);
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
LocalStorageAppender.maxMessagesDefault = 250;
|
|
489
|
-
LocalStorageAppender.thresholdDefault = "WARN";
|
|
490
|
-
|
|
491
|
-
/**
|
|
492
|
-
* Logger for writing log messages.
|
|
493
|
-
*/
|
|
494
|
-
class Logger {
|
|
495
|
-
/**
|
|
496
|
-
* Creates a new instance of a logger.
|
|
497
|
-
*/
|
|
498
|
-
constructor(logger) {
|
|
499
|
-
if (typeof logger === "undefined") {
|
|
500
|
-
this.logger = log4javascript.getRootLogger();
|
|
501
|
-
}
|
|
502
|
-
else if (typeof logger === "string") {
|
|
503
|
-
this.logger = log4javascript.getLogger(logger);
|
|
504
|
-
}
|
|
505
|
-
else {
|
|
506
|
-
this.logger = logger;
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
/**
|
|
510
|
-
* Get the log level.
|
|
511
|
-
*/
|
|
512
|
-
getLogLevel() {
|
|
513
|
-
return LogLevelConverter.levelFromLog4Javascript(this.logger.getLevel());
|
|
514
|
-
}
|
|
515
|
-
/**
|
|
516
|
-
* Set the log level.
|
|
517
|
-
*
|
|
518
|
-
* @param level the new log level
|
|
519
|
-
*/
|
|
520
|
-
setLogLevel(level) {
|
|
521
|
-
this.logger.setLevel(LogLevelConverter.levelToLog4Javascript(level));
|
|
522
|
-
}
|
|
523
|
-
/**
|
|
524
|
-
* Logs a message at level TRACE.
|
|
525
|
-
*
|
|
526
|
-
* @param methodName name of the method
|
|
527
|
-
* @param params optional parameters to be logged; objects will be formatted as JSON
|
|
528
|
-
*/
|
|
529
|
-
trace(methodName, ...params) {
|
|
530
|
-
if (this.logger.isTraceEnabled()) {
|
|
531
|
-
const args = [methodName];
|
|
532
|
-
for (const param of params) {
|
|
533
|
-
args.push(this.formatArgument(param));
|
|
534
|
-
}
|
|
535
|
-
this.logger.trace.apply(this.logger, args);
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
/**
|
|
539
|
-
* Logs a message at level DEBUG.
|
|
540
|
-
*
|
|
541
|
-
* @param methodName name of the method
|
|
542
|
-
* @param params optional parameters to be logged; objects will be formatted as JSON
|
|
543
|
-
*/
|
|
544
|
-
debug(methodName, ...params) {
|
|
545
|
-
if (this.logger.isDebugEnabled()) {
|
|
546
|
-
const args = [methodName];
|
|
547
|
-
for (const param of params) {
|
|
548
|
-
args.push(this.formatArgument(param));
|
|
549
|
-
}
|
|
550
|
-
this.logger.debug.apply(this.logger, args);
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
/**
|
|
554
|
-
* Logs a message at level INFO.
|
|
555
|
-
*
|
|
556
|
-
* @param methodName name of the method
|
|
557
|
-
* @param params optional parameters to be logged; objects will be formatted as JSON
|
|
558
|
-
*/
|
|
559
|
-
info(methodName, ...params) {
|
|
560
|
-
if (this.logger.isInfoEnabled()) {
|
|
561
|
-
const args = [methodName];
|
|
562
|
-
for (const param of params) {
|
|
563
|
-
args.push(this.formatArgument(param));
|
|
564
|
-
}
|
|
565
|
-
this.logger.info.apply(this.logger, args);
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
/**
|
|
569
|
-
* Logs a message at level WARN.
|
|
570
|
-
*
|
|
571
|
-
* @param methodName name of the method
|
|
572
|
-
* @param params optional parameters to be logged; objects will be formatted as JSON
|
|
573
|
-
*/
|
|
574
|
-
warn(methodName, ...params) {
|
|
575
|
-
if (this.logger.isWarnEnabled()) {
|
|
576
|
-
const args = [methodName];
|
|
577
|
-
for (const param of params) {
|
|
578
|
-
args.push(this.formatArgument(param));
|
|
579
|
-
}
|
|
580
|
-
this.logger.warn.apply(this.logger, args);
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
/**
|
|
584
|
-
* Logs a message at level ERROR.
|
|
585
|
-
*
|
|
586
|
-
* @param methodName name of the method
|
|
587
|
-
* @param params optional parameters to be logged; objects will be formatted as JSON
|
|
588
|
-
*/
|
|
589
|
-
error(methodName, ...params) {
|
|
590
|
-
if (this.logger.isErrorEnabled()) {
|
|
591
|
-
const args = [methodName];
|
|
592
|
-
for (const param of params) {
|
|
593
|
-
args.push(this.formatArgument(param));
|
|
594
|
-
}
|
|
595
|
-
this.logger.error.apply(this.logger, args);
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
/**
|
|
599
|
-
* Logs a message at level FATAL.
|
|
600
|
-
*
|
|
601
|
-
* @param methodName name of the method
|
|
602
|
-
* @param params optional parameters to be logged; objects will be formatted as JSON
|
|
603
|
-
*/
|
|
604
|
-
fatal(methodName, ...params) {
|
|
605
|
-
if (this.logger.isFatalEnabled()) {
|
|
606
|
-
const args = [methodName];
|
|
607
|
-
for (const param of params) {
|
|
608
|
-
args.push(this.formatArgument(param));
|
|
609
|
-
}
|
|
610
|
-
this.logger.fatal.apply(this.logger, args);
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
/**
|
|
614
|
-
* Logs the entry into a method.
|
|
615
|
-
* The method name will be logged at level INFO, the parameters at level DEBUG.
|
|
616
|
-
*
|
|
617
|
-
* @param methodName name of the method
|
|
618
|
-
* @param params optional parameters to be logged; objects will be formatted as JSON
|
|
619
|
-
*/
|
|
620
|
-
entry(methodName, ...params) {
|
|
621
|
-
if (this.logger.isInfoEnabled()) {
|
|
622
|
-
const args = [methodName, "entry"];
|
|
623
|
-
if (this.logger.isDebugEnabled()) {
|
|
624
|
-
for (const param of params) {
|
|
625
|
-
args.push(this.formatArgument(param));
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
this.logger.info.apply(this.logger, args);
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
/**
|
|
632
|
-
* Logs the exit of a method.
|
|
633
|
-
* The method name will be logged at level INFO, the parameters at level DEBUG.
|
|
634
|
-
*
|
|
635
|
-
* @param methodName name of the method
|
|
636
|
-
* @param params optional parameters to be logged; objects will be formatted as JSON
|
|
637
|
-
*/
|
|
638
|
-
exit(methodName, ...params) {
|
|
639
|
-
if (this.logger.isInfoEnabled()) {
|
|
640
|
-
const args = [methodName, "exit"];
|
|
641
|
-
if (this.logger.isDebugEnabled()) {
|
|
642
|
-
for (const param of params) {
|
|
643
|
-
args.push(this.formatArgument(param));
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
this.logger.info.apply(this.logger, args);
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
/**
|
|
650
|
-
* Formats the given argument.
|
|
651
|
-
*/
|
|
652
|
-
formatArgument(arg) {
|
|
653
|
-
if (typeof arg === "string") {
|
|
654
|
-
return arg;
|
|
655
|
-
}
|
|
656
|
-
else if (typeof arg === "number") {
|
|
657
|
-
return arg.toString();
|
|
658
|
-
}
|
|
659
|
-
else if (arg instanceof Error) {
|
|
660
|
-
// JSON.stringify() returns here "{ }"
|
|
661
|
-
return arg.toString();
|
|
662
|
-
}
|
|
663
|
-
else {
|
|
664
|
-
try {
|
|
665
|
-
return JSON.stringify(arg);
|
|
666
|
-
}
|
|
667
|
-
catch (e) {
|
|
668
|
-
return e.message;
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
/**
|
|
673
|
-
* Returns the internal Logger (for unit tests only).
|
|
674
|
-
*/
|
|
675
|
-
getInternalLogger() {
|
|
676
|
-
return this.logger;
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
/**
|
|
681
|
-
* An appender which stores the log messages in the browser's memory.
|
|
682
|
-
*
|
|
683
|
-
* The MemoryAppender is enabled by default.
|
|
684
|
-
* If you do not specify anything else, it is using this configuration:
|
|
685
|
-
*
|
|
686
|
-
* ```JSON
|
|
687
|
-
* {
|
|
688
|
-
* "memoryAppender": [
|
|
689
|
-
* {
|
|
690
|
-
* "maxMessages": 250,
|
|
691
|
-
* "threshold": "ALL"
|
|
692
|
-
* }
|
|
693
|
-
* }
|
|
694
|
-
* ```
|
|
695
|
-
*/
|
|
696
|
-
class MemoryAppender extends log4javascript.Appender {
|
|
697
|
-
/**
|
|
698
|
-
* Creates a new instance of the appender.
|
|
699
|
-
*
|
|
700
|
-
* @param configuration configuration for the appender.
|
|
701
|
-
*/
|
|
702
|
-
constructor(configuration) {
|
|
703
|
-
super();
|
|
704
|
-
this.logMessages = [];
|
|
705
|
-
// process configuration
|
|
706
|
-
configuration = configuration || {};
|
|
707
|
-
this.configure({
|
|
708
|
-
maxMessages: configuration.maxMessages || MemoryAppender.maxMessagesDefault,
|
|
709
|
-
threshold: configuration.threshold || MemoryAppender.thresholdDefault,
|
|
710
|
-
});
|
|
711
|
-
this.maxMessages = MemoryAppender.maxMessagesDefault;
|
|
712
|
-
}
|
|
713
|
-
/**
|
|
714
|
-
* Configures the logging depending on the given configuration.
|
|
715
|
-
* Only the defined properties get overwritten.
|
|
716
|
-
*
|
|
717
|
-
* @param configuration configuration data.
|
|
718
|
-
*/
|
|
719
|
-
configure(configuration) {
|
|
720
|
-
if (configuration) {
|
|
721
|
-
if (configuration.maxMessages) {
|
|
722
|
-
this.setMaxMessages(configuration.maxMessages);
|
|
723
|
-
}
|
|
724
|
-
if (configuration.threshold) {
|
|
725
|
-
const convertedThreshold = LogLevelConverter.levelToLog4Javascript(LogLevelConverter.levelFromString(configuration.threshold));
|
|
726
|
-
this.setThreshold(convertedThreshold);
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
/**
|
|
731
|
-
* Appender-specific method to append a log message.
|
|
732
|
-
*
|
|
733
|
-
* @param loggingEvent event to be appended.
|
|
734
|
-
*/
|
|
735
|
-
append(loggingEvent) {
|
|
736
|
-
// if logMessages is already full, remove oldest element
|
|
737
|
-
while (this.logMessages.length >= this.maxMessages) {
|
|
738
|
-
this.logMessages.shift();
|
|
739
|
-
}
|
|
740
|
-
// add event to logMessages
|
|
741
|
-
const message = {
|
|
742
|
-
level: LogLevel[LogLevelConverter.levelFromLog4Javascript(loggingEvent.level)],
|
|
743
|
-
logger: typeof loggingEvent.logger === "object" ? loggingEvent.logger.name : undefined,
|
|
744
|
-
message: loggingEvent.messages.slice(1),
|
|
745
|
-
methodName: loggingEvent.messages[0],
|
|
746
|
-
timeStamp: loggingEvent.timeStamp,
|
|
747
|
-
};
|
|
748
|
-
this.logMessages.push(message);
|
|
749
|
-
// inform about new message
|
|
750
|
-
if (typeof this.onLogMessagesChangedCallback === "function") {
|
|
751
|
-
this.onLogMessagesChangedCallback(message);
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
/**
|
|
755
|
-
* Gets the appender's name.
|
|
756
|
-
* Mainly for unit testing purposes.
|
|
757
|
-
*
|
|
758
|
-
* @return appender's name
|
|
759
|
-
*/
|
|
760
|
-
toString() {
|
|
761
|
-
return "Ionic.Logging.MemoryAppender";
|
|
762
|
-
}
|
|
763
|
-
/**
|
|
764
|
-
* Get the maximum number of messages which will be stored in memory.
|
|
765
|
-
*/
|
|
766
|
-
getMaxMessages() {
|
|
767
|
-
return this.maxMessages;
|
|
768
|
-
}
|
|
769
|
-
/**
|
|
770
|
-
* Set the maximum number of messages which will be stored in memory.
|
|
771
|
-
*
|
|
772
|
-
* If the appender stores currently more messages than the new value allows, the oldest messages get removed.
|
|
773
|
-
*
|
|
774
|
-
* @param value new maximum number
|
|
775
|
-
*/
|
|
776
|
-
setMaxMessages(value) {
|
|
777
|
-
this.maxMessages = value;
|
|
778
|
-
// if there are too much logMessages for the new value, remove oldest messages
|
|
779
|
-
if (this.logMessages.length > this.maxMessages) {
|
|
780
|
-
this.logMessages.splice(0, this.logMessages.length - this.maxMessages);
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
/**
|
|
784
|
-
* Gets all messages stored in memory.
|
|
785
|
-
*
|
|
786
|
-
* @return stored messages
|
|
787
|
-
*/
|
|
788
|
-
getLogMessages() {
|
|
789
|
-
return this.logMessages;
|
|
790
|
-
}
|
|
791
|
-
/**
|
|
792
|
-
* Remove all messages stored in memory.
|
|
793
|
-
*/
|
|
794
|
-
removeLogMessages() {
|
|
795
|
-
this.logMessages.splice(0);
|
|
796
|
-
}
|
|
797
|
-
/**
|
|
798
|
-
* Registers a callback which will be called every time a new message is appended.
|
|
799
|
-
* This could be useful if you want to show new messages in realtime.
|
|
800
|
-
*
|
|
801
|
-
* @param callback callback to be called
|
|
802
|
-
*/
|
|
803
|
-
setOnLogMessagesChangedCallback(callback) {
|
|
804
|
-
this.onLogMessagesChangedCallback = callback;
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
MemoryAppender.maxMessagesDefault = 250;
|
|
808
|
-
MemoryAppender.thresholdDefault = "ALL";
|
|
809
|
-
|
|
810
|
-
/**
|
|
811
|
-
* Service for logging functionality.
|
|
812
|
-
*
|
|
813
|
-
* By default, the following settings are used:
|
|
814
|
-
* - logger: root with level WARN
|
|
815
|
-
* - appender: BrowserConsoleAppender with threshold DEBUG and MemoryAppender with threshold ALL
|
|
816
|
-
*
|
|
817
|
-
* Via [configure](#configure), it is possible to amend these settings.
|
|
818
|
-
*/
|
|
819
|
-
class LoggingService {
|
|
820
|
-
/**
|
|
821
|
-
* Creates a new instance of the service.
|
|
822
|
-
*/
|
|
823
|
-
constructor() {
|
|
824
|
-
// prevent log4javascript to show alerts on case of errors
|
|
825
|
-
log4javascript.logLog.setQuietMode(true);
|
|
826
|
-
// create event emitter
|
|
827
|
-
this.logMessagesChanged = new EventEmitter();
|
|
828
|
-
this.ajaxAppenderFailed = new EventEmitter();
|
|
829
|
-
// configure appender
|
|
830
|
-
const logger = log4javascript.getRootLogger();
|
|
831
|
-
logger.setLevel(log4javascript.Level.WARN);
|
|
832
|
-
// browser console appender for debugger
|
|
833
|
-
this.browserConsoleAppender = new log4javascript.BrowserConsoleAppender();
|
|
834
|
-
this.browserConsoleAppender.setLayout(new log4javascript.PatternLayout("%d{HH:mm:ss,SSS} %c %m"));
|
|
835
|
-
this.browserConsoleAppender.setThreshold(log4javascript.Level.ALL);
|
|
836
|
-
logger.addAppender(this.browserConsoleAppender);
|
|
837
|
-
// in-memory appender for display on log messages page
|
|
838
|
-
this.memoryAppender = new MemoryAppender();
|
|
839
|
-
this.memoryAppender.setLayout(new log4javascript.PatternLayout("%d{HH:mm:ss,SSS} %c %m"));
|
|
840
|
-
this.memoryAppender.setOnLogMessagesChangedCallback((message) => {
|
|
841
|
-
this.logMessagesChanged.emit();
|
|
842
|
-
});
|
|
843
|
-
logger.addAppender(this.memoryAppender);
|
|
844
|
-
this.configure();
|
|
845
|
-
}
|
|
846
|
-
/**
|
|
847
|
-
* Configures the logging depending on the given configuration.
|
|
848
|
-
*
|
|
849
|
-
* @param configuration configuration data.
|
|
850
|
-
*/
|
|
851
|
-
configure(configuration) {
|
|
852
|
-
if (typeof configuration === "undefined") {
|
|
853
|
-
configuration = {};
|
|
854
|
-
}
|
|
855
|
-
// set log levels
|
|
856
|
-
if (typeof configuration.logLevels !== "undefined") {
|
|
857
|
-
for (const level of configuration.logLevels) {
|
|
858
|
-
let logger;
|
|
859
|
-
if (level.loggerName === "root") {
|
|
860
|
-
logger = log4javascript.getRootLogger();
|
|
861
|
-
}
|
|
862
|
-
else {
|
|
863
|
-
logger = log4javascript.getLogger(level.loggerName);
|
|
864
|
-
}
|
|
865
|
-
try {
|
|
866
|
-
logger.setLevel(LogLevelConverter.levelToLog4Javascript(LogLevelConverter.levelFromString(level.logLevel)));
|
|
867
|
-
}
|
|
868
|
-
catch (e) {
|
|
869
|
-
throw new Error(`invalid log level ${level.logLevel}`);
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
// configure AjaxAppender
|
|
874
|
-
if (typeof configuration.ajaxAppender !== "undefined") {
|
|
875
|
-
const ajaxAppender = new AjaxAppender(configuration.ajaxAppender);
|
|
876
|
-
ajaxAppender.appenderFailed.subscribe((message) => {
|
|
877
|
-
this.ajaxAppenderFailed.emit(message);
|
|
878
|
-
});
|
|
879
|
-
log4javascript.getRootLogger().addAppender(ajaxAppender);
|
|
880
|
-
}
|
|
881
|
-
// configure LocalStorageAppender
|
|
882
|
-
if (typeof configuration.localStorageAppender !== "undefined") {
|
|
883
|
-
const localStorageAppender = new LocalStorageAppender(configuration.localStorageAppender);
|
|
884
|
-
log4javascript.getRootLogger().addAppender(localStorageAppender);
|
|
885
|
-
// ensure that an eventual memoryAppender is behind the localStorageAppender
|
|
886
|
-
const appenders = new Logger().getInternalLogger().getEffectiveAppenders();
|
|
887
|
-
const memoryAppender = appenders.find((a) => a.toString() === "Ionic.Logging.MemoryAppender");
|
|
888
|
-
if (memoryAppender) {
|
|
889
|
-
log4javascript.getRootLogger().removeAppender(memoryAppender);
|
|
890
|
-
log4javascript.getRootLogger().addAppender(memoryAppender);
|
|
891
|
-
}
|
|
892
|
-
}
|
|
893
|
-
// configure MemoryAppender
|
|
894
|
-
if (configuration.memoryAppender) {
|
|
895
|
-
this.memoryAppender.configure(configuration.memoryAppender);
|
|
896
|
-
}
|
|
897
|
-
// configure BrowserConsoleAppender
|
|
898
|
-
if (configuration.browserConsoleAppender) {
|
|
899
|
-
if (configuration.browserConsoleAppender.threshold) {
|
|
900
|
-
const convertedThreshold = LogLevelConverter.levelToLog4Javascript(LogLevelConverter.levelFromString(configuration.browserConsoleAppender.threshold));
|
|
901
|
-
this.browserConsoleAppender.setThreshold(convertedThreshold);
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
/**
|
|
906
|
-
* Gets the root logger from which all other loggers derive.
|
|
907
|
-
*
|
|
908
|
-
* @return root logger
|
|
909
|
-
*/
|
|
910
|
-
getRootLogger() {
|
|
911
|
-
return new Logger();
|
|
912
|
-
}
|
|
913
|
-
/**
|
|
914
|
-
* Gets a logger with the specified name, creating it if a logger with that name does not already exist.
|
|
915
|
-
*
|
|
916
|
-
* @param loggerName name of the logger
|
|
917
|
-
* @return logger
|
|
918
|
-
*/
|
|
919
|
-
getLogger(loggerName) {
|
|
920
|
-
return new Logger(loggerName);
|
|
921
|
-
}
|
|
922
|
-
/**
|
|
923
|
-
* Gets the last log messages.
|
|
924
|
-
*
|
|
925
|
-
* The log messages are retrieved from the internal [MemoryAppender](../memoryappender.html).
|
|
926
|
-
* That means you will get only the most current messages. The number of the messages is limited
|
|
927
|
-
* by its maxMessages value.
|
|
928
|
-
*
|
|
929
|
-
* @return log messages
|
|
930
|
-
*/
|
|
931
|
-
getLogMessages() {
|
|
932
|
-
return this.memoryAppender.getLogMessages();
|
|
933
|
-
}
|
|
934
|
-
/**
|
|
935
|
-
* Loads the log messages written by the LocalStorageAppender with the given key.
|
|
936
|
-
*
|
|
937
|
-
* @param localStorageKey key for the local storage
|
|
938
|
-
* @returns log messages
|
|
939
|
-
*/
|
|
940
|
-
getLogMessagesFromLocalStorage(localStorageKey) {
|
|
941
|
-
return LocalStorageAppender.loadLogMessages(localStorageKey);
|
|
942
|
-
}
|
|
943
|
-
/**
|
|
944
|
-
* Remove all log messages.
|
|
945
|
-
*/
|
|
946
|
-
removeLogMessages() {
|
|
947
|
-
this.memoryAppender.removeLogMessages();
|
|
948
|
-
this.logMessagesChanged.emit();
|
|
949
|
-
}
|
|
950
|
-
/**
|
|
951
|
-
* Removes the log messages written by the LocalStorageAppender with the given key.
|
|
952
|
-
*
|
|
953
|
-
* @param localStorageKey key for the local storage
|
|
954
|
-
*/
|
|
955
|
-
removeLogMessagesFromLocalStorage(localStorageKey) {
|
|
956
|
-
LocalStorageAppender.removeLogMessages(localStorageKey);
|
|
957
|
-
this.logMessagesChanged.emit();
|
|
958
|
-
}
|
|
959
|
-
}
|
|
960
|
-
LoggingService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: LoggingService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
961
|
-
LoggingService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: LoggingService, providedIn: "root" });
|
|
962
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: LoggingService, decorators: [{
|
|
963
|
-
type: Injectable,
|
|
964
|
-
args: [{
|
|
965
|
-
providedIn: "root"
|
|
966
|
-
}]
|
|
967
|
-
}], ctorParameters: function () { return []; } });
|
|
968
|
-
|
|
969
|
-
class LoggingServiceModule {
|
|
970
|
-
}
|
|
971
|
-
LoggingServiceModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: LoggingServiceModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
972
|
-
LoggingServiceModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.0.4", ngImport: i0, type: LoggingServiceModule });
|
|
973
|
-
LoggingServiceModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: LoggingServiceModule });
|
|
974
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: LoggingServiceModule, decorators: [{
|
|
975
|
-
type: NgModule,
|
|
976
|
-
args: [{
|
|
977
|
-
imports: [],
|
|
978
|
-
declarations: [],
|
|
979
|
-
exports: []
|
|
980
|
-
}]
|
|
981
|
-
}] });
|
|
982
|
-
|
|
983
|
-
/*
|
|
984
|
-
* Public API Surface of ionic-logging-service.
|
|
985
|
-
*/
|
|
986
|
-
|
|
987
|
-
/**
|
|
988
|
-
* Generated bundle index. Do not edit.
|
|
989
|
-
*/
|
|
990
|
-
|
|
991
|
-
export { AjaxAppender, LocalStorageAppender, LogLevel, LogLevelConverter, Logger, LoggingService, LoggingServiceModule, MemoryAppender };
|
|
992
|
-
//# sourceMappingURL=ionic-logging-service.mjs.map
|