loglyn 0.0.1
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 +163 -0
- package/client/dist/assets/index-4cmYap6R.js +1 -0
- package/client/dist/assets/index-B2J1zNAH.css +2 -0
- package/client/dist/favicon.ico +0 -0
- package/client/dist/icon.png +0 -0
- package/client/dist/index.html +18 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/nest-logs/index.d.ts +3 -0
- package/dist/nest-logs/index.js +8 -0
- package/dist/nest-logs/index.js.map +1 -0
- package/dist/nest-logs/nest-logs.controller.d.ts +39 -0
- package/dist/nest-logs/nest-logs.controller.js +307 -0
- package/dist/nest-logs/nest-logs.controller.js.map +1 -0
- package/dist/nest-logs/nest-logs.interfaces.d.ts +44 -0
- package/dist/nest-logs/nest-logs.interfaces.js +3 -0
- package/dist/nest-logs/nest-logs.interfaces.js.map +1 -0
- package/dist/nest-logs/nest-logs.logger.d.ts +27 -0
- package/dist/nest-logs/nest-logs.logger.js +162 -0
- package/dist/nest-logs/nest-logs.logger.js.map +1 -0
- package/dist/nest-logs/nest-logs.middleware.d.ts +15 -0
- package/dist/nest-logs/nest-logs.middleware.js +121 -0
- package/dist/nest-logs/nest-logs.middleware.js.map +1 -0
- package/dist/nest-logs/nest-logs.module.d.ts +6 -0
- package/dist/nest-logs/nest-logs.module.js +38 -0
- package/dist/nest-logs/nest-logs.module.js.map +1 -0
- package/package.json +97 -0
package/README.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# loglyn
|
|
2
|
+
|
|
3
|
+
Production runtime logs for NestJS with an embedded dashboard.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install loglyn
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Setup
|
|
12
|
+
|
|
13
|
+
Register the module:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { Module } from '@nestjs/common';
|
|
17
|
+
import { NestLogsModule } from 'loglyn';
|
|
18
|
+
|
|
19
|
+
@Module({
|
|
20
|
+
imports: [
|
|
21
|
+
NestLogsModule.register({
|
|
22
|
+
timezone: 'Asia/Jakarta',
|
|
23
|
+
path: '/nest-logs',
|
|
24
|
+
title: 'Production Logs',
|
|
25
|
+
maxLogs: 1000,
|
|
26
|
+
storagePath: './logs',
|
|
27
|
+
retentionDays: 30,
|
|
28
|
+
password: process.env.NEST_LOGS_PASSWORD,
|
|
29
|
+
captureRequests: true,
|
|
30
|
+
}),
|
|
31
|
+
],
|
|
32
|
+
})
|
|
33
|
+
export class AppModule {}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Use it as the Nest logger:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { NestFactory } from '@nestjs/core';
|
|
40
|
+
import { AppModule } from './app.module';
|
|
41
|
+
import { NestLogsLogger } from 'loglyn';
|
|
42
|
+
|
|
43
|
+
const bootstrap = async () => {
|
|
44
|
+
const app = await NestFactory.create(AppModule, { bufferLogs: true });
|
|
45
|
+
app.useLogger(app.get(NestLogsLogger));
|
|
46
|
+
await app.listen(process.env.PORT ?? 3000);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
void bootstrap();
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Open `http://localhost:3000/nest-logs`.
|
|
53
|
+
|
|
54
|
+
## Options
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
NestLogsModule.register({
|
|
58
|
+
timezone: 'Asia/Jakarta',
|
|
59
|
+
path: '/nest-logs',
|
|
60
|
+
title: 'Production Logs',
|
|
61
|
+
maxLogs: 1000,
|
|
62
|
+
storagePath: './logs',
|
|
63
|
+
retentionDays: 30,
|
|
64
|
+
password: process.env.NEST_LOGS_PASSWORD,
|
|
65
|
+
sessionTtlMs: 1000 * 60 * 60 * 8,
|
|
66
|
+
captureRequests: true,
|
|
67
|
+
captureRequestBody: false,
|
|
68
|
+
captureResponseBody: false,
|
|
69
|
+
maxBodySize: 4096,
|
|
70
|
+
redact: ['authorization', 'cookie', 'set-cookie', 'password', 'token'],
|
|
71
|
+
})
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
| Option | Type | Default | Description |
|
|
75
|
+
| --- | --- | --- | --- |
|
|
76
|
+
| `timezone` | `string` | required | Timezone for daily log filenames and retention. Example: `Asia/Jakarta`. |
|
|
77
|
+
| `path` | `string` | `/nest-logs` | Dashboard and API base path. Example: `/logs` opens the dashboard at `http://localhost:3000/logs`. |
|
|
78
|
+
| `title` | `string` | `loglyn` | Dashboard and browser tab title. |
|
|
79
|
+
| `maxLogs` | `number` | `1000` | Maximum in-memory logs kept for realtime dashboard history. Older logs are removed from memory first. |
|
|
80
|
+
| `storagePath` | `string` | none | Folder for daily `.jsonl` files. Example: `./logs` writes `logs/YYYY-MM-DD.jsonl`. Leave empty to disable file storage. |
|
|
81
|
+
| `retentionDays` | `number` | none | How many days of `.jsonl` files to keep when `storagePath` is enabled. Leave empty to never delete log files automatically. |
|
|
82
|
+
| `password` | `string` | none | Optional dashboard password. Users see a password screen before opening logs. |
|
|
83
|
+
| `token` | `string` | none | Optional dashboard/API access token. Leave empty only for local development. |
|
|
84
|
+
| `sessionTtlMs` | `number` | 8 hours | Dashboard session token lifetime after login. |
|
|
85
|
+
| `captureRequests` | `boolean` | `false` | Capture HTTP requests automatically without manual `Logger` calls. |
|
|
86
|
+
| `captureRequestBody` | `boolean` | `false` | Capture parsed request body. Keep disabled unless needed because bodies can contain secrets. |
|
|
87
|
+
| `captureResponseBody` | `boolean` | `false` | Reserved for response body capture. Disabled by default. |
|
|
88
|
+
| `maxBodySize` | `number` | `4096` | Maximum serialized size for captured request data before truncation. |
|
|
89
|
+
| `redact` | `string[]` | sensitive defaults | Extra keys to hide from headers, query, and body. Case-insensitive. |
|
|
90
|
+
|
|
91
|
+
If `storagePath` is set, logs are appended as daily JSONL files.
|
|
92
|
+
|
|
93
|
+
When the app starts, today's JSONL file is loaded back into the in-memory buffer, then realtime logs are merged into the same dashboard stream.
|
|
94
|
+
|
|
95
|
+
## Capture HTTP Requests
|
|
96
|
+
|
|
97
|
+
Enable request monitoring:
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
NestLogsModule.register({
|
|
101
|
+
timezone: 'Asia/Jakarta',
|
|
102
|
+
path: '/logs',
|
|
103
|
+
password: process.env.NEST_LOGS_PASSWORD,
|
|
104
|
+
storagePath: './logs',
|
|
105
|
+
captureRequests: true,
|
|
106
|
+
})
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Captured request rows include:
|
|
110
|
+
|
|
111
|
+
- method and path
|
|
112
|
+
- status code
|
|
113
|
+
- duration
|
|
114
|
+
- IP
|
|
115
|
+
- user-agent
|
|
116
|
+
- request headers
|
|
117
|
+
- response headers
|
|
118
|
+
- query
|
|
119
|
+
- request body only when `captureRequestBody` is `true`
|
|
120
|
+
- response body only when `captureResponseBody` is `true`
|
|
121
|
+
|
|
122
|
+
Dashboard routes are skipped automatically, so `/logs/*` will not spam itself.
|
|
123
|
+
|
|
124
|
+
Date range filters fetch historical JSONL files from disk, then merge them with the realtime buffer.
|
|
125
|
+
|
|
126
|
+
Default redacted keys:
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
['authorization', 'cookie', 'set-cookie', 'password', 'token', 'secret', 'api-key', 'x-api-key']
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
For production, keep body capture disabled unless you have a clear debugging need.
|
|
133
|
+
|
|
134
|
+
## API
|
|
135
|
+
|
|
136
|
+
- `GET /nest-logs`
|
|
137
|
+
- `GET /nest-logs/api/logs`
|
|
138
|
+
- `GET /nest-logs/api/dates`
|
|
139
|
+
- `GET /nest-logs/api/stream`
|
|
140
|
+
|
|
141
|
+
Filters for `/api/logs`:
|
|
142
|
+
|
|
143
|
+
- `level`
|
|
144
|
+
- `search`
|
|
145
|
+
- `from`
|
|
146
|
+
- `to`
|
|
147
|
+
- `date`
|
|
148
|
+
|
|
149
|
+
## Security
|
|
150
|
+
|
|
151
|
+
Set `password` before exposing this dashboard outside local development.
|
|
152
|
+
|
|
153
|
+
Dashboard users enter the password in the browser. The dashboard exchanges it for a temporary session token and stores that token in `sessionStorage`.
|
|
154
|
+
|
|
155
|
+
```http
|
|
156
|
+
Authorization: Bearer <session-token>
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
If the token expires or becomes invalid, the dashboard shows the login screen again.
|
|
160
|
+
|
|
161
|
+
## License
|
|
162
|
+
|
|
163
|
+
MIT
|