{"id":17359,"library":"seq-logging","title":"Seq Logging for JavaScript","description":"seq-logging is a JavaScript library designed to send structured log events to the Seq HTTP ingestion API. It is currently at version 3.0.0 and serves as a low-level client, primarily intended for use by other logging frameworks and their respective Seq transports (e.g., winston-seq, pino-seq, bunyan-seq, @tsed/logger-seq), rather than for direct application interaction. The library handles asynchronous batching of log events based on payload size and provides mechanisms to ensure all buffered events are sent upon application exit or explicit flushing. Its key differentiator is acting as the foundational communication layer for Seq within the JavaScript ecosystem, offering both Node.js and browser-specific builds, and explicitly supports ESM.","status":"active","version":"3.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/datalust/seq-logging","tags":["javascript","seq","logging","typescript"],"install":[{"cmd":"npm install seq-logging","lang":"bash","label":"npm"},{"cmd":"yarn add seq-logging","lang":"bash","label":"yarn"},{"cmd":"pnpm add seq-logging","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Starting with v3, seq-logging is an ESM-only package. CommonJS `require()` is not supported for the main entry point.","wrong":"const { Logger } = require('seq-logging')","symbol":"Logger","correct":"import { Logger } from 'seq-logging'"},{"note":"For browser environments, use the dedicated `seq-logging/browser` entry point. CommonJS `require()` is not supported for v3.","wrong":"const { Logger } = require('seq-logging/browser')","symbol":"Logger","correct":"import { Logger } from 'seq-logging/browser'"},{"note":"Type-only import for configuring the Logger instance, especially when using TypeScript.","symbol":"LoggerOptions","correct":"import type { LoggerOptions } from 'seq-logging'"}],"quickstart":{"code":"import process from 'process';\nimport { Logger } from 'seq-logging';\n\nconst logger = new Logger({\n    serverUrl: process.env.SEQ_SERVER_URL ?? 'http://localhost:5341',\n    apiKey: process.env.SEQ_API_KEY ?? undefined, // Optional\n    requestTimeout: 30000 // default to 30s\n});\n\nlogger.emit({\n    timestamp: new Date(),\n    level: 'Information',\n    messageTemplate: 'Hello from {appName}! It is {currentTime}.',\n    properties: {\n        appName: 'MySeqApp',\n        currentTime: new Date().toISOString(),\n        user: process.env.USERNAME ?? 'anonymous'\n    }\n});\n\n// Ensure all buffered events are sent before exiting\nlogger.close().then(() => console.log('Logger closed successfully.'));","lang":"typescript","description":"Initializes a Seq Logger and emits a structured log event with properties, demonstrating basic usage and proper shutdown."},"warnings":[{"fix":"Migrate your import statements to use ES module syntax (e.g., `import { Logger } from 'seq-logging'`). If using Node.js, ensure your project is configured for ESM (e.g., `\"type\": \"module\"` in package.json or using `.mjs` file extension).","message":"Version 3.0.0 and later are ESM-only, meaning CommonJS `require()` syntax is no longer supported for importing the library. Attempting to use `require()` will result in import errors.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Always call `logger.close()` or `logger.flush()` before your application terminates to ensure all pending events are sent to Seq. Both methods return a Promise, which should be awaited.","message":"Events are buffered internally for asynchronous batching. If the application exits before `close()` or `flush()` is called, buffered events may be lost.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure your build system (e.g., Webpack, Rollup) or direct imports use `import { Logger } from 'seq-logging/browser'` when bundling for browsers, and `import { Logger } from 'seq-logging'` for Node.js.","message":"When targeting browser environments, a different entry point must be used (`seq-logging/browser`) compared to Node.js environments (`seq-logging`).","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade your Node.js environment to version 14.18.0 or newer to ensure full compatibility and access to required features.","message":"The package requires Node.js version 14.18 or higher. Running on older Node.js versions may lead to unexpected errors or compatibility issues.","severity":"gotcha","affected_versions":"<3.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Change `const { Logger } = require('seq-logging');` to `import { Logger } from 'seq-logging';` and ensure your project is set up for ES Modules.","cause":"Attempting to use CommonJS `require()` to import `seq-logging` in a project configured for ESM, or in `seq-logging` v3+ which is ESM-only.","error":"TypeError: require is not a function"},{"fix":"When building for browsers, avoid direct use of Node.js globals like `process`. If environment variables are needed, pass them in at build time or use a browser-compatible method. Alternatively, ensure your bundler provides a `process` polyfill.","cause":"Attempting to use `process` global in a browser environment without proper polyfill or a Node.js specific build setup.","error":"ReferenceError: process is not defined"}],"ecosystem":"npm","meta_description":null}