infront-logger 1.0.8 → 1.1.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/dist/index.es.js CHANGED
@@ -63,7 +63,7 @@ function fileFormatter(options) {
63
63
  );
64
64
  }
65
65
  function consoleFormatter(options) {
66
- return format$1.combine(
66
+ let formatters = [
67
67
  format$1.errors({ stack: true }),
68
68
  format$1.printf((info) => {
69
69
  if ((info == null ? void 0 : info.level) === "error" && info.stack) {
@@ -73,9 +73,12 @@ function consoleFormatter(options) {
73
73
  }
74
74
  }),
75
75
  // options.consoleJSON? format.json() : {transform : (info)=>info},
76
- options.consoleJSON ? format$1.json() : format$1.splat(),
77
- format$1.colorize({ all: true })
78
- );
76
+ options.consoleJSON ? format$1.json() : format$1.splat()
77
+ ];
78
+ if (!options.consoleJSON) {
79
+ formatters.push(format$1.colorize({ all: true }));
80
+ }
81
+ return format$1.combine(...formatters);
79
82
  }
80
83
  function getFormatter(type, options) {
81
84
  switch (type) {
@@ -135,16 +138,16 @@ class Logger {
135
138
  levels: this.options.levels,
136
139
  exitOnError: false,
137
140
  // format,
138
- transports: trans,
139
- exceptionHandlers
141
+ transports: trans
142
+ // exceptionHandlers
140
143
  });
141
144
  }
142
145
  }
143
- const redact$1 = (data, ...sensitiveKeysList) => {
146
+ const redact$2 = (data, ...sensitiveKeysList) => {
144
147
  var _a, _b;
145
148
  if (typeof data === "object" && data !== null && !((_b = (_a = data == null ? void 0 : data.constructor) == null ? void 0 : _a.name) == null ? void 0 : _b.startsWith("model"))) {
146
149
  if (Array.isArray(data)) {
147
- return data.map((item) => redact$1(item, ...sensitiveKeysList));
150
+ return data.map((item) => redact$2(item, ...sensitiveKeysList));
148
151
  }
149
152
  const redactedData = {};
150
153
  for (const key in data) {
@@ -152,7 +155,7 @@ const redact$1 = (data, ...sensitiveKeysList) => {
152
155
  if (sensitiveKeysList.includes(key)) {
153
156
  redactedData[key] = "*****";
154
157
  } else {
155
- redactedData[key] = redact$1(data[key], ...sensitiveKeysList);
158
+ redactedData[key] = redact$2(data[key], ...sensitiveKeysList);
156
159
  }
157
160
  }
158
161
  }
@@ -161,7 +164,7 @@ const redact$1 = (data, ...sensitiveKeysList) => {
161
164
  return data;
162
165
  }
163
166
  };
164
- const trim$1 = (data, length) => {
167
+ const trim$2 = (data, length) => {
165
168
  try {
166
169
  let str = JSON.stringify(data);
167
170
  if (str.length > length) {
@@ -174,8 +177,8 @@ const trim$1 = (data, length) => {
174
177
  };
175
178
  const http = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
176
179
  __proto__: null,
177
- redact: redact$1,
178
- trim: trim$1
180
+ redact: redact$2,
181
+ trim: trim$2
179
182
  }, Symbol.toStringTag, { value: "Module" }));
180
183
  function toFixedNumber(num, digits, base) {
181
184
  const pow = Math.pow(base ?? 10, digits);
@@ -184,7 +187,7 @@ function toFixedNumber(num, digits, base) {
184
187
  function bytesToMB$1(b) {
185
188
  return toFixedNumber(b / 1024 / 1024, 2, 10);
186
189
  }
187
- function formatBytes$1(bytes, decimals = 2) {
190
+ function formatBytes$2(bytes, decimals = 2) {
188
191
  if (!+bytes)
189
192
  return "0 Bytes";
190
193
  const k = 1024;
@@ -196,13 +199,13 @@ function formatBytes$1(bytes, decimals = 2) {
196
199
  const format = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
197
200
  __proto__: null,
198
201
  bytesToMB: bytesToMB$1,
199
- formatBytes: formatBytes$1,
202
+ formatBytes: formatBytes$2,
200
203
  toFixedNumber
201
204
  }, Symbol.toStringTag, { value: "Module" }));
202
205
  const pick = (obj, ...keys) => Object.fromEntries(
203
206
  keys.filter((key) => key in obj).map((key) => [key, obj[key]])
204
207
  );
205
- const omit$1 = (obj, ...keys) => {
208
+ const omit$2 = (obj, ...keys) => {
206
209
  const result = { ...obj };
207
210
  keys.forEach(function(prop) {
208
211
  delete result[prop];
@@ -211,7 +214,7 @@ const omit$1 = (obj, ...keys) => {
211
214
  };
212
215
  const object = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
213
216
  __proto__: null,
214
- omit: omit$1,
217
+ omit: omit$2,
215
218
  pick
216
219
  }, Symbol.toStringTag, { value: "Module" }));
217
220
  const v8 = require("v8");
@@ -299,10 +302,10 @@ class BaseLogger {
299
302
  return this;
300
303
  }
301
304
  }
302
- const { redact, trim } = http;
303
- const { formatBytes } = format;
304
- const { omit } = object;
305
- const MAX_BODY_LENGTH = 128;
305
+ const { redact: redact$1, trim: trim$1 } = http;
306
+ const { formatBytes: formatBytes$1 } = format;
307
+ const { omit: omit$1 } = object;
308
+ const MAX_BODY_LENGTH$1 = 128;
306
309
  class HTTPLogger extends BaseLogger {
307
310
  constructor(startTime, options = {}) {
308
311
  super("http", options);
@@ -327,20 +330,20 @@ class HTTPLogger extends BaseLogger {
327
330
  let res = this.res;
328
331
  let body = this.data;
329
332
  this.ctx.request = {
330
- headers: redact(req.headers, "cookie"),
333
+ headers: redact$1(req.headers, "cookie"),
331
334
  host: req.headers.host,
332
335
  baseUrl: req.baseUrl,
333
336
  url: req.originalUrl || req.url,
334
337
  method: req.method,
335
- body: redact(req.body, "password"),
338
+ body: redact$1(req.body, "password"),
336
339
  params: req == null ? void 0 : req.params,
337
- query: redact(req == null ? void 0 : req.query, "password"),
340
+ query: redact$1(req == null ? void 0 : req.query, "password"),
338
341
  clientIP: ((_a = req == null ? void 0 : req.headers["x-forwarded-for"]) == null ? void 0 : _a.split(",")[0]) ?? (req == null ? void 0 : req.socket.remoteAddress)
339
342
  };
340
343
  this.ctx.response = {
341
- headers: omit(res.getHeaders(), "set-cookie", "x-powered-by"),
344
+ headers: omit$1(res.getHeaders(), "set-cookie", "x-powered-by"),
342
345
  statusCode: res.statusCode,
343
- body: trim(body, MAX_BODY_LENGTH)
346
+ body: trim$1(body, MAX_BODY_LENGTH$1)
344
347
  };
345
348
  this.ctx.responseTimeMs = Date.now() - this.startTime;
346
349
  this.ctx.responseSizeBytes = this.data ? JSON.stringify(this.data).length : 0;
@@ -354,7 +357,7 @@ class HTTPLogger extends BaseLogger {
354
357
  let url = this.ctx.request.url;
355
358
  let statusCode = this.ctx.response.statusCode;
356
359
  let responseTimeMs = this.ctx.responseTimeMs + "ms";
357
- let responseSize = formatBytes((_a = JSON.stringify(this.data)) == null ? void 0 : _a.length);
360
+ let responseSize = formatBytes$1((_a = JSON.stringify(this.data)) == null ? void 0 : _a.length);
358
361
  return `${method} ${url} ${statusCode} ${responseTimeMs} ${responseSize} ${ip} ${remoteAddress} ${msg || ""}`;
359
362
  }
360
363
  success(req, res, body) {
@@ -447,8 +450,128 @@ function plugin(options = {}) {
447
450
  });
448
451
  };
449
452
  }
453
+ const { redact, trim } = http;
454
+ const { formatBytes } = format;
455
+ const { omit } = object;
456
+ const MAX_BODY_LENGTH = 128;
457
+ class FastifyLogger extends BaseLogger {
458
+ constructor(startTime, options = {}) {
459
+ super(options["component"] || "fastify-api", options);
460
+ this.startTime = startTime || Date.now();
461
+ }
462
+ getRequestSessionId(req) {
463
+ return req.id;
464
+ }
465
+ getResponseHeaders(res) {
466
+ return res.headers;
467
+ }
468
+ getRequestSocketRemoteAddress(req) {
469
+ var _a;
470
+ return (_a = req.socket) == null ? void 0 : _a.remoteAddress;
471
+ }
472
+ getRequestUserId(req) {
473
+ var _a;
474
+ return (_a = req["user"]) == null ? void 0 : _a.id;
475
+ }
476
+ getResponseStatusCode(res) {
477
+ return res.statusCode;
478
+ }
479
+ getRequestQuery(req) {
480
+ return { ...req.query };
481
+ }
482
+ getRequestParams(req) {
483
+ return req.params;
484
+ }
485
+ getRequestBody(req) {
486
+ return req.body;
487
+ }
488
+ getRequestMethod(req) {
489
+ return req.method;
490
+ }
491
+ getRequestUrl(req) {
492
+ return req.url;
493
+ }
494
+ getRequestOriginalUrl(req) {
495
+ return req.originalUrl;
496
+ }
497
+ getRequestBaseUrl(req) {
498
+ const url = new URL(req.url, "http://" + req.headers.host);
499
+ return url.origin;
500
+ }
501
+ getRequestHeaders(req) {
502
+ return req.headers;
503
+ }
504
+ request(req) {
505
+ this.session(this.getRequestSessionId(req));
506
+ this.req = req;
507
+ return this;
508
+ }
509
+ response(res) {
510
+ this.res = res;
511
+ return this;
512
+ }
513
+ body(data) {
514
+ this.data = data;
515
+ return this;
516
+ }
517
+ _prepare() {
518
+ var _a;
519
+ const req = this.req;
520
+ const res = this.res;
521
+ const body = this.data;
522
+ this.ctx.request = {
523
+ headers: redact(this.getRequestHeaders(req), "cookie"),
524
+ host: this.getRequestHeaders(req).host,
525
+ baseUrl: this.getRequestBaseUrl(req),
526
+ url: this.getRequestOriginalUrl(req) || this.getRequestUrl(req),
527
+ method: this.getRequestMethod(req),
528
+ body: redact(this.getRequestBody(req), "password"),
529
+ params: this.getRequestParams(req),
530
+ query: redact(this.getRequestQuery(req), "password"),
531
+ clientIP: ((_a = this.getRequestHeaders(req)["x-forwarded-for"]) == null ? void 0 : _a.split(",")[0]) ?? this.getRequestSocketRemoteAddress(req)
532
+ };
533
+ this.ctx.response = {
534
+ headers: omit(this.getResponseHeaders(res), "set-cookie", "x-powered-by"),
535
+ statusCode: this.getResponseStatusCode(res),
536
+ body: trim(body, MAX_BODY_LENGTH)
537
+ };
538
+ this.ctx.responseTimeMs = Date.now() - this.startTime;
539
+ this.ctx.responseSizeBytes = this.data ? JSON.stringify(this.data).length : 0;
540
+ this.ctx.user = this.getRequestUserId(req);
541
+ }
542
+ _message(msg) {
543
+ var _a;
544
+ const remoteAddress = this.getRemoteAddress(this.req);
545
+ const ip = this.ctx.request.clientIP;
546
+ const method = this.ctx.request.method;
547
+ const url = this.ctx.request.url;
548
+ const statusCode = this.ctx.response.statusCode;
549
+ const responseTimeMs = this.ctx.responseTimeMs + "ms";
550
+ const responseSize = formatBytes((_a = JSON.stringify(this.data)) == null ? void 0 : _a.length);
551
+ return `${method} ${url} ${statusCode} ${responseTimeMs} ${responseSize} ${ip} ${remoteAddress} ${msg || ""}`;
552
+ }
553
+ getRemoteAddress(req) {
554
+ var _a;
555
+ return ((_a = req == null ? void 0 : req.headers["x-forwarded-for"]) == null ? void 0 : _a.split(",")[0]) ?? (req == null ? void 0 : req.socket.remoteAddress);
556
+ }
557
+ success(req, res, body) {
558
+ if (req)
559
+ this.request(req);
560
+ if (res)
561
+ this.response(res);
562
+ if (body)
563
+ this.body(body);
564
+ this._prepare();
565
+ super.info(this._message());
566
+ }
567
+ error(err) {
568
+ this._prepare();
569
+ super.error(this._message(err));
570
+ }
571
+ }
450
572
  export {
451
573
  BaseLogger,
574
+ FastifyLogger,
452
575
  HTTPLogger as HttpLogger,
453
576
  plugin as MongooseLoggerPlugin
454
577
  };
package/dist/index.umd.js CHANGED
@@ -67,7 +67,7 @@
67
67
  );
68
68
  }
69
69
  function consoleFormatter(options) {
70
- return format$1.combine(
70
+ let formatters = [
71
71
  format$1.errors({ stack: true }),
72
72
  format$1.printf((info) => {
73
73
  if ((info == null ? void 0 : info.level) === "error" && info.stack) {
@@ -77,9 +77,12 @@
77
77
  }
78
78
  }),
79
79
  // options.consoleJSON? format.json() : {transform : (info)=>info},
80
- options.consoleJSON ? format$1.json() : format$1.splat(),
81
- format$1.colorize({ all: true })
82
- );
80
+ options.consoleJSON ? format$1.json() : format$1.splat()
81
+ ];
82
+ if (!options.consoleJSON) {
83
+ formatters.push(format$1.colorize({ all: true }));
84
+ }
85
+ return format$1.combine(...formatters);
83
86
  }
84
87
  function getFormatter(type, options) {
85
88
  switch (type) {
@@ -139,16 +142,16 @@
139
142
  levels: this.options.levels,
140
143
  exitOnError: false,
141
144
  // format,
142
- transports: trans,
143
- exceptionHandlers
145
+ transports: trans
146
+ // exceptionHandlers
144
147
  });
145
148
  }
146
149
  }
147
- const redact$1 = (data, ...sensitiveKeysList) => {
150
+ const redact$2 = (data, ...sensitiveKeysList) => {
148
151
  var _a, _b;
149
152
  if (typeof data === "object" && data !== null && !((_b = (_a = data == null ? void 0 : data.constructor) == null ? void 0 : _a.name) == null ? void 0 : _b.startsWith("model"))) {
150
153
  if (Array.isArray(data)) {
151
- return data.map((item) => redact$1(item, ...sensitiveKeysList));
154
+ return data.map((item) => redact$2(item, ...sensitiveKeysList));
152
155
  }
153
156
  const redactedData = {};
154
157
  for (const key in data) {
@@ -156,7 +159,7 @@
156
159
  if (sensitiveKeysList.includes(key)) {
157
160
  redactedData[key] = "*****";
158
161
  } else {
159
- redactedData[key] = redact$1(data[key], ...sensitiveKeysList);
162
+ redactedData[key] = redact$2(data[key], ...sensitiveKeysList);
160
163
  }
161
164
  }
162
165
  }
@@ -165,7 +168,7 @@
165
168
  return data;
166
169
  }
167
170
  };
168
- const trim$1 = (data, length) => {
171
+ const trim$2 = (data, length) => {
169
172
  try {
170
173
  let str = JSON.stringify(data);
171
174
  if (str.length > length) {
@@ -178,8 +181,8 @@
178
181
  };
179
182
  const http = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
180
183
  __proto__: null,
181
- redact: redact$1,
182
- trim: trim$1
184
+ redact: redact$2,
185
+ trim: trim$2
183
186
  }, Symbol.toStringTag, { value: "Module" }));
184
187
  function toFixedNumber(num, digits, base) {
185
188
  const pow = Math.pow(base ?? 10, digits);
@@ -188,7 +191,7 @@
188
191
  function bytesToMB$1(b) {
189
192
  return toFixedNumber(b / 1024 / 1024, 2, 10);
190
193
  }
191
- function formatBytes$1(bytes, decimals = 2) {
194
+ function formatBytes$2(bytes, decimals = 2) {
192
195
  if (!+bytes)
193
196
  return "0 Bytes";
194
197
  const k = 1024;
@@ -200,13 +203,13 @@
200
203
  const format = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
201
204
  __proto__: null,
202
205
  bytesToMB: bytesToMB$1,
203
- formatBytes: formatBytes$1,
206
+ formatBytes: formatBytes$2,
204
207
  toFixedNumber
205
208
  }, Symbol.toStringTag, { value: "Module" }));
206
209
  const pick = (obj, ...keys) => Object.fromEntries(
207
210
  keys.filter((key) => key in obj).map((key) => [key, obj[key]])
208
211
  );
209
- const omit$1 = (obj, ...keys) => {
212
+ const omit$2 = (obj, ...keys) => {
210
213
  const result = { ...obj };
211
214
  keys.forEach(function(prop) {
212
215
  delete result[prop];
@@ -215,7 +218,7 @@
215
218
  };
216
219
  const object = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
217
220
  __proto__: null,
218
- omit: omit$1,
221
+ omit: omit$2,
219
222
  pick
220
223
  }, Symbol.toStringTag, { value: "Module" }));
221
224
  const v8 = require("v8");
@@ -303,10 +306,10 @@
303
306
  return this;
304
307
  }
305
308
  }
306
- const { redact, trim } = http;
307
- const { formatBytes } = format;
308
- const { omit } = object;
309
- const MAX_BODY_LENGTH = 128;
309
+ const { redact: redact$1, trim: trim$1 } = http;
310
+ const { formatBytes: formatBytes$1 } = format;
311
+ const { omit: omit$1 } = object;
312
+ const MAX_BODY_LENGTH$1 = 128;
310
313
  class HTTPLogger extends BaseLogger {
311
314
  constructor(startTime, options = {}) {
312
315
  super("http", options);
@@ -331,20 +334,20 @@
331
334
  let res = this.res;
332
335
  let body = this.data;
333
336
  this.ctx.request = {
334
- headers: redact(req.headers, "cookie"),
337
+ headers: redact$1(req.headers, "cookie"),
335
338
  host: req.headers.host,
336
339
  baseUrl: req.baseUrl,
337
340
  url: req.originalUrl || req.url,
338
341
  method: req.method,
339
- body: redact(req.body, "password"),
342
+ body: redact$1(req.body, "password"),
340
343
  params: req == null ? void 0 : req.params,
341
- query: redact(req == null ? void 0 : req.query, "password"),
344
+ query: redact$1(req == null ? void 0 : req.query, "password"),
342
345
  clientIP: ((_a = req == null ? void 0 : req.headers["x-forwarded-for"]) == null ? void 0 : _a.split(",")[0]) ?? (req == null ? void 0 : req.socket.remoteAddress)
343
346
  };
344
347
  this.ctx.response = {
345
- headers: omit(res.getHeaders(), "set-cookie", "x-powered-by"),
348
+ headers: omit$1(res.getHeaders(), "set-cookie", "x-powered-by"),
346
349
  statusCode: res.statusCode,
347
- body: trim(body, MAX_BODY_LENGTH)
350
+ body: trim$1(body, MAX_BODY_LENGTH$1)
348
351
  };
349
352
  this.ctx.responseTimeMs = Date.now() - this.startTime;
350
353
  this.ctx.responseSizeBytes = this.data ? JSON.stringify(this.data).length : 0;
@@ -358,7 +361,7 @@
358
361
  let url = this.ctx.request.url;
359
362
  let statusCode = this.ctx.response.statusCode;
360
363
  let responseTimeMs = this.ctx.responseTimeMs + "ms";
361
- let responseSize = formatBytes((_a = JSON.stringify(this.data)) == null ? void 0 : _a.length);
364
+ let responseSize = formatBytes$1((_a = JSON.stringify(this.data)) == null ? void 0 : _a.length);
362
365
  return `${method} ${url} ${statusCode} ${responseTimeMs} ${responseSize} ${ip} ${remoteAddress} ${msg || ""}`;
363
366
  }
364
367
  success(req, res, body) {
@@ -451,7 +454,127 @@
451
454
  });
452
455
  };
453
456
  }
457
+ const { redact, trim } = http;
458
+ const { formatBytes } = format;
459
+ const { omit } = object;
460
+ const MAX_BODY_LENGTH = 128;
461
+ class FastifyLogger extends BaseLogger {
462
+ constructor(startTime, options = {}) {
463
+ super(options["component"] || "fastify-api", options);
464
+ this.startTime = startTime || Date.now();
465
+ }
466
+ getRequestSessionId(req) {
467
+ return req.id;
468
+ }
469
+ getResponseHeaders(res) {
470
+ return res.headers;
471
+ }
472
+ getRequestSocketRemoteAddress(req) {
473
+ var _a;
474
+ return (_a = req.socket) == null ? void 0 : _a.remoteAddress;
475
+ }
476
+ getRequestUserId(req) {
477
+ var _a;
478
+ return (_a = req["user"]) == null ? void 0 : _a.id;
479
+ }
480
+ getResponseStatusCode(res) {
481
+ return res.statusCode;
482
+ }
483
+ getRequestQuery(req) {
484
+ return { ...req.query };
485
+ }
486
+ getRequestParams(req) {
487
+ return req.params;
488
+ }
489
+ getRequestBody(req) {
490
+ return req.body;
491
+ }
492
+ getRequestMethod(req) {
493
+ return req.method;
494
+ }
495
+ getRequestUrl(req) {
496
+ return req.url;
497
+ }
498
+ getRequestOriginalUrl(req) {
499
+ return req.originalUrl;
500
+ }
501
+ getRequestBaseUrl(req) {
502
+ const url = new URL(req.url, "http://" + req.headers.host);
503
+ return url.origin;
504
+ }
505
+ getRequestHeaders(req) {
506
+ return req.headers;
507
+ }
508
+ request(req) {
509
+ this.session(this.getRequestSessionId(req));
510
+ this.req = req;
511
+ return this;
512
+ }
513
+ response(res) {
514
+ this.res = res;
515
+ return this;
516
+ }
517
+ body(data) {
518
+ this.data = data;
519
+ return this;
520
+ }
521
+ _prepare() {
522
+ var _a;
523
+ const req = this.req;
524
+ const res = this.res;
525
+ const body = this.data;
526
+ this.ctx.request = {
527
+ headers: redact(this.getRequestHeaders(req), "cookie"),
528
+ host: this.getRequestHeaders(req).host,
529
+ baseUrl: this.getRequestBaseUrl(req),
530
+ url: this.getRequestOriginalUrl(req) || this.getRequestUrl(req),
531
+ method: this.getRequestMethod(req),
532
+ body: redact(this.getRequestBody(req), "password"),
533
+ params: this.getRequestParams(req),
534
+ query: redact(this.getRequestQuery(req), "password"),
535
+ clientIP: ((_a = this.getRequestHeaders(req)["x-forwarded-for"]) == null ? void 0 : _a.split(",")[0]) ?? this.getRequestSocketRemoteAddress(req)
536
+ };
537
+ this.ctx.response = {
538
+ headers: omit(this.getResponseHeaders(res), "set-cookie", "x-powered-by"),
539
+ statusCode: this.getResponseStatusCode(res),
540
+ body: trim(body, MAX_BODY_LENGTH)
541
+ };
542
+ this.ctx.responseTimeMs = Date.now() - this.startTime;
543
+ this.ctx.responseSizeBytes = this.data ? JSON.stringify(this.data).length : 0;
544
+ this.ctx.user = this.getRequestUserId(req);
545
+ }
546
+ _message(msg) {
547
+ var _a;
548
+ const remoteAddress = this.getRemoteAddress(this.req);
549
+ const ip = this.ctx.request.clientIP;
550
+ const method = this.ctx.request.method;
551
+ const url = this.ctx.request.url;
552
+ const statusCode = this.ctx.response.statusCode;
553
+ const responseTimeMs = this.ctx.responseTimeMs + "ms";
554
+ const responseSize = formatBytes((_a = JSON.stringify(this.data)) == null ? void 0 : _a.length);
555
+ return `${method} ${url} ${statusCode} ${responseTimeMs} ${responseSize} ${ip} ${remoteAddress} ${msg || ""}`;
556
+ }
557
+ getRemoteAddress(req) {
558
+ var _a;
559
+ return ((_a = req == null ? void 0 : req.headers["x-forwarded-for"]) == null ? void 0 : _a.split(",")[0]) ?? (req == null ? void 0 : req.socket.remoteAddress);
560
+ }
561
+ success(req, res, body) {
562
+ if (req)
563
+ this.request(req);
564
+ if (res)
565
+ this.response(res);
566
+ if (body)
567
+ this.body(body);
568
+ this._prepare();
569
+ super.info(this._message());
570
+ }
571
+ error(err) {
572
+ this._prepare();
573
+ super.error(this._message(err));
574
+ }
575
+ }
454
576
  exports2.BaseLogger = BaseLogger;
577
+ exports2.FastifyLogger = FastifyLogger;
455
578
  exports2.HttpLogger = HTTPLogger;
456
579
  exports2.MongooseLoggerPlugin = plugin;
457
580
  Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
package/dist/main.d.ts CHANGED
@@ -20,13 +20,27 @@ export class BaseLogger {
20
20
  export class HTTPLogger extends BaseLogger {
21
21
  constructor(startTime: number, options?: any);
22
22
 
23
- request(req: HttpRequest): this;
23
+ request(req: object): this;
24
24
 
25
- response(res: HttpResponse): this;
25
+ response(res: object): this;
26
26
 
27
27
  body(data: any): this;
28
28
 
29
- success(req: HttpRequest, res: HttpResponse, body?: any): void;
29
+ success(req: object, res: object, body?: any): void;
30
+
31
+ error(err: any): void;
32
+ }
33
+
34
+ export class FastifyLogger extends BaseLogger {
35
+ constructor(startTime: number, options?: any);
36
+
37
+ request(req: object): this;
38
+
39
+ response(res: object): this;
40
+
41
+ body(data: any): this;
42
+
43
+ success(req?: object, res?: object, body?: any): void;
30
44
 
31
45
  error(err: any): void;
32
46
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "infront-logger",
3
- "version": "1.0.8",
3
+ "version": "1.1.0",
4
4
  "description": "",
5
5
  "files": [
6
6
  "dist"
@@ -32,6 +32,7 @@
32
32
  "test": "echo \"Error: no test specified\" && exit 1",
33
33
  "dev": "vite",
34
34
  "build": "vite build",
35
+ "build:watch": "vite build --watch",
35
36
  "preview": "vite preview"
36
37
  }
37
38
  }