@nolgard/webapps-logging
v0.1.0
Published
Standardized client-side logging bridge for Pinecone webapps (posts structured log events to the site's member-log endpoint).
Readme
@nolgard/webapps-logging
Standardized client-side logging bridge for PineCone webapps (React/Svelte widgets rendered
by addons). Posts structured log events to PineCone's member-log endpoint so front-end
issues (network failures, unexpected states, user-facing errors) show up alongside server-side
logs, using the same level / message / context / correlation_id shape as
Core\Log's event helpers.
Install
npm install @nolgard/webapps-loggingUsage
import { createPineconeLogger } from '@nolgard/webapps-logging'
const logger = createPineconeLogger({
source: 'pinecone-login',
csrfToken: () => currentCsrfToken, // string or (async) function
})
logger.info('Two-factor screen shown', { method: 'totp' })
logger.warning('Login submit failed', { reason: 'network_error' })
logger.error('Unexpected response shape', { status: 500 })API
createPineconeLogger(options)
endpoint: override the log endpoint URL (defaults to<base-path>/member-log)csrfToken: string or function (sync/async) returning the current member CSRF tokensource: short identifier for the calling widget (default'client')correlationId: reuse an existing correlation id instead of generating a new onefetchImpl: overridefetch(useful for tests)
Returns { correlationId, debug, info, warning, error, log(level, message, context) }.
Each method returns a promise resolving to { ok, error? } and never throws.
generateCorrelationId()
Generates a 16-character hex correlation id, matching the format produced by the server's
Core\Log::generateCorrelationId().
resolveDefaultLogEndpoint()
Resolves the default /member-log endpoint URL relative to the current page's base path.
Notes
- The
member-logendpoint requires a valid member CSRF token (obtained from/member-csrf) to reduce abuse; messages/context are capped server-side. - Only scalar context values are forwarded; nested objects/arrays are dropped.
