{"_id":"@apexmcp/logger","name":"@apexmcp/logger","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@apexmcp/logger","version":"1.0.0","description":"Universal logging utility for TypeScript applications. Supports structured logging, multiple log levels, and context tracking.","author":{"name":"@keyrxng"},"license":"MIT","main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"type":"module","scripts":{"build":"tsup","test":"bun test","test:watch":"bun test --watch","test:coverage":"bun test --coverage","format":"run-s format:lint format:prettier format:cspell","format:lint":"eslint --fix .","format:prettier":"prettier --write .","format:cspell":"cspell **/*","lint":"eslint .","typecheck":"tsc --noEmit","clean":"rm -rf dist coverage .swc","prepublishOnly":"bun run clean && bun run build && bun run test"},"keywords":["typescript","logger","logging","structured-logging","console","bun","deno","nodejs","universal"],"dependencies":{},"devDependencies":{"@types/bun":"^1.3.4","@types/node":"^25.0.2","eslint":"^9.39.2","eslint-config-prettier":"^10.1.8","eslint-plugin-import":"^2.32.0","eslint-plugin-sonarjs":"^3.0.5","prettier":"^3.1.0","tsup":"^8.5.1","typescript":"^5.9.3","typescript-eslint":"^8.49.0"},"_id":"@apexmcp/logger@1.0.0","gitHead":"c2bacc3d081daa027cca4938c418f926b1fbfe2b","_nodeVersion":"22.17.0","_npmVersion":"11.4.2","dist":{"integrity":"sha512-RQC0K0WRmnxlZMzQhJcwlC8xUhWEtvdNV0zchNZR0Tu1qVBb5vIf8QcdSKajDoZ92zxMVCPhAeThnP7SZsoYJg==","shasum":"c8434ccde6c78c252db116763c643b0c20c59f1b","tarball":"https://registry.npmjs.org/@apexmcp/logger/-/logger-1.0.0.tgz","fileCount":9,"unpackedSize":29549,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIGEvRaX5kVFn58YPc0/82VxtmIdIKYKg1+7jJDYB4XPnAiB+xuedPgfCWss7NJt5GmUKV9rmQwSEkfNT15LQNOBGOQ=="}]},"_npmUser":{"name":"official_apexmcp","email":"kieranpatton@proton.me"},"directories":{},"maintainers":[{"name":"official_apexmcp","email":"kieranpatton@proton.me"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/logger_1.0.0_1766261483500_0.2751554665352889"},"_hasShrinkwrap":false}},"time":{"created":"2025-12-20T20:11:23.341Z","1.0.0":"2025-12-20T20:11:23.651Z","modified":"2025-12-20T20:11:24.077Z"},"maintainers":[{"name":"official_apexmcp","email":"kieranpatton@proton.me"}],"description":"Universal logging utility for TypeScript applications. Supports structured logging, multiple log levels, and context tracking.","keywords":["typescript","logger","logging","structured-logging","console","bun","deno","nodejs","universal"],"author":{"name":"@keyrxng"},"license":"MIT","readme":"# @apexmcp/logger\n\nA universal logging utility for TypeScript applications with structured logging, multiple log levels, and context support. Works seamlessly across Bun, Deno, and Node.js environments.\n\n## Features\n\n- ✅ Multiple log levels (DEBUG, INFO, LOG, WARN, ERROR)\n- ✅ Structured logging with context support\n- ✅ Child loggers for hierarchical logging\n- ✅ Environment variable configuration (`LOG_LEVEL`)\n- ✅ TypeScript support with full type safety\n- ✅ Universal compatibility (Bun, Deno, Node.js)\n- ✅ Zero dependencies\n- ✅ ESM and CommonJS support\n\n## Installation\n\n```bash\n# Using bun\nbun add @apexmcp/logger\n\n# Using npm\nnpm install @apexmcp/logger\n\n# Using yarn\nyarn add @apexmcp/logger\n\n# Using pnpm\npnpm add @apexmcp/logger\n```\n\n## Quick Start\n\n```typescript\nimport { logger } from '@apexmcp/logger';\n\n// Basic logging\nlogger.info('Application started');\nlogger.warn('This is a warning');\nlogger.error('This is an error');\n\n// With additional data\nlogger.debug('Processing user', { userId: 123, action: 'login' });\n```\n\n## API Reference\n\n### Logger Instance\n\nThe package exports a default logger instance that can be used immediately:\n\n```typescript\nimport { logger } from '@apexmcp/logger';\n\nlogger.info('Hello, world!');\n```\n\n### Creating Custom Loggers\n\n```typescript\nimport { Logger, LOG_LEVEL } from '@apexmcp/logger';\n\n// Create a logger with specific level\nconst customLogger = new Logger(LOG_LEVEL.DEBUG);\n\n// Create a logger with context\nconst contextualLogger = new Logger(LOG_LEVEL.INFO, { service: 'api' });\n```\n\n### Log Levels\n\nAvailable log levels in order of verbosity:\n\n- `LOG_LEVEL.DEBUG` - Detailed debugging information\n- `LOG_LEVEL.INFO` - General information messages\n- `LOG_LEVEL.LOG` - Standard log messages\n- `LOG_LEVEL.WARN` - Warning messages\n- `LOG_LEVEL.ERROR` - Error messages (always logged)\n\n### Logging Methods\n\nAll logging methods accept a message string and optional additional arguments:\n\n```typescript\nlogger.debug(message: string, ...args: unknown[]): void\nlogger.info(message: string, ...args: unknown[]): void\nlogger.log(message: string, ...args: unknown[]): void\nlogger.warn(message: string, ...args: unknown[]): void\nlogger.error(message: string, ...args: unknown[]): void\n```\n\nArguments are automatically serialized to JSON:\n\n```typescript\nlogger.info('User logged in', { userId: 123, timestamp: new Date() });\n// Output: [2023-01-01T12:00:00.000Z] INFO: User logged in {\"userId\":123,\"timestamp\":\"2023-01-01T12:00:00.000Z\"}\n```\n\n### Structured Logging with Context\n\nAdd persistent context to loggers:\n\n```typescript\nconst userLogger = logger.child({ userId: 123, sessionId: 'abc' });\n\nuserLogger.info('User action performed', { action: 'login' });\n// Output: [2023-01-01T12:00:00.000Z] INFO: {\"userId\":123,\"sessionId\":\"abc\"} User action performed {\"action\":\"login\"}\n```\n\nContext is merged when creating child loggers:\n\n```typescript\nconst baseLogger = new Logger(LOG_LEVEL.INFO, { service: 'api' });\nconst requestLogger = baseLogger.child({ requestId: 'req-123' });\n\nrequestLogger.info('Processing request');\n// Output: [2023-01-01T12:00:00.000Z] INFO: {\"service\":\"api\",\"requestId\":\"req-123\"} Processing request\n```\n\n### Changing Log Levels\n\n```typescript\n// Change level on existing logger instance\nconst newLogger = logger.setLevel(LOG_LEVEL.DEBUG);\n\n// Create new logger with different level\nconst debugLogger = new Logger(LOG_LEVEL.DEBUG);\n```\n\n### Environment Variable Configuration\n\nSet the `LOG_LEVEL` environment variable to control logging verbosity:\n\n```bash\n# Enable debug logging\nLOG_LEVEL=DEBUG bun run app.ts\n\n# Only show warnings and errors\nLOG_LEVEL=WARN node app.js\n```\n\nSupported values: `DEBUG`, `INFO`, `LOG`, `WARN`, `ERROR`\n\n### Universal Environment Support\n\nThe logger automatically detects and works in different JavaScript environments:\n\n- **Bun**: Uses `process.env.LOG_LEVEL`\n- **Deno**: Uses `Deno.env.get('LOG_LEVEL')`\n- **Node.js**: Uses `process.env.LOG_LEVEL`\n\n## Advanced Usage\n\n### Request Logging Middleware\n\n```typescript\nfunction createRequestLogger(requestId: string) {\n  return logger.child({ requestId });\n}\n\n// In your request handler\nconst requestLogger = createRequestLogger('req-123');\nrequestLogger.info('Request received', { method: 'GET', path: '/api/users' });\n\n// Later in processing\nrequestLogger.debug('Validating user input', { input: userData });\nrequestLogger.warn('Invalid email format', { email: 'invalid-email' });\n```\n\n### Service-Specific Loggers\n\n```typescript\nclass UserService {\n  private logger = logger.child({ service: 'UserService' });\n\n  async createUser(userData: any) {\n    this.logger.info('Creating user', { email: userData.email });\n\n    try {\n      // ... user creation logic\n      this.logger.info('User created successfully', { userId: result.id });\n      return result;\n    } catch (error) {\n      this.logger.error('Failed to create user', { error: error.message });\n      throw error;\n    }\n  }\n}\n```\n\n## TypeScript Support\n\nFull TypeScript support with exported types:\n\n```typescript\nimport type { Logger, LogLevel, LogContext } from '@apexmcp/logger';\n\ninterface CustomContext extends LogContext {\n  userId: string;\n  sessionId: string;\n}\n\nconst customLogger: Logger = new Logger(LOG_LEVEL.INFO);\n```\n\n## Output Format\n\nLog messages follow this format:\n\n```\n[timestamp] LEVEL: [context] message [args]\n```\n\n- **timestamp**: ISO 8601 formatted timestamp\n- **LEVEL**: Log level (DEBUG, INFO, LOG, WARN, ERROR)\n- **context**: Optional JSON context object (only shown if context exists)\n- **message**: Log message\n- **args**: Optional additional arguments as JSON (only shown if args exist)\n\n## Examples\n\n### Basic Application Logging\n\n```typescript\nimport { logger } from '@apexmcp/logger';\n\nfunction startApp() {\n  logger.info('Application starting...');\n\n  // Simulate app startup\n  logger.debug('Loading configuration...');\n  logger.debug('Connecting to database...');\n  logger.info('Database connected successfully');\n\n  logger.info('Application started successfully');\n}\n\nstartApp();\n```\n\n### Error Handling\n\n```typescript\nimport { logger } from '@apexmcp/logger';\n\nasync function processUser(userId: string) {\n  const userLogger = logger.child({ userId });\n\n  try {\n    userLogger.debug('Processing user data');\n\n    const user = await fetchUser(userId);\n    userLogger.info('User data retrieved', { userFound: !!user });\n\n    return user;\n  } catch (error) {\n    userLogger.error('Failed to process user', {\n      error: error.message,\n      stack: error.stack,\n    });\n    throw error;\n  }\n}\n```\n\n## Contributing\n\nContributions are welcome! Please ensure all tests pass and add tests for new features.\n\n```bash\n# Install dependencies\nbun install\n\n# Run tests\nbun test\n\n# Run tests in watch mode\nbun test --watch\n\n# Build the package\nbun run build\n```\n\n## License\n\nMIT\n","readmeFilename":"README.md","_rev":"1-96c103dedeaada9e091bbff4cb0477a4"}