{"_id":"@caregenix/sumo-logger","_rev":"2-81cf2b81e6ee2b7218c542994b494201","name":"@caregenix/sumo-logger","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@caregenix/sumo-logger","version":"1.0.0","keywords":["sumologic","logging","typescript","nextjs","nodejs","tracing"],"author":{"name":"Junaid Basit"},"license":"MIT","_id":"@caregenix/sumo-logger@1.0.0","maintainers":[{"name":"junaid-basit-caregenix","email":"junaid.basit@caregenix.solutions"}],"dist":{"shasum":"1cbb94126ee6e9330ef61ff64d3fea4ca843f924","tarball":"https://registry.npmjs.org/@caregenix/sumo-logger/-/sumo-logger-1.0.0.tgz","fileCount":6,"integrity":"sha512-C4b2cQ9yDTykihIbwpItDZjAPIOn0nBrXimLTw02ScoZalJlt7INdBkV2U2ZBeQfyLZpZN4AJDiHI7y7y66pTw==","signatures":[{"sig":"MEUCIA9JpcH7E0Ek+iV9/rKuSEBT9wHdDKjwu5AygH/yNiR5AiEAstRVhxKJT1sS6fUPCBUGvFJv23QiLbEoFVQfGHzLx34=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":28341},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.mjs","engines":{"node":">=18.0.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"gitHead":"166ae0984fbc12812946b88ca4ff4bad0d6744e9","scripts":{"lint":"eslint src/**/*.ts","test":"vitest run","build":"tsup src/index.ts --format cjs,esm --dts --clean","prepublishOnly":"npm run build"},"_npmUser":{"name":"junaid-basit-caregenix","email":"junaid.basit@caregenix.solutions"},"_npmVersion":"10.9.7","description":"A production-ready TypeScript logger for Sumo Logic with request tracking, batching, and improved error handling.","directories":{},"_nodeVersion":"22.22.2","_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.0","vitest":"^1.0.0","typescript":"^5.0.0","@types/node":"^20.0.0"},"_npmOperationalInternal":{"tmp":"tmp/sumo-logger_1.0.0_1778862664154_0.9971863010110962","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@caregenix/sumo-logger","version":"1.0.1","description":"A production-ready TypeScript logger for Sumo Logic with request tracking, batching, and improved error handling.","type":"module","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs","default":"./dist/index.js"}},"main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","scripts":{"build":"tsup src/index.ts --format cjs,esm --dts --clean","postbuild":"node -e \"const fs=require('fs');['dist/index.js','dist/index.cjs','dist/index.d.ts'].forEach(f=>{if(!fs.existsSync(f))throw new Error('Missing '+f)})\"","test":"vitest run","lint":"eslint src/**/*.ts","prepublishOnly":"npm run build"},"keywords":["sumologic","logging","typescript","nextjs","nodejs","tracing"],"author":{"name":"Junaid Basit"},"license":"MIT","devDependencies":{"@types/node":"^20.0.0","tsup":"^8.0.0","typescript":"^5.0.0","vitest":"^1.0.0"},"engines":{"node":">=18.0.0"},"_id":"@caregenix/sumo-logger@1.0.1","gitHead":"2c04cc1a9a8d9889b155625c570a2b60961c71ea","_nodeVersion":"22.22.2","_npmVersion":"10.9.7","dist":{"integrity":"sha512-xIAWuHhUqfF33Wmr1aaokV6WLl8rXzXLa03ksr/pyrbim9oD+71BHijHbv7jVr3v8o0YLKTClGGSnL4CqIbwog==","shasum":"f78a8507ab02551c8c0515ae7d4b6b9e3a80569c","tarball":"https://registry.npmjs.org/@caregenix/sumo-logger/-/sumo-logger-1.0.1.tgz","fileCount":6,"unpackedSize":28552,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIE0AhZQjb+2zJoJyZuWmGdW2UHLOZ1YSeGo0AuP0GbdVAiA5pffOrmtBar6BTfwouMoZeUt49hHBEWhILNI75xMkMw=="}]},"_npmUser":{"name":"junaid-basit-caregenix","email":"junaid.basit@caregenix.solutions"},"directories":{},"maintainers":[{"name":"junaid-basit-caregenix","email":"junaid.basit@caregenix.solutions"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/sumo-logger_1.0.1_1779372476689_0.8162814518358903"},"_hasShrinkwrap":false}},"time":{"created":"2026-05-15T16:31:04.026Z","modified":"2026-05-21T14:07:56.963Z","1.0.0":"2026-05-15T16:31:04.303Z","1.0.1":"2026-05-21T14:07:56.823Z"},"author":{"name":"Junaid Basit"},"license":"MIT","keywords":["sumologic","logging","typescript","nextjs","nodejs","tracing"],"description":"A production-ready TypeScript logger for Sumo Logic with request tracking, batching, and improved error handling.","maintainers":[{"name":"junaid-basit-caregenix","email":"junaid.basit@caregenix.solutions"}],"readme":"# @caregenix/sumo-logger\r\n\r\nA production-ready, TypeScript-first logging library for shipping logs to **Sumo Logic HTTP Sources**. Optimized for Node.js (18+) and Next.js backends.\r\n\r\n## 🚀 Features\r\n\r\n- **High Performance**: Built-in batching and buffering to minimize network overhead.\r\n- **Request Tracking**: Automatic `requestId` tracing using `AsyncLocalStorage`.\r\n- **TypeScript Native**: Full typing support for a superior developer experience.\r\n- **Smart Error Handling**: Automatically preserves and formats stack traces for `Error` objects.\r\n- **Isomorphic**: Works seamlessly in Node.js, Next.js (API routes & Middleware), and Edge functions.\r\n- **Flexible**: Supports both Singleton and Instance-based usage for better testability.\r\n\r\n---\r\n\r\n## 📦 Installation\r\n\r\n```bash\r\nnpm install @caregenix/sumo-logger\r\n```\r\n\r\n---\r\n\r\n## 🛠️ Usage Guide\r\n\r\n### 1. Initialization (Best Practices)\r\n\r\n**Is a Singleton right for me?**\r\nYes, for most applications, initializing once globally is the correct approach. It ensures all parts of your app share the same connection pool, batching queue, and configuration.\r\n\r\n#### Step A: Create a logger configuration file\r\nCreate a file like `lib/logger.ts` in your project.\r\n\r\n```typescript\r\nimport SumoLogger from '@caregenix/sumo-logger';\r\n\r\n// Initialize once\r\nSumoLogger.initialize({\r\n  httpSourceUrl: process.env.SUMO_LOGIC_URL!,\r\n  sourceName: 'my-production-app',\r\n  defaultMetadata: {\r\n    env: process.env.NODE_ENV,\r\n    version: '1.0.0'\r\n  },\r\n  batchInterval: 5000, // Batch every 5 seconds\r\n  batchSize: 100,      // Or every 100 logs\r\n});\r\n\r\n// Export the instance for use throughout your app\r\nexport const logger = SumoLogger.getInstance();\r\n```\r\n\r\n#### Step B: Use it anywhere\r\n```typescript\r\nimport { logger } from './lib/logger';\r\n\r\nlogger.info('User logged in', { userId: '123' });\r\n```\r\n\r\n---\r\n\r\n### 2. Advanced Usage\r\n\r\n#### Request Tracing (Next.js/Node.js Middleware)\r\nTo correlate all logs within a single request, wrap your handler:\r\n\r\n```typescript\r\nimport { runWithRequestId } from '@caregenix/sumo-logger';\r\nimport { logger } from './lib/logger';\r\n\r\nexport default async function handler(req, res) {\r\n  const requestId = req.headers['x-request-id'] || 'gen-' + Date.now();\r\n  \r\n  return runWithRequestId(requestId, async () => {\r\n    logger.info('Processing API request'); // Will include requestId in Sumo Logic\r\n    // ... logic\r\n  });\r\n}\r\n```\r\n\r\n#### Error Logging\r\n```typescript\r\ntry {\r\n  throw new Error('Database connection failed');\r\n} catch (err) {\r\n  // Automatically captures error message and stack trace\r\n  logger.error('Critical Error', err);\r\n}\r\n```\r\n\r\n#### Graceful Shutdown\r\nTo ensure pending logs are sent before the process exits:\r\n\r\n```typescript\r\nprocess.on('SIGTERM', async () => {\r\n  await logger.flush();\r\n  process.exit(0);\r\n});\r\n```\r\n\r\n---\r\n\r\n### 3. Instance-based Usage (DI)\r\nUseful for unit testing or if you need multiple distinct loggers.\r\n\r\n```typescript\r\nimport { SumoLogger, SumoTransport } from '@caregenix/sumo-logger';\r\n\r\nconst transport = new SumoTransport({ httpSourceUrl: '...' });\r\nconst logger = new SumoLogger({ httpSourceUrl: '...' }, transport);\r\n```\r\n\r\n---\r\n\r\n## ⚙️ Configuration Options\r\n\r\n| Option | Type | Default | Description |\r\n| :--- | :--- | :--- | :--- |\r\n| `httpSourceUrl` | `string` | - | **Required**. Sumo Logic HTTP Source URL. |\r\n| `sourceName` | `string` | - | `X-Sumo-Name` header. |\r\n| `sourceCategory`| `string` | - | `X-Sumo-Category` header. |\r\n| `defaultMetadata`| `object` | `{}` | Metadata included in every log. |\r\n| `batchInterval` | `number` | `5000` | Batching interval in ms (0 to disable). |\r\n| `batchSize` | `number` | `100` | Max messages per batch. |\r\n| `internalLogger`| `object` | `console` | Logger for internal library health. |\r\n\r\n---\r\n\r\n## 📜 License\r\n\r\nMIT\r\n","readmeFilename":"README.md"}