@remote-logger/sdk 0.1.4 → 0.1.5
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/SKILL.md +25 -10
- package/package.json +1 -1
package/SKILL.md
CHANGED
|
@@ -22,10 +22,34 @@ You should default to placing logs early when investigating runtime issues. Don'
|
|
|
22
22
|
- Correlating behavior across multiple services or processes (use `traceId`)
|
|
23
23
|
- Monitoring a specific code path after a fix to verify it works
|
|
24
24
|
|
|
25
|
+
## Best Practices
|
|
26
|
+
|
|
27
|
+
**Use `withGroup()` to categorize logs — don't embed context in the message.**
|
|
28
|
+
|
|
29
|
+
The `group` field is a queryable column in ClickHouse. When you prefix messages manually, you lose the ability to filter and aggregate by subsystem.
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
// Bad — context is buried in the message string, not queryable
|
|
33
|
+
logger.info("[StorageService] Getting user");
|
|
34
|
+
|
|
35
|
+
// Good — group is a structured, queryable field
|
|
36
|
+
const log = logger.withGroup("StorageService");
|
|
37
|
+
log.info("Getting user");
|
|
38
|
+
|
|
39
|
+
// Also good — inline object form for one-off logs
|
|
40
|
+
logger.info({ message: "Getting user", group: "StorageService" });
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
This lets you later query `WHERE group = 'StorageService'` or `GROUP BY group` to see log volume by subsystem.
|
|
44
|
+
|
|
45
|
+
When placing logs across multiple files or modules during an investigation, create a scoped logger per module so logs are naturally organized. Use `withTraceId()` to correlate logs across a single request or operation, especially across services.
|
|
46
|
+
|
|
25
47
|
## SDK Quick Reference
|
|
26
48
|
|
|
27
49
|
### Setup (already done if the project uses this SDK)
|
|
28
50
|
|
|
51
|
+
**Important:** Look for an existing logger instance in the project before creating a new one. Projects typically have a shared logger in a file like `logger.ts` or `lib/logger.ts` — import from there instead of calling `createLogger()` again.
|
|
52
|
+
|
|
29
53
|
```ts
|
|
30
54
|
import { createLogger } from '@remote-logger/sdk';
|
|
31
55
|
|
|
@@ -49,15 +73,6 @@ logger.error(err as Error, { orderId: order.id }); // Error objects extract sta
|
|
|
49
73
|
logger.fatal(new Error("database unreachable"));
|
|
50
74
|
```
|
|
51
75
|
|
|
52
|
-
### Scoped Loggers (for grouping or tracing)
|
|
53
|
-
|
|
54
|
-
```ts
|
|
55
|
-
const authLogger = logger.withGroup("auth"); // all calls get group: "auth"
|
|
56
|
-
const reqLogger = logger.withTraceId("req-abc"); // all calls get trace_id: "req-abc"
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
Use `group` to categorize logs by subsystem (e.g., "auth", "billing", "renderer"). Use `traceId` to correlate logs across a single request or operation, especially across services.
|
|
60
|
-
|
|
61
76
|
### Console Interception
|
|
62
77
|
|
|
63
78
|
```ts
|
|
@@ -111,7 +126,7 @@ group String -- categorization (e.g., 'api/billing', 'main', 'rendere
|
|
|
111
126
|
message String -- log content
|
|
112
127
|
stack Nullable(String) -- stack trace
|
|
113
128
|
error_type String -- exception class name
|
|
114
|
-
metadata
|
|
129
|
+
metadata JSON -- arbitrary structured data
|
|
115
130
|
```
|
|
116
131
|
|
|
117
132
|
## Do NOT
|