@aomex/access-log 0.0.0-stage → 4.5.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/CHANGELOG.md ADDED
@@ -0,0 +1,740 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # [4.5.0](https://github.com/aomex/aomex/compare/v4.4.0...v4.5.0) (2026-11-24)
7
+
8
+ ### Features
9
+
10
+ * **access-log:** 由 http-access-log 重命名并增加 websocket 访问日志 ([1426d7b](https://github.com/aomex/aomex/commit/1426d7b624b150f94f28b485be29c69e54e87b07))
11
+
12
+
13
+ # [4.4.0](https://github.com/aomex/aomex/compare/v4.3.0...v4.4.0) (2026-11-22)
14
+
15
+ **Note:** Version bump only for package @aomex/http-access-log
16
+
17
+
18
+
19
+
20
+
21
+ # [4.3.0](https://github.com/aomex/aomex/compare/v4.2.0...v4.3.0) (2026-11-21)
22
+
23
+ **Note:** Version bump only for package @aomex/http-access-log
24
+
25
+
26
+
27
+
28
+
29
+ # [4.2.0](https://github.com/aomex/aomex/compare/v4.1.0...v4.2.0) (2026-11-20)
30
+
31
+ **Note:** Version bump only for package @aomex/http-access-log
32
+
33
+
34
+
35
+
36
+
37
+ # [4.1.0](https://github.com/aomex/aomex/compare/v4.0.0...v4.1.0) (2026-11-18)
38
+
39
+ **Note:** Version bump only for package @aomex/http-access-log
40
+
41
+
42
+
43
+
44
+
45
+ # [4.0.0](https://github.com/aomex/aomex/compare/v3.30.7...v4.0.0) (2026-11-17)
46
+
47
+ * feat(logger)!: 引入 BaseLoggerService ([4c2657a](https://github.com/aomex/aomex/commit/4c2657aae21d3fcbe139d4de3477a6415d901b2c))
48
+
49
+ ### BREAKING CHANGES
50
+
51
+ * http-logger 重命名为 http-access-log
52
+ * logger需绑定到service中使用
53
+
54
+
55
+ ## [3.30.7](https://github.com/aomex/aomex/compare/v3.30.6...v3.30.7) (2026-11-01)
56
+
57
+ **Note:** Version bump only for package @aomex/http-logger
58
+
59
+
60
+
61
+
62
+
63
+ ## [3.30.6](https://github.com/aomex/aomex/compare/v3.30.5...v3.30.6) (2026-10-19)
64
+
65
+ **Note:** Version bump only for package @aomex/http-logger
66
+
67
+
68
+
69
+
70
+
71
+ ## [3.30.5](https://github.com/aomex/aomex/compare/v3.30.4...v3.30.5) (2026-06-16)
72
+
73
+ **Note:** Version bump only for package @aomex/http-logger
74
+
75
+
76
+
77
+
78
+
79
+ ## [3.30.4](https://github.com/aomex/aomex/compare/v3.30.3...v3.30.4) (2026-01-21)
80
+
81
+ **Note:** Version bump only for package @aomex/http-logger
82
+
83
+
84
+
85
+
86
+
87
+ ## [3.30.3](https://github.com/aomex/aomex/compare/v3.30.2...v3.30.3) (2025-12-01)
88
+
89
+ **Note:** Version bump only for package @aomex/http-logger
90
+
91
+
92
+
93
+
94
+
95
+ ## [3.30.2](https://github.com/aomex/aomex/compare/v3.30.1...v3.30.2) (2025-12-01)
96
+
97
+ **Note:** Version bump only for package @aomex/http-logger
98
+
99
+
100
+
101
+
102
+
103
+ ## [3.30.1](https://github.com/aomex/aomex/compare/v3.30.0...v3.30.1) (2025-12-01)
104
+
105
+ **Note:** Version bump only for package @aomex/http-logger
106
+
107
+
108
+
109
+
110
+
111
+ # [3.30.0](https://github.com/aomex/aomex/compare/v3.29.2...v3.30.0) (2025-11-30)
112
+
113
+ **Note:** Version bump only for package @aomex/http-logger
114
+
115
+
116
+
117
+
118
+
119
+ ## [3.29.2](https://github.com/aomex/aomex/compare/v3.29.1...v3.29.2) (2025-08-25)
120
+
121
+ **Note:** Version bump only for package @aomex/http-logger
122
+
123
+
124
+
125
+
126
+
127
+ ## [3.29.1](https://github.com/aomex/aomex/compare/v3.29.0...v3.29.1) (2025-07-26)
128
+
129
+ **Note:** Version bump only for package @aomex/http-logger
130
+
131
+
132
+
133
+
134
+
135
+ # [3.29.0](https://github.com/aomex/aomex/compare/v3.28.3...v3.29.0) (2025-07-17)
136
+
137
+ **Note:** Version bump only for package @aomex/http-logger
138
+
139
+
140
+
141
+
142
+
143
+ ## [3.28.3](https://github.com/aomex/aomex/compare/v3.28.2...v3.28.3) (2025-07-10)
144
+
145
+ **Note:** Version bump only for package @aomex/http-logger
146
+
147
+
148
+
149
+
150
+
151
+ ## [3.28.2](https://github.com/aomex/aomex/compare/v3.28.1...v3.28.2) (2025-07-09)
152
+
153
+ **Note:** Version bump only for package @aomex/http-logger
154
+
155
+
156
+
157
+
158
+
159
+ ## [3.28.1](https://github.com/aomex/aomex/compare/v3.28.0...v3.28.1) (2025-07-08)
160
+
161
+ **Note:** Version bump only for package @aomex/http-logger
162
+
163
+
164
+
165
+
166
+
167
+ # [3.28.0](https://github.com/aomex/aomex/compare/v3.27.4...v3.28.0) (2025-07-08)
168
+
169
+ **Note:** Version bump only for package @aomex/http-logger
170
+
171
+
172
+
173
+
174
+
175
+ ## [3.27.4](https://github.com/aomex/aomex/compare/v3.27.3...v3.27.4) (2025-06-29)
176
+
177
+ **Note:** Version bump only for package @aomex/http-logger
178
+
179
+
180
+
181
+
182
+
183
+ ## [3.27.3](https://github.com/aomex/aomex/compare/v3.27.2...v3.27.3) (2025-06-29)
184
+
185
+ **Note:** Version bump only for package @aomex/http-logger
186
+
187
+
188
+
189
+
190
+
191
+ ## [3.27.2](https://github.com/aomex/aomex/compare/v3.27.1...v3.27.2) (2025-06-04)
192
+
193
+ **Note:** Version bump only for package @aomex/http-logger
194
+
195
+
196
+
197
+
198
+
199
+ ## [3.27.1](https://github.com/aomex/aomex/compare/v3.27.0...v3.27.1) (2025-05-22)
200
+
201
+ **Note:** Version bump only for package @aomex/http-logger
202
+
203
+
204
+
205
+
206
+
207
+ # [3.27.0](https://github.com/aomex/aomex/compare/v3.26.0...v3.27.0) (2025-05-03)
208
+
209
+ **Note:** Version bump only for package @aomex/http-logger
210
+
211
+
212
+
213
+
214
+
215
+ # [3.26.0](https://github.com/aomex/aomex/compare/v3.25.0...v3.26.0) (2025-05-03)
216
+
217
+ **Note:** Version bump only for package @aomex/http-logger
218
+
219
+
220
+
221
+
222
+
223
+ # [3.25.0](https://github.com/aomex/aomex/compare/v3.24.0...v3.25.0) (2025-04-22)
224
+
225
+ **Note:** Version bump only for package @aomex/http-logger
226
+
227
+
228
+
229
+
230
+
231
+ # [3.24.0](https://github.com/aomex/aomex/compare/v3.23.3...v3.24.0) (2025-04-20)
232
+
233
+ **Note:** Version bump only for package @aomex/http-logger
234
+
235
+
236
+
237
+
238
+
239
+ ## [3.23.3](https://github.com/aomex/aomex/compare/v3.23.2...v3.23.3) (2025-04-18)
240
+
241
+ **Note:** Version bump only for package @aomex/http-logger
242
+
243
+
244
+
245
+
246
+
247
+ ## [3.23.2](https://github.com/aomex/aomex/compare/v3.23.1...v3.23.2) (2025-04-18)
248
+
249
+ **Note:** Version bump only for package @aomex/http-logger
250
+
251
+
252
+
253
+
254
+
255
+ ## [3.23.1](https://github.com/aomex/aomex/compare/v3.23.0...v3.23.1) (2025-04-18)
256
+
257
+ **Note:** Version bump only for package @aomex/http-logger
258
+
259
+
260
+
261
+
262
+
263
+ # [3.23.0](https://github.com/aomex/aomex/compare/v3.22.0...v3.23.0) (2025-04-16)
264
+
265
+ **Note:** Version bump only for package @aomex/http-logger
266
+
267
+
268
+
269
+
270
+
271
+ # [3.22.0](https://github.com/aomex/aomex/compare/v3.21.1...v3.22.0) (2025-04-07)
272
+
273
+ **Note:** Version bump only for package @aomex/http-logger
274
+
275
+
276
+
277
+
278
+
279
+ ## [3.21.1](https://github.com/aomex/aomex/compare/v3.21.0...v3.21.1) (2025-04-06)
280
+
281
+ **Note:** Version bump only for package @aomex/http-logger
282
+
283
+
284
+
285
+
286
+
287
+ # [3.21.0](https://github.com/aomex/aomex/compare/v3.20.0...v3.21.0) (2025-04-06)
288
+
289
+ **Note:** Version bump only for package @aomex/http-logger
290
+
291
+
292
+
293
+
294
+
295
+ # [3.20.0](https://github.com/aomex/aomex/compare/v3.19.2...v3.20.0) (2025-04-05)
296
+
297
+ **Note:** Version bump only for package @aomex/http-logger
298
+
299
+
300
+
301
+
302
+
303
+ ## [3.19.2](https://github.com/aomex/aomex/compare/v3.19.1...v3.19.2) (2025-04-05)
304
+
305
+ **Note:** Version bump only for package @aomex/http-logger
306
+
307
+
308
+
309
+
310
+
311
+ ## [3.19.1](https://github.com/aomex/aomex/compare/v3.19.0...v3.19.1) (2025-04-05)
312
+
313
+ **Note:** Version bump only for package @aomex/http-logger
314
+
315
+
316
+
317
+
318
+
319
+ # [3.19.0](https://github.com/aomex/aomex/compare/v3.18.0...v3.19.0) (2025-04-05)
320
+
321
+ **Note:** Version bump only for package @aomex/http-logger
322
+
323
+
324
+
325
+
326
+
327
+ # [3.18.0](https://github.com/aomex/aomex/compare/v3.17.3...v3.18.0) (2025-04-03)
328
+
329
+ **Note:** Version bump only for package @aomex/http-logger
330
+
331
+
332
+
333
+
334
+
335
+ ## [3.17.3](https://github.com/aomex/aomex/compare/v3.17.2...v3.17.3) (2025-03-26)
336
+
337
+
338
+ ### Bug Fixes
339
+
340
+ * 内部依赖使用固定版本号 ([aa70c2a](https://github.com/aomex/aomex/commit/aa70c2ad444414ec6619b9579ad8037a7191a86f))
341
+
342
+
343
+
344
+
345
+
346
+ ## [3.17.2](https://github.com/aomex/aomex/compare/v3.17.1...v3.17.2) (2025-03-26)
347
+
348
+ **Note:** Version bump only for package @aomex/http-logger
349
+
350
+
351
+
352
+
353
+
354
+ ## [3.17.1](https://github.com/aomex/aomex/compare/v3.17.0...v3.17.1) (2025-03-09)
355
+
356
+ **Note:** Version bump only for package @aomex/http-logger
357
+
358
+
359
+
360
+
361
+
362
+ # [3.17.0](https://github.com/aomex/aomex/compare/v3.16.0...v3.17.0) (2025-03-09)
363
+
364
+
365
+ ### Features
366
+
367
+ * **http-logger:** 增加disable属性禁用日志 ([8d43283](https://github.com/aomex/aomex/commit/8d43283b00e5df9e398655b5e5b78049cd20083a))
368
+ * **logger:** 独立安装 ([9a3f444](https://github.com/aomex/aomex/commit/9a3f4446ba7dd2da9a7f52eec8891624e9208435))
369
+
370
+
371
+
372
+
373
+
374
+ # [3.16.0](https://github.com/aomex/aomex/compare/v3.15.1...v3.16.0) (2025-03-09)
375
+
376
+ **Note:** Version bump only for package @aomex/http-logger
377
+
378
+
379
+
380
+
381
+
382
+ ## [3.15.1](https://github.com/aomex/aomex/compare/v3.15.0...v3.15.1) (2025-02-09)
383
+
384
+ **Note:** Version bump only for package @aomex/http-logger
385
+
386
+
387
+
388
+
389
+
390
+ # [3.15.0](https://github.com/aomex/aomex/compare/v3.14.2...v3.15.0) (2025-02-09)
391
+
392
+ **Note:** Version bump only for package @aomex/http-logger
393
+
394
+
395
+
396
+
397
+
398
+ ## [3.14.2](https://github.com/aomex/aomex/compare/v3.14.1...v3.14.2) (2025-01-14)
399
+
400
+ **Note:** Version bump only for package @aomex/http-logger
401
+
402
+
403
+
404
+
405
+
406
+ ## [3.14.1](https://github.com/aomex/aomex/compare/v3.14.0...v3.14.1) (2025-01-09)
407
+
408
+ **Note:** Version bump only for package @aomex/http-logger
409
+
410
+
411
+
412
+
413
+
414
+ # [3.14.0](https://github.com/aomex/aomex/compare/v3.13.1...v3.14.0) (2025-01-02)
415
+
416
+ **Note:** Version bump only for package @aomex/http-logger
417
+
418
+
419
+
420
+
421
+
422
+ ## [3.13.1](https://github.com/aomex/aomex/compare/v3.13.0...v3.13.1) (2024-12-29)
423
+
424
+ **Note:** Version bump only for package @aomex/http-logger
425
+
426
+
427
+
428
+
429
+
430
+ # [3.13.0](https://github.com/aomex/aomex/compare/v3.12.1...v3.13.0) (2024-12-27)
431
+
432
+ **Note:** Version bump only for package @aomex/http-logger
433
+
434
+
435
+
436
+
437
+
438
+ ## [3.12.1](https://github.com/aomex/aomex/compare/v3.12.0...v3.12.1) (2024-12-19)
439
+
440
+ **Note:** Version bump only for package @aomex/http-logger
441
+
442
+
443
+
444
+
445
+
446
+ # [3.12.0](https://github.com/aomex/aomex/compare/v3.11.0...v3.12.0) (2024-11-07)
447
+
448
+ **Note:** Version bump only for package @aomex/http-logger
449
+
450
+
451
+
452
+
453
+
454
+ # [3.11.0](https://github.com/aomex/aomex/compare/v3.10.0...v3.11.0) (2024-11-07)
455
+
456
+ **Note:** Version bump only for package @aomex/http-logger
457
+
458
+
459
+
460
+
461
+
462
+ # [3.10.0](https://github.com/aomex/aomex/compare/v3.9.0...v3.10.0) (2024-11-02)
463
+
464
+
465
+ ### Features
466
+
467
+ * **logger:** timestamp使用日期类型 ([26a5931](https://github.com/aomex/aomex/commit/26a5931ca0a9dfdb5a7abcdfd967092e5334aa04))
468
+
469
+
470
+
471
+
472
+
473
+ # [3.9.0](https://github.com/aomex/aomex/compare/v3.8.1...v3.9.0) (2024-10-30)
474
+
475
+
476
+ ### Features
477
+
478
+ * **http-logger:** 请求日志简化为一条 ([71a9c91](https://github.com/aomex/aomex/commit/71a9c91df80adbfb87ca07b25b52c3b430ad1b12))
479
+
480
+
481
+
482
+
483
+
484
+ ## [3.8.1](https://github.com/aomex/aomex/compare/v3.8.0...v3.8.1) (2024-10-26)
485
+
486
+ **Note:** Version bump only for package @aomex/http-logger
487
+
488
+
489
+
490
+
491
+
492
+ # [3.8.0](https://github.com/aomex/aomex/compare/v3.7.2...v3.8.0) (2024-10-26)
493
+
494
+ **Note:** Version bump only for package @aomex/http-logger
495
+
496
+
497
+
498
+
499
+
500
+ ## [3.7.2](https://github.com/aomex/aomex/compare/v3.7.1...v3.7.2) (2024-10-22)
501
+
502
+ **Note:** Version bump only for package @aomex/http-logger
503
+
504
+
505
+
506
+
507
+
508
+ ## [3.7.1](https://github.com/aomex/aomex/compare/v3.7.0...v3.7.1) (2024-10-22)
509
+
510
+ **Note:** Version bump only for package @aomex/http-logger
511
+
512
+
513
+
514
+
515
+
516
+ # [3.7.0](https://github.com/aomex/aomex/compare/v3.6.0...v3.7.0) (2024-10-19)
517
+
518
+ **Note:** Version bump only for package @aomex/http-logger
519
+
520
+
521
+
522
+
523
+
524
+ # [3.6.0](https://github.com/aomex/aomex/compare/v3.5.0...v3.6.0) (2024-10-17)
525
+
526
+ **Note:** Version bump only for package @aomex/http-logger
527
+
528
+
529
+
530
+
531
+
532
+ # [3.5.0](https://github.com/aomex/aomex/compare/v3.4.2...v3.5.0) (2024-10-16)
533
+
534
+ **Note:** Version bump only for package @aomex/http-logger
535
+
536
+
537
+
538
+
539
+
540
+ ## [3.4.2](https://github.com/aomex/aomex/compare/v3.4.1...v3.4.2) (2024-10-07)
541
+
542
+ **Note:** Version bump only for package @aomex/http-logger
543
+
544
+
545
+
546
+
547
+
548
+ ## [3.4.1](https://github.com/aomex/aomex/compare/v3.4.0...v3.4.1) (2024-10-06)
549
+
550
+ **Note:** Version bump only for package @aomex/http-logger
551
+
552
+
553
+
554
+
555
+
556
+ # [3.4.0](https://github.com/aomex/aomex/compare/v3.3.0...v3.4.0) (2024-10-04)
557
+
558
+ **Note:** Version bump only for package @aomex/http-logger
559
+
560
+
561
+
562
+
563
+
564
+ # [3.3.0](https://github.com/aomex/aomex/compare/v3.2.4...v3.3.0) (2024-09-26)
565
+
566
+ **Note:** Version bump only for package @aomex/http-logger
567
+
568
+
569
+
570
+
571
+
572
+ ## [3.2.4](https://github.com/aomex/aomex/compare/v3.2.3...v3.2.4) (2024-09-25)
573
+
574
+ **Note:** Version bump only for package @aomex/http-logger
575
+
576
+
577
+
578
+
579
+
580
+ ## [3.2.3](https://github.com/aomex/aomex/compare/v3.2.2...v3.2.3) (2024-09-25)
581
+
582
+ **Note:** Version bump only for package @aomex/http-logger
583
+
584
+
585
+
586
+
587
+
588
+ ## [3.2.2](https://github.com/aomex/aomex/compare/v3.2.1...v3.2.2) (2024-09-19)
589
+
590
+ **Note:** Version bump only for package @aomex/http-logger
591
+
592
+
593
+
594
+
595
+
596
+ ## [3.2.1](https://github.com/aomex/aomex/compare/v3.2.0...v3.2.1) (2024-09-17)
597
+
598
+ **Note:** Version bump only for package @aomex/http-logger
599
+
600
+
601
+
602
+
603
+
604
+ # [3.2.0](https://github.com/aomex/aomex/compare/v3.1.1...v3.2.0) (2024-09-17)
605
+
606
+ **Note:** Version bump only for package @aomex/http-logger
607
+
608
+
609
+
610
+
611
+
612
+ ## [3.1.1](https://github.com/aomex/aomex/compare/v3.1.0...v3.1.1) (2024-09-13)
613
+
614
+ **Note:** Version bump only for package @aomex/http-logger
615
+
616
+
617
+
618
+
619
+
620
+ # [3.1.0](https://github.com/aomex/aomex/compare/v3.0.0...v3.1.0) (2024-09-13)
621
+
622
+
623
+ ### Bug Fixes
624
+
625
+ * update peer deps ([98b7c10](https://github.com/aomex/aomex/commit/98b7c10068a3c62a0361b1b43a86728a7d445ab5))
626
+
627
+
628
+
629
+
630
+
631
+
632
+
633
+ # [2.2.0](https://github.com/aomex/aomex/compare/v2.1.0...v2.2.0) (2024-08-05)
634
+
635
+ **Note:** Version bump only for package @aomex/http-logger
636
+
637
+
638
+
639
+
640
+
641
+ # [2.1.0](https://github.com/aomex/aomex/compare/v2.0.2...v2.1.0) (2024-07-28)
642
+
643
+ **Note:** Version bump only for package @aomex/http-logger
644
+
645
+
646
+
647
+
648
+
649
+ ## [2.0.2](https://github.com/aomex/aomex/compare/v2.0.1...v2.0.2) (2024-07-27)
650
+
651
+ **Note:** Version bump only for package @aomex/http-logger
652
+
653
+
654
+
655
+
656
+
657
+ ## [2.0.1](https://github.com/aomex/aomex/compare/v2.0.0...v2.0.1) (2024-07-26)
658
+
659
+
660
+ ### Bug Fixes
661
+
662
+ * 未更新peerDependencies ([0492453](https://github.com/aomex/aomex/commit/0492453d5a748aa6dd2047622a19a86dc7b6036e))
663
+
664
+
665
+
666
+
667
+
668
+ # [2.0.0](https://github.com/aomex/aomex/compare/v1.7.0...v2.0.0) (2024-07-26)
669
+
670
+ **Note:** Version bump only for package @aomex/http-logger
671
+
672
+
673
+
674
+
675
+
676
+ # [1.7.0](https://github.com/aomex/aomex/compare/v1.6.0...v1.7.0) (2024-07-13)
677
+
678
+ **Note:** Version bump only for package @aomex/http-logger
679
+
680
+
681
+
682
+
683
+
684
+ # [1.6.0](https://github.com/aomex/aomex/compare/v1.5.1...v1.6.0) (2024-07-05)
685
+
686
+ **Note:** Version bump only for package @aomex/http-logger
687
+
688
+
689
+
690
+
691
+
692
+ ## [1.5.1](https://github.com/aomex/aomex/compare/v1.5.0...v1.5.1) (2024-07-04)
693
+
694
+ **Note:** Version bump only for package @aomex/http-logger
695
+
696
+
697
+
698
+
699
+
700
+ # [1.5.0](https://github.com/aomex/aomex/compare/v1.4.0...v1.5.0) (2024-07-04)
701
+
702
+ **Note:** Version bump only for package @aomex/http-logger
703
+
704
+
705
+
706
+
707
+
708
+ # [1.4.0](https://github.com/aomex/aomex/compare/v1.3.0...v1.4.0) (2024-06-29)
709
+
710
+ **Note:** Version bump only for package @aomex/http-logger
711
+
712
+
713
+
714
+
715
+
716
+ # [1.3.0](https://github.com/aomex/aomex/compare/v1.2.0...v1.3.0) (2024-06-28)
717
+
718
+
719
+ ### Features
720
+
721
+ * **core:** 删除中间件链条概念 ([12f42e6](https://github.com/aomex/aomex/commit/12f42e6ba15f3118b98f5ff31832121b1b2b9896))
722
+
723
+
724
+
725
+
726
+
727
+ # [1.2.0](https://github.com/aomex/aomex/compare/v1.1.0...v1.2.0) (2024-06-27)
728
+
729
+ **Note:** Version bump only for package @aomex/http-logger
730
+
731
+
732
+
733
+
734
+
735
+ # 1.1.0 (2024-06-27)
736
+
737
+
738
+ ### Features
739
+
740
+ * 初始化 ([3350159](https://github.com/aomex/aomex/commit/3350159454ad230e6d910405f907293b059b1f49))
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-2024 geekact
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,3 @@
1
- # Temporary Holding Version
1
+ # @aomex/access-log
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 文档:https://aomex.js.org
@@ -0,0 +1,43 @@
1
+ import { Transport } from "@aomex/logger";
2
+ import { WebContext, WebMiddleware } from "@aomex/web";
3
+ export interface HttpAccessLogOptions {
4
+ /**
5
+ * 是否禁用请求日志。默认:`false`
6
+ */
7
+ disabled?: boolean;
8
+ /**
9
+ * 响应输出格式,建议使用 **HttpAccessLogToken** 拼接。默认值:`[ip] [method] [url] [statusCode] [duration] [contentLength]`
10
+ */
11
+ format?: string;
12
+ /**
13
+ * 日志输出端口。默认使用 `ConsoleTransport`;传空数组相当于禁用。
14
+ */
15
+ transports?: Transport[];
16
+ /**
17
+ * 自定义关键词
18
+ * ```
19
+ * httpAccessLog({
20
+ * format: ' [request] [time] [href]',
21
+ * customTokens: {
22
+ * href: (ctx) => ctx.request.href,
23
+ * },
24
+ * })
25
+ * ```
26
+ */
27
+ customTokens?: {
28
+ [key: string]: (ctx: WebContext) => string | Promise<string>;
29
+ };
30
+ }
31
+ /**
32
+ * HTTP 访问日志。挂在 `WebApp.mount` 里。
33
+ */
34
+ export declare const httpAccessLog: (options?: HttpAccessLogOptions) => WebMiddleware;
35
+ export declare enum HttpAccessLogToken {
36
+ method = "[method]",
37
+ url = "[url]",
38
+ statusCode = "[statusCode]",
39
+ contentLength = "[contentLength]",
40
+ contentType = "[contentType]",
41
+ duration = "[duration]",
42
+ ip = "[ip]"
43
+ }
package/dist/index.js ADDED
@@ -0,0 +1,125 @@
1
+ import { middleware } from "@aomex/common";
2
+ import { BaseLoggerService, ConsoleTransport } from "@aomex/logger";
3
+ import stream from "node:stream";
4
+ import prettyTime from "pretty-time";
5
+ import { bytes } from "@aomex/internal-tools";
6
+ import { statuses } from "@aomex/web";
7
+ import { styleText } from "node:util";
8
+ // src/http-access-log-token.ts
9
+ let HttpAccessLogToken = /* @__PURE__ */ function(HttpAccessLogToken) {
10
+ HttpAccessLogToken["method"] = "[method]";
11
+ HttpAccessLogToken["url"] = "[url]";
12
+ HttpAccessLogToken["statusCode"] = "[statusCode]";
13
+ HttpAccessLogToken["contentLength"] = "[contentLength]";
14
+ HttpAccessLogToken["contentType"] = "[contentType]";
15
+ HttpAccessLogToken["duration"] = "[duration]";
16
+ HttpAccessLogToken["ip"] = "[ip]";
17
+ return HttpAccessLogToken;
18
+ }({});
19
+ // src/counter.ts
20
+ var Counter = class extends stream.Transform {
21
+ length = 0;
22
+ _transform(chunk, _encoding, callback) {
23
+ this.length += chunk.length;
24
+ this.push(chunk);
25
+ callback();
26
+ }
27
+ };
28
+ // src/replace-token.ts
29
+ const colorCodes = {
30
+ 7: "magenta",
31
+ 5: "red",
32
+ 4: "yellow",
33
+ 3: "cyan",
34
+ 2: "green",
35
+ 1: "green",
36
+ 0: "yellow"
37
+ };
38
+ const pattern = /\[[^\[\]]+\]/g;
39
+ const replaceToken = async (opts) => {
40
+ const { message, startTime, request, response = {}, tokens = {} } = opts;
41
+ const { method, url } = request;
42
+ const { contentLength, contentType = "-", statusCode = 404 } = response;
43
+ let formatted = message;
44
+ for (let match of message.matchAll(pattern)) {
45
+ const tokenWithBrackets = match[0];
46
+ const token = tokenWithBrackets.slice(1, -1);
47
+ const replace = (data) => {
48
+ formatted = formatted.replaceAll(tokenWithBrackets, data);
49
+ };
50
+ if (tokens[token]) replace(await tokens[token]());
51
+ switch (`[${token}]`) {
52
+ case "[method]":
53
+ replace(styleText("bold", method));
54
+ break;
55
+ case "[url]":
56
+ replace(styleText("gray", url));
57
+ break;
58
+ case "[statusCode]":
59
+ const c = colorCodes[statusCode / 100 | 0] || colorCodes[0];
60
+ replace(styleText(c, statusCode.toString()));
61
+ break;
62
+ case "[contentLength]":
63
+ replace(styleText("gray", statuses.empty[statusCode] || contentLength === 0 ? "0" : contentLength == null ? "-" : bytes(contentLength).toLowerCase()));
64
+ break;
65
+ case "[contentType]":
66
+ replace(styleText("gray", contentType));
67
+ break;
68
+ case "[duration]":
69
+ replace(styleText("gray", prettyTime(process.hrtime(startTime))));
70
+ break;
71
+ case "[ip]": replace(styleText("gray", request.ip));
72
+ }
73
+ }
74
+ return formatted;
75
+ };
76
+ // src/http-access-log.ts
77
+ var HttpAccessLogService = class extends BaseLoggerService {
78
+ entries;
79
+ constructor(entries) {
80
+ super();
81
+ this.entries = entries;
82
+ }
83
+ createTransports() {
84
+ return this.entries;
85
+ }
86
+ };
87
+ /**
88
+ * HTTP 访问日志。挂在 `WebApp.mount` 里。
89
+ */
90
+ const httpAccessLog = (options = {}) => {
91
+ const { disabled = false, customTokens } = options;
92
+ const format = options.format || `[ip] [method] [url] [statusCode] [duration] [contentLength]`;
93
+ const transportList = options.transports ?? [new ConsoleTransport()];
94
+ const logger = new HttpAccessLogService(transportList.map((transport) => ({ transport })));
95
+ return middleware.web(async (ctx, next) => {
96
+ if (disabled || transportList.length === 0) return next();
97
+ const start = process.hrtime();
98
+ const tokens = customTokens ? Object.fromEntries(Object.entries(customTokens).map(([key, value]) => {
99
+ return [key, value.bind(null, ctx)];
100
+ })) : {};
101
+ try {
102
+ await next();
103
+ } finally {
104
+ const { response, response: { body } } = ctx;
105
+ let counter;
106
+ if (body instanceof stream.Readable && body.readable) ctx.send(body.pipe(counter = new Counter()));
107
+ response.once("close", async () => {
108
+ logger.info(await replaceToken({
109
+ message: format,
110
+ tokens,
111
+ startTime: start,
112
+ request: ctx.request,
113
+ response: {
114
+ statusCode: response.statusCode,
115
+ contentType: response.contentType,
116
+ contentLength: counter ? counter.length : response.contentLength
117
+ }
118
+ }));
119
+ });
120
+ }
121
+ });
122
+ };
123
+ export { HttpAccessLogToken, httpAccessLog };
124
+
125
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/http-access-log-token.ts","../src/counter.ts","../src/replace-token.ts","../src/http-access-log.ts"],"sourcesContent":["export enum HttpAccessLogToken {\n method = '[method]',\n url = '[url]',\n statusCode = '[statusCode]',\n contentLength = '[contentLength]',\n contentType = '[contentType]',\n duration = '[duration]',\n ip = '[ip]',\n}\n","import stream, { type TransformCallback } from 'node:stream';\n\nexport class Counter extends stream.Transform {\n public length: number = 0;\n\n override _transform(\n chunk: any,\n _encoding: BufferEncoding,\n callback: TransformCallback,\n ): void {\n this.length += chunk.length;\n this.push(chunk);\n callback();\n }\n}\n","import prettyTime from 'pretty-time';\nimport { bytes } from '@aomex/internal-tools';\nimport { statuses } from '@aomex/web';\nimport { HttpAccessLogToken } from './http-access-log-token';\nimport { styleText } from 'node:util';\n\nexport const colorCodes = <const>{\n 7: 'magenta',\n 5: 'red',\n 4: 'yellow',\n 3: 'cyan',\n 2: 'green',\n 1: 'green',\n 0: 'yellow',\n};\n\nconst pattern = /\\[[^\\[\\]]+\\]/g;\n\nexport const replaceToken = async (opts: {\n message: string;\n startTime: [number, number];\n tokens?: { [key: string]: () => string | Promise<string> };\n request: {\n method: string;\n url: string;\n ip: string;\n };\n response?: {\n statusCode?: number;\n contentType?: string;\n contentLength?: number;\n };\n}): Promise<string> => {\n const { message, startTime, request, response = {}, tokens = {} } = opts;\n const { method, url } = request;\n const { contentLength, contentType = '-', statusCode = 404 } = response;\n let formatted = message;\n\n for (let match of message.matchAll(pattern)) {\n const tokenWithBrackets = match[0];\n const token = tokenWithBrackets.slice(1, -1);\n\n const replace = (data: string) => {\n formatted = formatted.replaceAll(tokenWithBrackets, data);\n };\n\n if (tokens[token]) {\n replace(await tokens[token]!());\n }\n\n switch (`[${token}]`) {\n case HttpAccessLogToken.method:\n replace(styleText('bold', method));\n break;\n case HttpAccessLogToken.url:\n replace(styleText('gray', url));\n break;\n case HttpAccessLogToken.statusCode:\n const c =\n colorCodes[((statusCode / 100) | 0) as keyof typeof colorCodes] ||\n colorCodes[0]!;\n replace(styleText(c, statusCode.toString()));\n break;\n case HttpAccessLogToken.contentLength:\n replace(\n styleText(\n 'gray',\n statuses.empty[statusCode] || contentLength === 0\n ? '0'\n : contentLength == null\n ? '-'\n : bytes(contentLength).toLowerCase(),\n ),\n );\n break;\n case HttpAccessLogToken.contentType:\n replace(styleText('gray', contentType));\n break;\n case HttpAccessLogToken.duration:\n replace(styleText('gray', prettyTime(process.hrtime(startTime))));\n break;\n case HttpAccessLogToken.ip:\n replace(styleText('gray', request.ip));\n break;\n }\n }\n\n return formatted;\n};\n","import { middleware } from '@aomex/common';\nimport { BaseLoggerService, ConsoleTransport, type Transport } from '@aomex/logger';\nimport type { WebContext, WebMiddleware } from '@aomex/web';\nimport { HttpAccessLogToken } from './http-access-log-token';\nimport { Counter } from './counter';\nimport stream from 'node:stream';\nimport { replaceToken } from './replace-token';\n\nexport interface HttpAccessLogOptions {\n /**\n * 是否禁用请求日志。默认:`false`\n */\n disabled?: boolean;\n /**\n * 响应输出格式,建议使用 **HttpAccessLogToken** 拼接。默认值:`[ip] [method] [url] [statusCode] [duration] [contentLength]`\n */\n format?: string;\n /**\n * 日志输出端口。默认使用 `ConsoleTransport`;传空数组相当于禁用。\n */\n transports?: Transport[];\n /**\n * 自定义关键词\n * ```\n * httpAccessLog({\n * format: ' [request] [time] [href]',\n * customTokens: {\n * href: (ctx) => ctx.request.href,\n * },\n * })\n * ```\n */\n customTokens?: { [key: string]: (ctx: WebContext) => string | Promise<string> };\n}\n\nclass HttpAccessLogService extends BaseLoggerService {\n constructor(private readonly entries: BaseLoggerService.TransportEntry[]) {\n super();\n }\n\n protected createTransports(): BaseLoggerService.TransportEntry[] {\n return this.entries;\n }\n}\n\n/**\n * HTTP 访问日志。挂在 `WebApp.mount` 里。\n */\nexport const httpAccessLog = (options: HttpAccessLogOptions = {}): WebMiddleware => {\n const { disabled = false, customTokens } = options;\n const format =\n options.format ||\n `${HttpAccessLogToken.ip} ${HttpAccessLogToken.method} ${HttpAccessLogToken.url} ${HttpAccessLogToken.statusCode} ${HttpAccessLogToken.duration} ${HttpAccessLogToken.contentLength}`;\n\n const transportList = options.transports ?? [new ConsoleTransport()];\n\n const logger = new HttpAccessLogService(\n transportList.map((transport) => ({ transport })),\n );\n\n return middleware.web(async (ctx, next) => {\n if (disabled || transportList.length === 0) return next();\n\n const start = process.hrtime();\n const tokens = customTokens\n ? Object.fromEntries(\n Object.entries(customTokens).map(([key, value]) => {\n return [key, value.bind(null, ctx)];\n }),\n )\n : {};\n\n try {\n await next();\n } finally {\n const {\n response,\n response: { body },\n } = ctx;\n let counter: Counter | undefined;\n if (body instanceof stream.Readable && body.readable) {\n ctx.send(body.pipe((counter = new Counter())));\n }\n\n response.once('close', async () => {\n logger.info(\n await replaceToken({\n message: format,\n tokens,\n startTime: start,\n request: ctx.request,\n response: {\n statusCode: response.statusCode,\n contentType: response.contentType,\n contentLength: counter ? counter.length : response.contentLength,\n },\n }),\n );\n });\n }\n });\n};\n"],"mappings":";;;;;;;;AAAA,IAAY,qBAAL,yBAAA,oBAAA;CACL,mBAAA,YAAA;CACA,mBAAA,SAAA;CACA,mBAAA,gBAAA;CACA,mBAAA,mBAAA;CACA,mBAAA,iBAAA;CACA,mBAAA,cAAA;CACA,mBAAA,QAAA;;AACF,EAAA,CAAA,CAAA;;ACNA,IAAa,UAAb,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1
+ import { Transport } from "@aomex/logger";
2
+ import { WebsocketContext } from "@aomex/websocket";
3
+ /** WebSocket 入站访问日志令牌 */
4
+ export declare enum WebsocketAccessLogToken {
5
+ ip = "[ip]",
6
+ clientId = "[clientId]",
7
+ event = "[event]",
8
+ duration = "[duration]"
9
+ }
10
+ export interface WebsocketAccessLogOptions {
11
+ /**
12
+ * 是否禁用入站日志。默认:`false`
13
+ */
14
+ disabled?: boolean;
15
+ /**
16
+ * 输出格式,建议使用 **WebsocketAccessLogToken** 拼接。
17
+ * 默认:`[ip] [clientId] [event] [duration]`
18
+ */
19
+ format?: string;
20
+ /**
21
+ * 日志输出端口。默认使用 `ConsoleTransport`;传空数组相当于禁用。
22
+ */
23
+ transports?: Transport[];
24
+ /**
25
+ * 自定义关键词
26
+ * ```
27
+ * websocketAccessLog({
28
+ * format: '[event] [room]',
29
+ * customTokens: {
30
+ * room: (ctx) => String(ctx.client.data['room'] ?? '-'),
31
+ * },
32
+ * })
33
+ * ```
34
+ */
35
+ customTokens?: {
36
+ [key: string]: (ctx: WebsocketContext) => string | Promise<string>;
37
+ };
38
+ }
39
+ /**
40
+ * 入站消息访问日志。挂在 `WebsocketApp.mount` 里、`channels()` 前面。
41
+ * 每条入站消息在中间件链结束后打一条日志(含抛错路径)。
42
+ *
43
+ * ```ts
44
+ * import { websocketAccessLog } from '@aomex/access-log/websocket';
45
+ * import { WebsocketApp, channels } from '@aomex/websocket';
46
+ *
47
+ * new WebsocketApp({
48
+ * logger,
49
+ * language,
50
+ * transport,
51
+ * mount: [websocketAccessLog(), channels('./src/channels')],
52
+ * });
53
+ * ```
54
+ */
55
+ export declare const websocketAccessLog: (options?: WebsocketAccessLogOptions) => import("@aomex/websocket").SocketMiddleware<object>;
@@ -0,0 +1,98 @@
1
+ import { middleware } from "@aomex/common";
2
+ import { BaseLoggerService, ConsoleTransport } from "@aomex/logger";
3
+ import prettyTime from "pretty-time";
4
+ import { styleText } from "node:util";
5
+ import "@aomex/websocket";
6
+ // src/websocket-token.ts
7
+ /** WebSocket 入站访问日志令牌 */
8
+ let WebsocketAccessLogToken = /* @__PURE__ */ function(WebsocketAccessLogToken) {
9
+ WebsocketAccessLogToken["ip"] = "[ip]";
10
+ WebsocketAccessLogToken["clientId"] = "[clientId]";
11
+ WebsocketAccessLogToken["event"] = "[event]";
12
+ WebsocketAccessLogToken["duration"] = "[duration]";
13
+ return WebsocketAccessLogToken;
14
+ }({});
15
+ // src/replace-websocket-token.ts
16
+ const pattern = /\[[^\[\]]+\]/g;
17
+ const replaceWebsocketToken = async (opts) => {
18
+ const { message, startTime, tokens = {}, ip, clientId, event } = opts;
19
+ let formatted = message;
20
+ for (const match of message.matchAll(pattern)) {
21
+ const tokenWithBrackets = match[0];
22
+ const token = tokenWithBrackets.slice(1, -1);
23
+ const replace = (data) => {
24
+ formatted = formatted.replaceAll(tokenWithBrackets, data);
25
+ };
26
+ if (tokens[token]) replace(await tokens[token]());
27
+ switch (`[${token}]`) {
28
+ case "[ip]":
29
+ replace(styleText("gray", ip || "-"));
30
+ break;
31
+ case "[clientId]":
32
+ replace(styleText("gray", clientId));
33
+ break;
34
+ case "[event]":
35
+ replace(styleText("bold", event));
36
+ break;
37
+ case "[duration]": replace(styleText("gray", prettyTime(process.hrtime(startTime))));
38
+ }
39
+ }
40
+ return formatted;
41
+ };
42
+ // src/websocket.ts
43
+ var WebsocketAccessLogService = class extends BaseLoggerService {
44
+ entries;
45
+ constructor(entries) {
46
+ super();
47
+ this.entries = entries;
48
+ }
49
+ createTransports() {
50
+ return this.entries;
51
+ }
52
+ };
53
+ /**
54
+ * 入站消息访问日志。挂在 `WebsocketApp.mount` 里、`channels()` 前面。
55
+ * 每条入站消息在中间件链结束后打一条日志(含抛错路径)。
56
+ *
57
+ * ```ts
58
+ * import { websocketAccessLog } from '@aomex/access-log/websocket';
59
+ * import { WebsocketApp, channels } from '@aomex/websocket';
60
+ *
61
+ * new WebsocketApp({
62
+ * logger,
63
+ * language,
64
+ * transport,
65
+ * mount: [websocketAccessLog(), channels('./src/channels')],
66
+ * });
67
+ * ```
68
+ */
69
+ const websocketAccessLog = (options = {}) => {
70
+ const { disabled = false, customTokens } = options;
71
+ const format = options.format || `[ip] [clientId] [event] [duration]`;
72
+ const transportList = options.transports ?? [new ConsoleTransport()];
73
+ const logger = new WebsocketAccessLogService(transportList.map((transport) => ({ transport })));
74
+ return middleware.socket(async (ctx, next) => {
75
+ if (disabled || transportList.length === 0) return next();
76
+ const start = process.hrtime();
77
+ const tokens = customTokens ? Object.fromEntries(Object.entries(customTokens).map(([key, value]) => {
78
+ return [key, value.bind(null, ctx)];
79
+ })) : {};
80
+ try {
81
+ await next();
82
+ } finally {
83
+ try {
84
+ logger.info(await replaceWebsocketToken({
85
+ message: format,
86
+ tokens,
87
+ startTime: start,
88
+ ip: ctx.client.request.ip,
89
+ clientId: ctx.client.id,
90
+ event: ctx.event
91
+ }));
92
+ } catch {}
93
+ }
94
+ });
95
+ };
96
+ export { WebsocketAccessLogToken, websocketAccessLog };
97
+
98
+ //# sourceMappingURL=websocket.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket.js","names":[],"sources":["../src/websocket-token.ts","../src/replace-websocket-token.ts","../src/websocket.ts"],"sourcesContent":["/** WebSocket 入站访问日志令牌 */\nexport enum WebsocketAccessLogToken {\n ip = '[ip]',\n clientId = '[clientId]',\n event = '[event]',\n duration = '[duration]',\n}\n","import prettyTime from 'pretty-time';\nimport { styleText } from 'node:util';\nimport { WebsocketAccessLogToken } from './websocket-token';\n\nconst pattern = /\\[[^\\[\\]]+\\]/g;\n\nexport const replaceWebsocketToken = async (opts: {\n message: string;\n startTime: [number, number];\n tokens?: { [key: string]: () => string | Promise<string> };\n ip: string;\n clientId: string;\n event: string;\n}): Promise<string> => {\n const { message, startTime, tokens = {}, ip, clientId, event } = opts;\n let formatted = message;\n\n for (const match of message.matchAll(pattern)) {\n const tokenWithBrackets = match[0]!;\n const token = tokenWithBrackets.slice(1, -1);\n\n const replace = (data: string) => {\n formatted = formatted.replaceAll(tokenWithBrackets, data);\n };\n\n if (tokens[token]) {\n replace(await tokens[token]!());\n }\n\n switch (`[${token}]`) {\n case WebsocketAccessLogToken.ip:\n replace(styleText('gray', ip || '-'));\n break;\n case WebsocketAccessLogToken.clientId:\n replace(styleText('gray', clientId));\n break;\n case WebsocketAccessLogToken.event:\n replace(styleText('bold', event));\n break;\n case WebsocketAccessLogToken.duration:\n replace(styleText('gray', prettyTime(process.hrtime(startTime))));\n break;\n }\n }\n\n return formatted;\n};\n","import '@aomex/websocket';\nimport type { WebsocketContext } from '@aomex/websocket';\nimport { middleware } from '@aomex/common';\nimport { BaseLoggerService, ConsoleTransport, type Transport } from '@aomex/logger';\nimport { replaceWebsocketToken } from './replace-websocket-token';\nimport { WebsocketAccessLogToken } from './websocket-token';\n\nexport interface WebsocketAccessLogOptions {\n /**\n * 是否禁用入站日志。默认:`false`\n */\n disabled?: boolean;\n /**\n * 输出格式,建议使用 **WebsocketAccessLogToken** 拼接。\n * 默认:`[ip] [clientId] [event] [duration]`\n */\n format?: string;\n /**\n * 日志输出端口。默认使用 `ConsoleTransport`;传空数组相当于禁用。\n */\n transports?: Transport[];\n /**\n * 自定义关键词\n * ```\n * websocketAccessLog({\n * format: '[event] [room]',\n * customTokens: {\n * room: (ctx) => String(ctx.client.data['room'] ?? '-'),\n * },\n * })\n * ```\n */\n customTokens?: {\n [key: string]: (ctx: WebsocketContext) => string | Promise<string>;\n };\n}\n\nclass WebsocketAccessLogService extends BaseLoggerService {\n constructor(private readonly entries: BaseLoggerService.TransportEntry[]) {\n super();\n }\n\n protected createTransports(): BaseLoggerService.TransportEntry[] {\n return this.entries;\n }\n}\n\n/**\n * 入站消息访问日志。挂在 `WebsocketApp.mount` 里、`channels()` 前面。\n * 每条入站消息在中间件链结束后打一条日志(含抛错路径)。\n *\n * ```ts\n * import { websocketAccessLog } from '@aomex/access-log/websocket';\n * import { WebsocketApp, channels } from '@aomex/websocket';\n *\n * new WebsocketApp({\n * logger,\n * language,\n * transport,\n * mount: [websocketAccessLog(), channels('./src/channels')],\n * });\n * ```\n */\nexport const websocketAccessLog = (options: WebsocketAccessLogOptions = {}) => {\n const { disabled = false, customTokens } = options;\n const format =\n options.format ||\n `${WebsocketAccessLogToken.ip} ${WebsocketAccessLogToken.clientId} ${WebsocketAccessLogToken.event} ${WebsocketAccessLogToken.duration}`;\n\n const transportList = options.transports ?? [new ConsoleTransport()];\n\n const logger = new WebsocketAccessLogService(\n transportList.map((transport) => ({ transport })),\n );\n\n return middleware.socket(async (ctx, next) => {\n if (disabled || transportList.length === 0) return next();\n\n const start = process.hrtime();\n const tokens = customTokens\n ? Object.fromEntries(\n Object.entries(customTokens).map(([key, value]) => {\n return [key, value.bind(null, ctx)];\n }),\n )\n : {};\n\n try {\n await next();\n } finally {\n // 打日志失败不得掩盖 next() 的业务异常\n try {\n logger.info(\n await replaceWebsocketToken({\n message: format,\n tokens,\n startTime: start,\n ip: ctx.client.request.ip,\n clientId: ctx.client.id,\n event: ctx.event,\n }),\n );\n } catch {\n // 访问日志失败静默忽略\n }\n }\n });\n};\n\nexport { WebsocketAccessLogToken } from './websocket-token';\n"],"mappings":";;;;;;;AACA,IAAY,0BAAL,yBAAA,yBAAA;CACL,wBAAA,QAAA;CACA,wBAAA,cAAA;CACA,wBAAA,WAAA;CACA,wBAAA,cAAA;;AACF,EAAA,CAAA,CAAA;;ACFA,MAAM,UAAU;AAEhB,MAAa,wBAAwB,OAAO,SAOrB;CACrB,MAAM,EAAE,SAAS,WAAW,SAAS,CAAC,GAAG,IAAI,UAAU,UAAU;CACjE,IAAI,YAAY;CAEhB,KAAK,MAAM,SAAS,QAAQ,SAAS,OAAO,GAAG;EAC7C,MAAM,oBAAoB,MAAM;EAChC,MAAM,QAAQ,kBAAkB,MAAM,GAAG,EAAE;EAE3C,MAAM,WAAW,SAAiB;GAChC,YAAY,UAAU,WAAW,mBAAmB,IAAI;EAC1D;EAEA,IAAI,OAAO,QACT,QAAQ,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b,CAAC,CACH;GACF,QAAQ,CAER;EACF;CACF,CAAC;AACH"}
package/package.json CHANGED
@@ -1,6 +1,59 @@
1
1
  {
2
2
  "name": "@aomex/access-log",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "4.5.0",
4
+ "description": "访问日志",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git@github.com:aomex/aomex.git"
8
+ },
9
+ "homepage": "https://aomex.js.org",
10
+ "license": "MIT",
11
+ "type": "module",
12
+ "sideEffects": [
13
+ "./dist/websocket.js"
14
+ ],
15
+ "types": "dist/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "import": "./dist/index.js"
20
+ },
21
+ "./websocket": {
22
+ "types": "./dist/websocket.d.ts",
23
+ "import": "./dist/websocket.js"
24
+ },
25
+ "./package.json": "./package.json"
26
+ },
27
+ "files": [
28
+ "dist",
29
+ "LICENSE",
30
+ "package.json",
31
+ "README.md",
32
+ "CHANGELOG.md"
33
+ ],
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "peerDependencies": {
38
+ "@aomex/common": "^4.0.0",
39
+ "@aomex/web": "^4.0.0",
40
+ "@aomex/websocket": "^4.0.0"
41
+ },
42
+ "peerDependenciesMeta": {
43
+ "@aomex/websocket": {
44
+ "optional": true
45
+ }
46
+ },
47
+ "dependencies": {
48
+ "@aomex/internal-tools": "4.5.0",
49
+ "@aomex/logger": "4.5.0",
50
+ "pretty-time": "^1.1.0"
51
+ },
52
+ "devDependencies": {
53
+ "@aomex/common": "4.5.0",
54
+ "@aomex/web": "4.5.0",
55
+ "@aomex/websocket": "4.5.0",
56
+ "@types/pretty-time": "^1.1.5"
57
+ },
58
+ "scripts": {}
6
59
  }