seven365-logger
v0.1.1
Published
Seven365's TypeScript logger — logs to console and ships every level to a Laravel log server. Built for Nuxt 3 + Capacitor apps.
Maintainers
Readme
seven365-logger
Seven365's own logger for TypeScript apps (Nuxt 3, Capacitor). Logs to the console like normal, and ships every level to a Laravel log server so production logs are visible remotely — no more digging through device logs.
Install
npm install seven365-loggerUsage
import { Seven365Logger } from 'seven365-logger';
export const logger = new Seven365Logger({
apiUrl: 'https://logs.my-app.seven365.io/api/v1/logs',
apiKey: process.env.LOGGER_API_KEY!,
appName: 'my-nuxt-app',
environment: 'production', // 'staging' | 'development'
});
logger.info('User logged in', { userId: 123 });
logger.warn('Slow response', { ms: 4200 });
logger.error('Payment failed', { orderId: 456 });
logger.fatal('Unrecoverable state', { error });Instantiate once in a shared module and import that instance everywhere — ES module caching already gives you a singleton, no getInstance() needed.
Nuxt 3
// plugins/logger.ts
import { Seven365Logger } from 'seven365-logger';
export default defineNuxtPlugin(() => {
const config = useRuntimeConfig();
const logger = new Seven365Logger({
apiUrl: config.public.logsApiUrl,
apiKey: config.public.logsApiKey,
appName: 'my-nuxt-app',
environment: config.public.env,
});
return { provide: { logger } };
});Then use const { $logger } = useNuxtApp() anywhere in the app.
Capacitor
This package has no direct dependency on Capacitor — pass in the plugin instances your app already installed:
import { Network } from '@capacitor/network';
import { App } from '@capacitor/app';
import { Preferences } from '@capacitor/preferences';
import { Seven365Logger, CapacitorPreferencesQueueStorage, attachCapacitorLifecycle } from 'seven365-logger/capacitor';
const logger = new Seven365Logger({
apiUrl: '...',
apiKey: '...',
appName: 'my-app',
platform: 'ios',
storage: new CapacitorPreferencesQueueStorage(Preferences),
});
attachCapacitorLifecycle(logger, { network: Network, app: App });This flushes the queue as soon as connectivity returns or the app backgrounds, and persists pending logs across restarts while offline.
Behavior
- All five levels (
debug,info,warn,error,fatal) go to the console and ship to the server — there's no separate remote-level filtering. - Shipping is batched and non-blocking: entries queue up and flush every
flushIntervalMs(default 5s) or oncebatchSize(default 20) is reached — never one HTTP request per log line. - Failed batches stay queued and retry with backoff (
maxRetries, default 5) on the next flush. - Sensitive-looking context keys (
password,token,secret,apiKey,authorization, card-number-shaped keys, etc.) are redacted before the payload ever leaves the device. Extend the list viaredactKeys. apiUrlmust behttps://outside ofenvironment: 'development'.- The API key is sent via the
X-App-Keyheader, never a query string. Treat it as a low-trust client identifier — a value embedded in a shipped app can always be extracted — real protection is server-side rate limiting and the ability to rotate the key.
Retrofitting legacy console.log calls
Set captureConsole: true to patch global console.debug/info/warn/error so existing scattered console calls route through the logger too, without a rewrite. Off by default — prefer explicit logger.x() calls in new code.
Config reference
See Seven365LoggerConfig for the full list of options.
