{"_id":"@appinventiv/logger","_rev":"5-e2ef64d1dfef944e6c05050d03de4859","name":"@appinventiv/logger","dist-tags":{"latest":"1.0.3"},"versions":{"1.0.0":{"name":"@appinventiv/logger","version":"1.0.0","keywords":[],"author":"","license":"ISC","_id":"@appinventiv/logger@1.0.0","maintainers":[{"name":"abhishek.tyagi1","email":"abhishek.tyagi1@appinventiv.com"}],"dist":{"shasum":"fc32faf031499c359c809368581382a87444f2df","tarball":"https://registry.npmjs.org/@appinventiv/logger/-/logger-1.0.0.tgz","fileCount":16,"integrity":"sha512-d2PDfbkoWFQ6KOlX3/hi6+4gj+TrdCGR72wsQSVDO1GBuXQ+Lw0eB15P84lo4CwBfyC62Sv89xW3sb+fsZqFzg==","signatures":[{"sig":"MEYCIQDLz+hJQOnov+6A8Ve9xJUkUnmm0cUYBBekHa+5iKmOuQIhALhgQqCgq//j9w8sTGLIm3XiP//w7YsaIujrFSfmTtIQ","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":57601},"main":"dist/index.js","types":"dist/index.d.ts","scripts":{"test":"echo \"Error: no test specified\" && exit 1","build":"tsc"},"_npmUser":{"name":"abhishek.tyagi1","email":"abhishek.tyagi1@appinventiv.com"},"_npmVersion":"10.9.3","description":"Reusable Winston logger with context for Node.js services","directories":{},"_nodeVersion":"22.19.0","dependencies":{"winston":"^3.19.0"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.9.3","@types/node":"^25.0.9"},"_npmOperationalInternal":{"tmp":"tmp/logger_1.0.0_1769313976360_0.6488565948887293","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@appinventiv/logger","version":"1.0.1","keywords":[],"author":"","license":"ISC","_id":"@appinventiv/logger@1.0.1","maintainers":[{"name":"developer-at","email":"abhishektyagi199816@gmail.com"},{"name":"abhishek.tyagi1","email":"abhishek.tyagi1@appinventiv.com"}],"dist":{"shasum":"f6a0891e12213aad017dfdf8cab5d0e87a7a3e87","tarball":"https://registry.npmjs.org/@appinventiv/logger/-/logger-1.0.1.tgz","fileCount":16,"integrity":"sha512-rqOYqP3/E0MtCk/X+x+FN+mIOgWsC1SlrHSrkmIu7wakpMUkK18700rVIisBGeUGZAiE36KBM3ntHYrhfAQUuw==","signatures":[{"sig":"MEQCIDbWlHj4W1yUd4JBN5mbfuAOYaH9KcJpNO2rVZKf1KAeAiBrPu8DE33dXRGw3jxZ7SNc4DBCntyzXsPVPnwI2Y1TFA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":59452},"main":"dist/index.js","types":"dist/index.d.ts","scripts":{"test":"echo \"Error: no test specified\" && exit 1","build":"tsc"},"_npmUser":{"name":"abhishek.tyagi1","email":"abhishek.tyagi1@appinventiv.com"},"_npmVersion":"10.9.3","description":"Reusable Winston logger with context for Node.js services","directories":{},"_nodeVersion":"22.19.0","dependencies":{"winston":"^3.19.0"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.9.3","@types/node":"^25.0.9"},"_npmOperationalInternal":{"tmp":"tmp/logger_1.0.1_1769596123747_0.054249777514110864","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"@appinventiv/logger","version":"1.0.2","keywords":[],"author":"","license":"ISC","_id":"@appinventiv/logger@1.0.2","maintainers":[{"name":"developer-at","email":"abhishektyagi199816@gmail.com"},{"name":"abhishek.tyagi1","email":"abhishek.tyagi1@appinventiv.com"}],"dist":{"shasum":"6b079329a40a82f30660daf4b69fa6ea82111689","tarball":"https://registry.npmjs.org/@appinventiv/logger/-/logger-1.0.2.tgz","fileCount":16,"integrity":"sha512-XNBTHsoBgYu7R971/+BE4FRuSi/ygA8IU9WSNzLvccS6FQFDsnoNp+cBGy09wOY1nkZRaVdH2cl8n1VvZ7R/Qw==","signatures":[{"sig":"MEUCIQDj60QpE7cDOSSfRwoCjP6nL2bEiCoK/4WmkX2LpuZ0xgIgBoPqKXH19pSeNYWWFTIUIXT3c0pYvpXAPCp77EOJspM=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":63670},"main":"dist/index.js","types":"dist/index.d.ts","scripts":{"test":"echo \"Error: no test specified\" && exit 1","build":"tsc"},"_npmUser":{"name":"abhishek.tyagi1","email":"abhishek.tyagi1@appinventiv.com"},"_npmVersion":"10.9.3","description":"Reusable Winston logger with context for Node.js services","directories":{},"_nodeVersion":"22.19.0","dependencies":{"winston":"^3.19.0"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.9.3","@types/node":"^25.0.9"},"_npmOperationalInternal":{"tmp":"tmp/logger_1.0.2_1775662183630_0.9225762361678673","host":"s3://npm-registry-packages-npm-production"}},"1.0.3":{"name":"@appinventiv/logger","version":"1.0.3","description":"Reusable Winston logger with context for Node.js services","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"tsc","test":"echo \"Error: no test specified\" && exit 1"},"keywords":[],"author":"","license":"ISC","dependencies":{"winston":"^3.19.0"},"devDependencies":{"@types/node":"^25.0.9","typescript":"^5.9.3"},"_id":"@appinventiv/logger@1.0.3","_nodeVersion":"22.19.0","_npmVersion":"10.9.3","dist":{"integrity":"sha512-dojqBGQtjMHlx+ch14OIj5vLtDNEJpsDeAnxfKknggbFctHwbbfxlQPFFY5J39MxwrXX76pbZs0GYTR3XQuSlA==","shasum":"f258370d10c9b88f28cab08d3a82e957716d17a6","tarball":"https://registry.npmjs.org/@appinventiv/logger/-/logger-1.0.3.tgz","fileCount":16,"unpackedSize":65950,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCJLb0s9ccDdv3Cho4ExEGPOXgPwi6GKyhJWC3ThDBopAIgLEdRY4QIRF9AShZlLdr9fAMb2BXozgWRwVB97f4pCw4="}]},"_npmUser":{"name":"abhishek.tyagi1","email":"abhishek.tyagi1@appinventiv.com"},"directories":{},"maintainers":[{"name":"developer-at","email":"abhishektyagi199816@gmail.com"},{"name":"abhishek.tyagi1","email":"abhishek.tyagi1@appinventiv.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/logger_1.0.3_1778746154382_0.6527792654544273"},"_hasShrinkwrap":false}},"time":{"created":"2026-01-25T04:06:16.249Z","modified":"2026-05-14T08:09:14.634Z","1.0.0":"2026-01-25T04:06:16.536Z","1.0.1":"2026-01-28T10:28:43.911Z","1.0.2":"2026-04-08T15:29:43.780Z","1.0.3":"2026-05-14T08:09:14.516Z"},"license":"ISC","keywords":[],"description":"Reusable Winston logger with context for Node.js services","maintainers":[{"name":"developer-at","email":"abhishektyagi199816@gmail.com"},{"name":"abhishek.tyagi1","email":"abhishek.tyagi1@appinventiv.com"}],"readme":"# @developer-at/logger\n\nA reusable Winston logger package with context support for Node.js services. Provides structured logging with trace ID, user ID, and request source tracking.\n\n## Installation\n\n```bash\nnpm install @developer-at/logger\n```\n\n## Features\n\n- Winston-based logging with console transport\n- Context-aware logging (trace ID, user ID, request source)\n- **Plain logging:** `pInfo`, `pWarn`, `pError` — same Winston pipeline but **no** `{ trace, logs }` wrapper; all arguments are collected into one array and passed through to Winston as-is\n- Structured log output with timestamps\n- Service name labeling\n- TypeScript support\n\n## Usage\n\n### Basic Setup\n\n```typescript\nimport { logger } from '@developer-at/logger';\n\n// Set environment variable for service name (optional)\nprocess.env.SERVICE_NAME = 'my-service';\n\n// Basic logging\nlogger.info('Application started');\nlogger.warn('This is a warning');\nlogger.error('An error occurred');\n```\n\n### With Context Information\n\n```typescript\nimport { logger } from '@developer-at/logger';\n\n// Set context information\nlogger.setTraceId('trace-123-456');\nlogger.setUserId('user-789');\nlogger.setRequestFrom('API');\n\n// Log with context\nlogger.info('User logged in', { userId: 'user-789' });\nlogger.error('Failed to process request', { error: 'Database connection failed' });\n```\n\n### Plain logging (`pInfo`, `pWarn`, `pError`)\n\nUse these when you want logs **without** the structured context object (`trace`, `userId`, `requestFrom`). Each call forwards **one value** to Winston: an **array of every argument** you passed, in order. Nothing is stringified or merged for you; objects, errors, and primitives stay as you passed them (subject to how Winston / JSON serialization represent them in output).\n\nStructured methods (`info`, `warn`, `error`) always emit `{ trace, logs }` where `logs` is your argument list. Plain methods skip that wrapper entirely.\n\nWinston still applies your configured format (`json` / `pretty`) and default metadata (for example `service` / `label`).\n\n```typescript\n// Multiple arguments become one array payload for Winston\nlogger.pInfo('Server listening on', 3000);\n// Conceptually similar to: winston.info(['Server listening on', 3000])\n\nlogger.pWarn('Deprecated option', { key: 'oldFlag' });\n\nlogger.pError('Something failed', new Error('timeout'));\n\n// Single argument → array of one element\nlogger.pInfo({ event: 'boot', version: '1.0.0' });\n```\n\n**When to use which**\n\n| Method   | Context fields (`traceId`, `userId`, `requestFrom`) | Payload shape                          |\n|----------|--------------------------------------------------------|----------------------------------------|\n| `info` … | Included in `trace`                                    | `{ trace, logs }`                      |\n| `pInfo` …| Not attached                                           | `[ ...yourArgs ]` as the logged message |\n\n### Express.js Integration Example\n\n```typescript\nimport express from 'express';\nimport { logger } from '@developer-at/logger';\n\nconst app = express();\n\n// Middleware to set trace context\napp.use((req, res, next) => {\n  const traceId = req.headers['x-trace-id'] as string || `trace-${Date.now()}`;\n  const userId = req.headers['x-user-id'] as string;\n  \n  logger.setTraceId(traceId);\n  if (userId) logger.setUserId(userId);\n  logger.setRequestFrom('API');\n  \n  next();\n});\n\napp.get('/users', (req, res) => {\n  logger.info('Fetching users');\n  // ... your logic\n  logger.info('Users fetched successfully');\n  res.json({ users: [] });\n});\n```\n\n### Using LoggerUtils Class Directly\n\n```typescript\nimport { LoggerUtils } from '@developer-at/logger';\n\n// Create a custom logger instance\nconst customLogger = new LoggerUtils();\ncustomLogger.setTraceId('custom-trace');\ncustomLogger.setUserId('custom-user');\ncustomLogger.setRequestFrom('Worker');\n\ncustomLogger.info('Processing job');\ncustomLogger.error('Job failed', { error: 'Timeout' });\n```\n\n## API Reference\n\n### `logger` (Singleton Instance)\n\nPre-configured logger instance ready to use.\n\n### `LoggerUtils` Class\n\nMain logger utility class.\n\n#### `constructor()`\n\nInitializes a new LoggerUtils instance with Winston logger.\n\n#### `setTraceId(traceId: string)`\n\nSets the trace ID for request tracking.\n\n**Parameters:**\n- `traceId` (string): Unique trace identifier\n\n#### `setUserId(userId: string)`\n\nSets the user ID for logging context.\n\n**Parameters:**\n- `userId` (string): User identifier\n\n#### `setRequestFrom(requestFrom: string)`\n\nSets the request source for logging context.\n\n**Parameters:**\n- `requestFrom` (string): Source of the request (e.g., 'API', 'Worker', 'Cron')\n\n#### `getTraceId(): string | undefined`\n\nReturns the current trace ID, if any was set with `setTraceId`.\n\n#### `getUserId(): string | undefined`\n\nReturns the current user ID, if any was set with `setUserId`.\n\n#### `getRequestFrom(): string | undefined`\n\nReturns the current request source, if any was set with `setRequestFrom`.\n\n#### `info(...logs: any[])`\n\nLogs an informational message.\n\n**Parameters:**\n- `...logs` (any[]): One or more log messages or objects\n\n**Example:**\n```typescript\nlogger.info('User created', { userId: '123', email: 'user@example.com' });\n```\n\n#### `warn(...logs: any[])`\n\nLogs a warning message.\n\n**Parameters:**\n- `...logs` (any[]): One or more log messages or objects\n\n**Example:**\n```typescript\nlogger.warn('Rate limit approaching', { current: 90, limit: 100 });\n```\n\n#### `error(...logs: any[])`\n\nLogs an error message.\n\n**Parameters:**\n- `...logs` (any[]): One or more log messages or objects\n\n**Example:**\n```typescript\nlogger.error('Database connection failed', { error: error.message, stack: error.stack });\n```\n\n#### `pInfo(...logs: any[])`\n\nPlain informational log at Winston level `info`. Does **not** wrap output in `{ trace, logs }`. All arguments are gathered into `[...logs]` and that array is what Winston receives as the log message payload.\n\n**Parameters:**\n\n- `...logs` (any[]): Any values you want on the log line; order is preserved in the array.\n\n**Example:**\n\n```typescript\nlogger.pInfo('ready', { port: 8080 });\n// Winston sees a single payload: ['ready', { port: 8080 }]\n```\n\n#### `pWarn(...logs: any[])`\n\nSame as `pInfo`, but at Winston level `warn`.\n\n#### `pError(...logs: any[])`\n\nSame as `pInfo`, but at Winston level `error`.\n\n## Configuration\n\n### Environment Variables\n\n- `SERVICE_NAME`: Service name to include in log labels (optional, defaults to empty string)\n- `LOG_OUTPUT_FORMAT`: Log output mode (optional)\n  - `pretty`: human-readable structured logs (can be multiline)\n  - `json`: single-line JSON output\n  - `minified`: single-line JSON output\n  - default: `json`\n\n### Log Format\n\nLogs are output in the following format:\n- **Label**: Service name (from `SERVICE_NAME` env var)\n- **Timestamp**: ISO-8601 format (e.g. `2026-03-13T10:21:45.123Z`)\n- **Level**: Log level (info, warn, error)\n- **Trace**: Object containing traceId, userId, and requestFrom\n- **Logs**: Array of log messages/objects\n\n### CloudWatch Friendly Mode (Single Line)\n\nSet:\n\n```bash\nLOG_OUTPUT_FORMAT=json\n```\n\nor\n\n```bash\nLOG_OUTPUT_FORMAT=minified\n```\n\nBoth output one JSON object per line, which is easier to query in CloudWatch.\n\n### Pretty Mode (Local Debugging)\n\nSet:\n\n```bash\nLOG_OUTPUT_FORMAT=pretty\n```\n\nThis keeps a more readable format and may span multiple lines.\n\n### Example Log Output (JSON/Minified)\n\n```json\n{\n  \"level\": \"info\",\n  \"message\": \"\",\n  \"label\": \"my-service\",\n  \"timestamp\": \"2026-03-13T10:21:45.123Z\",\n  \"trace\": {\n    \"traceId\": \"trace-123-456\",\n    \"userId\": \"user-789\",\n    \"requestFrom\": \"API\"\n  },\n  \"logs\": [\n    \"User logged in\",\n    {\n      \"userId\": \"user-789\",\n      \"action\": \"login\"\n    }\n  ]\n}\n```\n\n## TypeScript Support\n\nThe package includes full TypeScript definitions and is written in TypeScript.\n\n## Dependencies\n\n- `winston`: ^3.19.0\n\n## License\n\nISC\n","readmeFilename":"README.md"}