{"_id":"@atlantis-gr/svelte-logging-abstractions","name":"@atlantis-gr/svelte-logging-abstractions","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@atlantis-gr/svelte-logging-abstractions","version":"1.0.0","description":"Logging abstractions for Svelte components","scripts":{"dev":"vite dev","build:pack":"svelte-package && npm pack","build":"svelte-package","preview":"vite preview","prepare":"svelte-kit sync || echo ''","prepack":"svelte-package","check":"svelte-kit sync && svelte-check --tsconfig ./tsconfig.json","check:watch":"svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch","format":"prettier --write .","lint":"prettier --check ."},"sideEffects":["**/*.css"],"svelte":"./dist/index.js","types":"./dist/index.d.ts","type":"module","exports":{".":{"types":"./dist/index.d.ts","svelte":"./dist/index.js"},"./components":{"types":"./dist/components/index.d.ts","svelte":"./dist/components/index.js"}},"peerDependencies":{"svelte":"^5.0.0","@sveltejs/kit":"^2.0.0"},"devDependencies":{"@sveltejs/adapter-auto":"^6.1.0","@sveltejs/kit":"^2.43.2","@sveltejs/package":"^2.5.4","@sveltejs/vite-plugin-svelte":"^6.2.0","prettier":"^3.6.2","prettier-plugin-svelte":"^3.4.0","prettier-plugin-tailwindcss":"^0.6.14","publint":"^0.3.13","svelte":"^5.39.5","svelte-check":"^4.3.2","tailwindcss":"^4.1.13","typescript":"^5.9.2","vite":"^7.1.7"},"author":{"name":"Atlantis GR"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/Atlantis-GR/svelte-components.git"},"keywords":["svelte","logging"],"_id":"@atlantis-gr/svelte-logging-abstractions@1.0.0","gitHead":"137e0990ef179a7a96718e6db5186bbc15d47f13","bugs":{"url":"https://github.com/Atlantis-GR/svelte-components/issues"},"homepage":"https://github.com/Atlantis-GR/svelte-components#readme","_nodeVersion":"24.2.0","_npmVersion":"10.9.1","dist":{"integrity":"sha512-PMnNU/nCtehJdBuGGzpUIUvSbf3vbmS0AbEoTDBnBejLCmdNcE94gXHhOsgg+CzdGa/vx7VXb1z7zmzCLvrocg==","shasum":"2965c2eb1c8c1c9f48829323c6d905814f0539f6","tarball":"https://registry.npmjs.org/@atlantis-gr/svelte-logging-abstractions/-/svelte-logging-abstractions-1.0.0.tgz","fileCount":4,"unpackedSize":12750,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIDNzlhrJ0KpVwbZLosGx+IymudBa/wdHUu3yHUozqiBPAiEA8p4bDMzKduKfZv6G50aG3LMwPr2gWM/R1PwXcCZ3S1Y="}]},"_npmUser":{"name":"lefterisrentas","email":"lefteris.rentasac@gmail.com"},"directories":{},"maintainers":[{"name":"lefterisrentas","email":"lefteris.rentasac@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/svelte-logging-abstractions_1.0.0_1760717350623_0.02601463070019605"},"_hasShrinkwrap":false}},"time":{"created":"2025-10-17T16:09:10.482Z","1.0.0":"2025-10-17T16:09:10.810Z","modified":"2025-10-17T16:09:11.070Z"},"maintainers":[{"name":"lefterisrentas","email":"lefteris.rentasac@gmail.com"}],"description":"Logging abstractions for Svelte components","homepage":"https://github.com/Atlantis-GR/svelte-components#readme","keywords":["svelte","logging"],"repository":{"type":"git","url":"git+https://github.com/Atlantis-GR/svelte-components.git"},"author":{"name":"Atlantis GR"},"bugs":{"url":"https://github.com/Atlantis-GR/svelte-components/issues"},"license":"MIT","readme":"# @atlantis-gr/svelte-logging-abstractions\r\n\r\nFlexible logging abstractions for Svelte applications with structured logging support.\r\n\r\n## Features\r\n\r\n- Multiple log levels (debug, info, warn, error)\r\n- Scoped loggers for component-specific logging\r\n- Custom formatters for different output formats\r\n- Browser and server compatibility\r\n- Structured logging with metadata support\r\n- TypeScript support with full type definitions\r\n\r\n## Installation\r\n\r\n```bash\r\nnpm install @atlantis-gr/svelte-logging-abstractions\r\n```\r\n\r\n## Usage\r\n\r\n### 1. Create a Logger\r\n\r\n```typescript\r\nimport { createScopedLogger } from '@atlantis-gr/svelte-logging-abstractions';\r\n\r\nconst logger = createScopedLogger('MyComponent');\r\n\r\nlogger.info('Component initialized');\r\nlogger.warn('Deprecation warning', { component: 'MyComponent' });\r\nlogger.error('An error occurred', { error: 'Details here' });\r\n```\r\n\r\n### 2. Use in Svelte Components\r\n\r\n```svelte\r\n<script>\r\n  import { createScopedLogger } from '@atlantis-gr/svelte-logging-abstractions';\r\n  import { onMount } from 'svelte';\r\n  \r\n  const logger = createScopedLogger('UserProfile');\r\n  \r\n  onMount(() => {\r\n    logger.info('UserProfile component mounted');\r\n  });\r\n  \r\n  function handleUserUpdate() {\r\n    try {\r\n      // Update user logic\r\n      logger.info('User profile updated successfully');\r\n    } catch (error) {\r\n      logger.error('Failed to update user profile', { error });\r\n    }\r\n  }\r\n</script>\r\n```\r\n\r\n### 3. Configure Logging Levels\r\n\r\n```typescript\r\nimport { getLogger, LogLevel } from '@atlantis-gr/svelte-logging-abstractions';\r\n\r\n// Set global log level\r\nconst rootLogger = getLogger();\r\nrootLogger.setLevel(LogLevel.DEBUG);\r\n\r\n// Set specific logger level\r\nconst apiLogger = createScopedLogger('API');\r\napiLogger.setLevel(LogLevel.WARN); // Only warn and error messages\r\n```\r\n\r\n## 🔧 API Reference\r\n\r\n### Core Functions\r\n\r\n#### `createScopedLogger(scope: string)`\r\nCreates a scoped logger with the specified scope name.\r\n\r\n```typescript\r\nconst logger = createScopedLogger('AuthService');\r\nlogger.info('User authenticated'); // [AuthService] User authenticated\r\n```\r\n\r\n#### `getLogger()`\r\nReturns the root logger instance.\r\n\r\n```typescript\r\nconst rootLogger = getLogger();\r\nrootLogger.setLevel(LogLevel.DEBUG);\r\n```\r\n\r\n### Logger Interface\r\n\r\n```typescript\r\ninterface Logger {\r\n  debug(message: string, meta?: Record<string, any>): void;\r\n  info(message: string, meta?: Record<string, any>): void;\r\n  warn(message: string, meta?: Record<string, any>): void;\r\n  error(message: string, meta?: Record<string, any>): void;\r\n  setLevel(level: LogLevel): void;\r\n  getLevel(): LogLevel;\r\n}\r\n```\r\n\r\n### Log Levels\r\n\r\n```typescript\r\nenum LogLevel {\r\n  DEBUG = 0,\r\n  INFO = 1,\r\n  WARN = 2,\r\n  ERROR = 3\r\n}\r\n```\r\n\r\n### Usage Examples\r\n\r\n#### Basic Logging\r\n\r\n```typescript\r\nconst logger = createScopedLogger('DataService');\r\n\r\n// Simple messages\r\nlogger.debug('Fetching user data');\r\nlogger.info('Data loaded successfully');\r\nlogger.warn('Cache is getting full');\r\nlogger.error('Failed to load data');\r\n```\r\n\r\n#### Structured Logging with Metadata\r\n\r\n```typescript\r\nconst logger = createScopedLogger('API');\r\n\r\n// With metadata\r\nlogger.info('API request completed', {\r\n  endpoint: '/api/users',\r\n  method: 'GET',\r\n  duration: 234,\r\n  status: 200\r\n});\r\n\r\nlogger.error('API request failed', {\r\n  endpoint: '/api/users',\r\n  method: 'POST',\r\n  error: 'Network timeout',\r\n  retryCount: 3\r\n});\r\n```\r\n\r\n#### Performance Tracking\r\n\r\n```typescript\r\nconst logger = createScopedLogger('Performance');\r\n\r\nfunction trackOperation(name: string, operation: () => Promise<any>) {\r\n  const startTime = performance.now();\r\n  \r\n  return operation()\r\n    .then(result => {\r\n      const duration = performance.now() - startTime;\r\n      logger.info(`Operation completed: ${name}`, { duration, success: true });\r\n      return result;\r\n    })\r\n    .catch(error => {\r\n      const duration = performance.now() - startTime;\r\n      logger.error(`Operation failed: ${name}`, { duration, error: error.message });\r\n      throw error;\r\n    });\r\n}\r\n```\r\n\r\n## ⚙️ Configuration\r\n\r\n### Environment-Based Configuration\r\n\r\n```typescript\r\nimport { getLogger, LogLevel } from '@atlantis-gr/svelte-logging-abstractions';\r\n\r\n// Configure based on environment\r\nconst isDevelopment = import.meta.env.DEV;\r\nconst rootLogger = getLogger();\r\n\r\nif (isDevelopment) {\r\n  rootLogger.setLevel(LogLevel.DEBUG);\r\n} else {\r\n  rootLogger.setLevel(LogLevel.WARN);\r\n}\r\n```\r\n\r\n### Custom Log Formatters\r\n\r\n```typescript\r\nimport { getLogger } from '@atlantis-gr/svelte-logging-abstractions';\r\n\r\nconst logger = getLogger();\r\n\r\n// Custom formatter (if supported by implementation)\r\nlogger.setFormatter((level, scope, message, meta) => {\r\n  const timestamp = new Date().toISOString();\r\n  const metaStr = meta ? ` ${JSON.stringify(meta)}` : '';\r\n  return `${timestamp} [${level}] ${scope}: ${message}${metaStr}`;\r\n});\r\n```\r\n\r\n## 🔍 Advanced Usage\r\n\r\n### Conditional Logging\r\n\r\n```typescript\r\nconst logger = createScopedLogger('ConditionalLogger');\r\n\r\n// Only log in development\r\nif (import.meta.env.DEV) {\r\n  logger.debug('Debug information');\r\n}\r\n\r\n// Log with conditions\r\nfunction logUserAction(action: string, user: User) {\r\n  if (user.isAdmin) {\r\n    logger.warn(`Admin action performed: ${action}`, { userId: user.id });\r\n  } else {\r\n    logger.info(`User action: ${action}`, { userId: user.id });\r\n  }\r\n}\r\n```\r\n\r\n### Error Boundary Logging\r\n\r\n```svelte\r\n<script>\r\n  import { createScopedLogger } from '@atlantis-gr/svelte-logging-abstractions';\r\n  \r\n  const logger = createScopedLogger('ErrorBoundary');\r\n  \r\n  function handleError(error) {\r\n    logger.error('Component error caught', {\r\n      error: error.message,\r\n      stack: error.stack,\r\n      component: 'MyComponent'\r\n    });\r\n  }\r\n</script>\r\n\r\n{#if errorState}\r\n  <div class=\"error-message\">\r\n    Something went wrong. Please try again.\r\n  </div>\r\n{/if}\r\n```\r\n\r\n### Integration with Error Tracking\r\n\r\n```typescript\r\nimport { createScopedLogger } from '@atlantis-gr/svelte-logging-abstractions';\r\n\r\nconst logger = createScopedLogger('ErrorTracking');\r\n\r\n// Custom error handler that logs and reports\r\nfunction handleApplicationError(error: Error, context?: Record<string, any>) {\r\n  // Log locally\r\n  logger.error('Application error', {\r\n    message: error.message,\r\n    stack: error.stack,\r\n    ...context\r\n  });\r\n  \r\n  // Report to external service (Sentry, etc.)\r\n  if (typeof window !== 'undefined' && window.Sentry) {\r\n    window.Sentry.captureException(error, { extra: context });\r\n  }\r\n}\r\n```\r\n\r\n## 🧪 Testing\r\n\r\n### Testing with Loggers\r\n\r\n```typescript\r\nimport { createScopedLogger } from '@atlantis-gr/svelte-logging-abstractions';\r\nimport { vi } from 'vitest';\r\n\r\ndescribe('UserService', () => {\r\n  let logger: Logger;\r\n  \r\n  beforeEach(() => {\r\n    logger = createScopedLogger('UserService');\r\n    // Mock console methods if needed\r\n    vi.spyOn(console, 'log');\r\n    vi.spyOn(console, 'warn');\r\n    vi.spyOn(console, 'error');\r\n  });\r\n  \r\n  afterEach(() => {\r\n    vi.restoreAllMocks();\r\n  });\r\n  \r\n  test('logs user creation', () => {\r\n    const userService = new UserService(logger);\r\n    userService.createUser({ name: 'John' });\r\n    \r\n    expect(console.log).toHaveBeenCalledWith(\r\n      expect.stringContaining('User created')\r\n    );\r\n  });\r\n});\r\n```\r\n\r\n### Development vs Production\r\n\r\n```typescript\r\n// development.ts\r\nimport { getLogger, LogLevel } from '@atlantis-gr/svelte-logging-abstractions';\r\n\r\nexport function setupDevelopmentLogging() {\r\n  const logger = getLogger();\r\n  logger.setLevel(LogLevel.DEBUG);\r\n  \r\n  // Enhanced logging for development\r\n  const originalError = console.error;\r\n  console.error = (...args) => {\r\n    logger.error('Console error', { args });\r\n    originalError.apply(console, args);\r\n  };\r\n}\r\n\r\n// production.ts\r\nexport function setupProductionLogging() {\r\n  const logger = getLogger();\r\n  logger.setLevel(LogLevel.ERROR);\r\n  \r\n  // Send errors to monitoring service\r\n  logger.setErrorHandler((message, meta) => {\r\n    // Send to monitoring service\r\n    fetch('/api/logs', {\r\n      method: 'POST',\r\n      body: JSON.stringify({ message, meta, timestamp: new Date() })\r\n    });\r\n  });\r\n}\r\n```\r\n\r\n## 📊 Performance Considerations\r\n\r\n### Lazy Logging\r\n\r\n```typescript\r\nconst logger = createScopedLogger('Performance');\r\n\r\n// Expensive computation for debug info\r\nlogger.debug(() => {\r\n  const expensiveData = computeExpensiveDebugInfo();\r\n  return `Debug info: ${JSON.stringify(expensiveData)}`;\r\n});\r\n\r\n// Only computed if debug level is enabled\r\n```\r\n\r\n### Batched Logging\r\n\r\n```typescript\r\nclass BatchedLogger {\r\n  private batch: LogEntry[] = [];\r\n  private logger = createScopedLogger('BatchedLogger');\r\n  \r\n  constructor(private batchSize = 10, private flushInterval = 5000) {\r\n    setInterval(() => this.flush(), flushInterval);\r\n  }\r\n  \r\n  log(level: string, message: string, meta?: any) {\r\n    this.batch.push({ level, message, meta, timestamp: Date.now() });\r\n    \r\n    if (this.batch.length >= this.batchSize) {\r\n      this.flush();\r\n    }\r\n  }\r\n  \r\n  flush() {\r\n    if (this.batch.length > 0) {\r\n      this.logger.info('Batch log entries', { entries: this.batch });\r\n      this.batch = [];\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## 🤝 Contributing\r\n\r\nSee [CONTRIBUTING.md](../CONTRIBUTING.md) for development setup and guidelines.\r\n\r\n## 📄 License\r\n\r\nMIT License - see [LICENSE](../LICENSE) for details.\r\n\r\n## 🆘 Support\r\n\r\n- 📖 [Documentation](../README.md)\r\n- 🐛 [Issue Tracker](https://github.com/your-org/svelte-components/issues)\r\n- 💬 [Discussions](https://github.com/your-org/svelte-components/discussions)","readmeFilename":"README.md","_rev":"1-877cff8b5abbe74ac9bf7301bc9264b0"}