@johnboxcodes/boxlogger 0.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/CHANGELOG.md +23 -0
- package/LICENSE +21 -0
- package/README.md +248 -0
- package/dist/index.d.ts +607 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1147 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +180 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +389 -0
- package/dist/logger.js.map +1 -0
- package/dist/scope.d.ts +242 -0
- package/dist/scope.d.ts.map +1 -0
- package/dist/scope.js +373 -0
- package/dist/scope.js.map +1 -0
- package/dist/stores/base.d.ts +127 -0
- package/dist/stores/base.d.ts.map +1 -0
- package/dist/stores/base.js +288 -0
- package/dist/stores/base.js.map +1 -0
- package/dist/stores/index.d.ts +12 -0
- package/dist/stores/index.d.ts.map +1 -0
- package/dist/stores/index.js +12 -0
- package/dist/stores/index.js.map +1 -0
- package/dist/stores/memory.d.ts +131 -0
- package/dist/stores/memory.d.ts.map +1 -0
- package/dist/stores/memory.js +284 -0
- package/dist/stores/memory.js.map +1 -0
- package/dist/stores/sqlite.d.ts +204 -0
- package/dist/stores/sqlite.d.ts.map +1 -0
- package/dist/stores/sqlite.js +608 -0
- package/dist/stores/sqlite.js.map +1 -0
- package/dist/types.d.ts +607 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +18 -0
- package/dist/types.js.map +1 -0
- package/package.json +84 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2026-02-02
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Initial release
|
|
12
|
+
- Sentry-compatible API with top 5 functions (captureException, captureMessage, setUser, addBreadcrumb, withScope)
|
|
13
|
+
- SQLite storage provider with persistent logging
|
|
14
|
+
- Memory storage provider for development/testing
|
|
15
|
+
- Session tracking with crash detection
|
|
16
|
+
- Transaction support for performance monitoring
|
|
17
|
+
- Breadcrumb trail for debugging
|
|
18
|
+
- Scoped context with tags and metadata
|
|
19
|
+
- Configurable sampling rates
|
|
20
|
+
- Error filtering with ignoreErrors patterns
|
|
21
|
+
- beforeSend and beforeSendMessage hooks
|
|
22
|
+
- Comprehensive TypeScript types
|
|
23
|
+
- Full test coverage
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 johnbox codes
|
|
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
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
# boxlogger
|
|
2
|
+
|
|
3
|
+
A lightweight, Sentry-compatible backend logger with pluggable storage providers for Node.js applications.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ๐ **Pluggable Storage** - SQLite, Memory, or custom providers
|
|
8
|
+
- ๐ฏ **Sentry-Compatible API** - Drop-in replacement for common Sentry functions
|
|
9
|
+
- ๐ **Session Tracking** - Track user sessions with crash detection
|
|
10
|
+
- ๐ **Transaction Support** - Performance monitoring with custom measurements
|
|
11
|
+
- ๐ **Breadcrumbs** - Event trail for debugging
|
|
12
|
+
- ๐ท๏ธ **Scoped Context** - Isolated logging contexts with tags and metadata
|
|
13
|
+
- ๐พ **Persistent Storage** - SQLite backend for production use
|
|
14
|
+
- ๐งช **Fully Tested** - Comprehensive test coverage
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @johnboxcodes/boxlogger
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
For SQLite support:
|
|
23
|
+
```bash
|
|
24
|
+
npm install @johnboxcodes/boxlogger better-sqlite3
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import * as Sentry from '@johnboxcodes/boxlogger';
|
|
31
|
+
|
|
32
|
+
// Initialize with SQLite
|
|
33
|
+
await Sentry.init('sqlite', {
|
|
34
|
+
filename: './logs.db',
|
|
35
|
+
service: 'my-api',
|
|
36
|
+
environment: 'production'
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Capture errors
|
|
40
|
+
try {
|
|
41
|
+
await riskyOperation();
|
|
42
|
+
} catch (error) {
|
|
43
|
+
Sentry.captureException(error, {
|
|
44
|
+
tags: { section: 'payment' },
|
|
45
|
+
extra: { userId: '123' }
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Log messages
|
|
50
|
+
Sentry.captureMessage('Payment processed', 'info');
|
|
51
|
+
|
|
52
|
+
// Set user context
|
|
53
|
+
Sentry.setUser({ id: '123', email: 'user@example.com' });
|
|
54
|
+
|
|
55
|
+
// Add breadcrumbs
|
|
56
|
+
Sentry.addBreadcrumb({
|
|
57
|
+
category: 'navigation',
|
|
58
|
+
message: 'User navigated to checkout',
|
|
59
|
+
level: 'info'
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Storage Providers
|
|
64
|
+
|
|
65
|
+
### SQLite (Recommended for Production)
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
import * as Sentry from '@johnboxcodes/boxlogger';
|
|
69
|
+
|
|
70
|
+
await Sentry.init('sqlite', {
|
|
71
|
+
filename: './logs.db',
|
|
72
|
+
service: 'my-service',
|
|
73
|
+
environment: 'production',
|
|
74
|
+
minLevel: 'info'
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Memory (Development/Testing)
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
await Sentry.init('memory', {
|
|
82
|
+
service: 'my-service',
|
|
83
|
+
environment: 'development',
|
|
84
|
+
minLevel: 'debug'
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Custom Provider
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import { create } from 'boxlogger';
|
|
92
|
+
import { MyCustomStore } from './my-store';
|
|
93
|
+
|
|
94
|
+
const logger = await create(new MyCustomStore(), {
|
|
95
|
+
service: 'my-service'
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## API Reference
|
|
100
|
+
|
|
101
|
+
### Core Functions
|
|
102
|
+
|
|
103
|
+
#### `init(provider, options)`
|
|
104
|
+
Initialize the logger with a storage provider.
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
await Sentry.init('sqlite', {
|
|
108
|
+
filename: './logs.db',
|
|
109
|
+
service: 'my-api',
|
|
110
|
+
environment: 'production',
|
|
111
|
+
release: '1.0.0',
|
|
112
|
+
minLevel: 'info',
|
|
113
|
+
ignoreErrors: [/NetworkError/],
|
|
114
|
+
sampleRate: 1.0,
|
|
115
|
+
beforeSend: (event) => event
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
#### `captureException(error, context?)`
|
|
120
|
+
Capture and log exceptions with optional context.
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
Sentry.captureException(error, {
|
|
124
|
+
tags: { section: 'api' },
|
|
125
|
+
extra: { endpoint: '/users' },
|
|
126
|
+
level: 'error',
|
|
127
|
+
user: { id: '123' }
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
#### `captureMessage(message, level?)`
|
|
132
|
+
Log custom messages.
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
Sentry.captureMessage('User action completed', 'info');
|
|
136
|
+
Sentry.captureMessage('Warning: High memory usage', {
|
|
137
|
+
level: 'warning',
|
|
138
|
+
tags: { component: 'memory-monitor' }
|
|
139
|
+
});
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
#### `setUser(user)`
|
|
143
|
+
Set user context for all subsequent logs.
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
Sentry.setUser({
|
|
147
|
+
id: '123',
|
|
148
|
+
email: 'user@example.com',
|
|
149
|
+
username: 'john_doe',
|
|
150
|
+
ip_address: '{{auto}}'
|
|
151
|
+
});
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
#### `addBreadcrumb(breadcrumb)`
|
|
155
|
+
Add breadcrumb for event trail.
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
Sentry.addBreadcrumb({
|
|
159
|
+
category: 'http',
|
|
160
|
+
message: 'API request',
|
|
161
|
+
level: 'info',
|
|
162
|
+
data: { url: '/api/users', method: 'GET' }
|
|
163
|
+
});
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
#### `withScope(callback)`
|
|
167
|
+
Execute code with isolated logging context.
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
Sentry.withScope((scope) => {
|
|
171
|
+
scope.setTag('transaction', 'payment');
|
|
172
|
+
scope.setExtra('orderId', '12345');
|
|
173
|
+
Sentry.captureException(error);
|
|
174
|
+
});
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Session Management
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
// Start session
|
|
181
|
+
await Sentry.startSession({ user: { id: '123' } });
|
|
182
|
+
|
|
183
|
+
// End session
|
|
184
|
+
await Sentry.endSession('ended');
|
|
185
|
+
|
|
186
|
+
// Get current session
|
|
187
|
+
const session = Sentry.getCurrentSession();
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Transaction Tracking
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
const transaction = Sentry.startTransaction({
|
|
194
|
+
name: 'payment-processing',
|
|
195
|
+
op: 'payment'
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
transaction.setTag('payment-method', 'credit-card');
|
|
199
|
+
transaction.setMeasurement('amount', 99.99, 'usd');
|
|
200
|
+
transaction.setStatus('ok');
|
|
201
|
+
transaction.finish();
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Query Logs
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
// Get logs with filters
|
|
208
|
+
const logs = await Sentry.getLogs({
|
|
209
|
+
level: 'error',
|
|
210
|
+
startTime: new Date('2024-01-01'),
|
|
211
|
+
limit: 100
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
// Get sessions
|
|
215
|
+
const sessions = await Sentry.getSessions({
|
|
216
|
+
status: 'crashed'
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
// Get statistics
|
|
220
|
+
const stats = await Sentry.getStats();
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## Configuration Options
|
|
224
|
+
|
|
225
|
+
| Option | Type | Default | Description |
|
|
226
|
+
|--------|------|---------|-------------|
|
|
227
|
+
| `service` | `string` | - | Service name |
|
|
228
|
+
| `environment` | `string` | `'production'` | Environment (production, development, etc.) |
|
|
229
|
+
| `release` | `string` | - | Release version |
|
|
230
|
+
| `minLevel` | `LogLevel` | `'info'` | Minimum log level |
|
|
231
|
+
| `ignoreErrors` | `(string\|RegExp)[]` | `[]` | Errors to ignore |
|
|
232
|
+
| `sampleRate` | `number` | `1.0` | Error sampling rate (0-1) |
|
|
233
|
+
| `messagesSampleRate` | `number` | `1.0` | Message sampling rate (0-1) |
|
|
234
|
+
| `beforeSend` | `function` | - | Hook to modify/filter events |
|
|
235
|
+
| `beforeSendMessage` | `function` | - | Hook to modify/filter messages |
|
|
236
|
+
|
|
237
|
+
## Examples
|
|
238
|
+
|
|
239
|
+
See the [examples](./examples) directory for complete examples:
|
|
240
|
+
- [examples/server.ts](./examples/server.ts) - Express server with error tracking
|
|
241
|
+
|
|
242
|
+
## License
|
|
243
|
+
|
|
244
|
+
MIT
|
|
245
|
+
|
|
246
|
+
## Author
|
|
247
|
+
|
|
248
|
+
johnbox codes
|