@cooperco/nuxt-layer-base 1.3.1 → 1.3.2
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 +8 -8
- package/app/composables/useLogger.ts +8 -1
- package/nuxt.config.ts +8 -6
- package/package.json +2 -1
- package/server/api/log.post.ts +8 -1
package/README.md
CHANGED
|
@@ -133,11 +133,11 @@ When enabled via environment variables, the base layer will:
|
|
|
133
133
|
|
|
134
134
|
Enable in your app with environment variables:
|
|
135
135
|
|
|
136
|
-
- `
|
|
137
|
-
- `
|
|
138
|
-
- `
|
|
139
|
-
- `
|
|
140
|
-
- `
|
|
136
|
+
- `NUXT_PUBLIC_LOGGLY_ENABLED=true`
|
|
137
|
+
- `NUXT_LOGGLY_TOKEN=<your Loggly customer token>` (server-only)
|
|
138
|
+
- `NUXT_PUBLIC_LOGGLY_TAGS=app-name,env` (optional, comma-separated)
|
|
139
|
+
- `NUXT_PUBLIC_LOG_LEVEL=error` (optional; exposed to client for your own use)
|
|
140
|
+
- `NUXT_LOGGLY_ENDPOINT=https://logs-01.loggly.com/inputs` (optional override, server-only)
|
|
141
141
|
|
|
142
142
|
Notes
|
|
143
143
|
- The token is never exposed to the client. Browsers only post to your app’s `/api/log` endpoint (with `/api/loggly` kept as a deprecated alias).
|
|
@@ -176,9 +176,9 @@ Security and privacy:
|
|
|
176
176
|
Verify locally:
|
|
177
177
|
1) Add env vars in your app (e.g., `.env.local`):
|
|
178
178
|
```
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
179
|
+
NUXT_PUBLIC_LOGGLY_ENABLED=true
|
|
180
|
+
NUXT_LOGGLY_TOKEN=...your token...
|
|
181
|
+
NUXT_PUBLIC_LOGGLY_TAGS=app-name,local
|
|
182
182
|
```
|
|
183
183
|
2) Start your app and trigger a test error.
|
|
184
184
|
3) Check the network tab for `POST /api/log` and then confirm the entry in Loggly.
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
export type LogLevel = 'error' | 'warn' | 'info' | 'debug'
|
|
2
2
|
|
|
3
|
+
// Parse logglyTags from string (comma-separated) or array
|
|
4
|
+
const parseTags = (tags: unknown): string[] => {
|
|
5
|
+
if (Array.isArray(tags)) return tags
|
|
6
|
+
if (typeof tags === 'string') return tags.split(',').map(s => s.trim()).filter(Boolean)
|
|
7
|
+
return []
|
|
8
|
+
}
|
|
9
|
+
|
|
3
10
|
export const useLogger = () => {
|
|
4
11
|
const { public: pub } = useRuntimeConfig()
|
|
5
12
|
const enabled = !!pub?.logglyEnabled
|
|
6
|
-
const baseTags = (pub?.logglyTags
|
|
13
|
+
const baseTags = parseTags(pub?.logglyTags)
|
|
7
14
|
|
|
8
15
|
const send = (
|
|
9
16
|
level: LogLevel,
|
package/nuxt.config.ts
CHANGED
|
@@ -5,16 +5,18 @@ export default defineNuxtConfig({
|
|
|
5
5
|
compatibilityDate: '2025-07-15',
|
|
6
6
|
|
|
7
7
|
runtimeConfig: {
|
|
8
|
-
// server-only
|
|
8
|
+
// server-only - Set via NUXT_LOGGLY_TOKEN or LOGGLY_TOKEN at runtime
|
|
9
9
|
logglyToken: process.env.LOGGLY_TOKEN || '',
|
|
10
10
|
logglyEndpoint: process.env.LOGGLY_ENDPOINT || 'https://logs-01.loggly.com/inputs',
|
|
11
11
|
|
|
12
|
-
// public
|
|
12
|
+
// public - Set via NUXT_PUBLIC_* or legacy non-prefixed vars at runtime
|
|
13
13
|
public: {
|
|
14
|
-
//
|
|
15
|
-
logglyEnabled:
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
// NUXT_PUBLIC_LOGGLY_ENABLED or LOGGLY_ENABLED
|
|
15
|
+
logglyEnabled: process.env.LOGGLY_ENABLED === 'true' || false,
|
|
16
|
+
// NUXT_PUBLIC_LOGGLY_TAGS or LOGGLY_TAGS
|
|
17
|
+
logglyTags: process.env.LOGGLY_TAGS || 'nuxt,base',
|
|
18
|
+
// NUXT_PUBLIC_LOG_LEVEL or LOG_LEVEL
|
|
19
|
+
logLevel: process.env.LOG_LEVEL || 'error'
|
|
18
20
|
}
|
|
19
21
|
},
|
|
20
22
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cooperco/nuxt-layer-base",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./nuxt.config.ts",
|
|
6
6
|
"author": "cooperco",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@nuxt/eslint": "^1.12.1",
|
|
32
32
|
"@nuxt/test-utils": "^3.23.0",
|
|
33
|
+
"@types/node": "^25.0.10",
|
|
33
34
|
"eslint": "^9.39.2",
|
|
34
35
|
"vue-tsc": "^3.2.2"
|
|
35
36
|
}
|
package/server/api/log.post.ts
CHANGED
|
@@ -8,6 +8,13 @@ type LogglyBody = {
|
|
|
8
8
|
meta?: Record<string, unknown>
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
// Parse logglyTags from string (comma-separated) or array
|
|
12
|
+
const parseTags = (tags: unknown): string[] => {
|
|
13
|
+
if (Array.isArray(tags)) return tags
|
|
14
|
+
if (typeof tags === 'string') return tags.split(',').map(s => s.trim()).filter(Boolean)
|
|
15
|
+
return []
|
|
16
|
+
}
|
|
17
|
+
|
|
11
18
|
const sanitizeMeta = (input: unknown) => {
|
|
12
19
|
if (!input || typeof input !== 'object') return undefined
|
|
13
20
|
const blocked = [
|
|
@@ -48,7 +55,7 @@ export default defineEventHandler(async (event) => {
|
|
|
48
55
|
const scrubbed = {
|
|
49
56
|
level: body?.level ?? 'error',
|
|
50
57
|
message: body?.message?.toString().slice(0, 5000),
|
|
51
|
-
tags: [...new Set([...(pub.logglyTags
|
|
58
|
+
tags: [...new Set([...parseTags(pub.logglyTags), ...(body?.tags || [])])].slice(0, 10),
|
|
52
59
|
meta: sanitizeMeta(body?.meta),
|
|
53
60
|
error: body?.error ? serializeError(body.error) : undefined,
|
|
54
61
|
ts: new Date().toISOString()
|