Lime Web Components API Documentation - v7.4.0
    Preparing search index...

    Interface LoggerBeta

    Logger service for writing log messages to configured handlers

    Loggers are created from a LoggerFactory with a specific scope/category. All log messages written to a logger will be sent to all handlers configured in the factory.

    import { createLogger } from '@limetech/lime-web-components';

    const logger = createLogger('my-component');

    logger.info('Component initialized');
    logger.debug('Processing data', { itemCount: 42 });
    logger.warn('Deprecated API usage detected');

    try {
    await fetch('/api/data');
    } catch (error) {
    logger.error('Failed to fetch data', asError(error), { url: '/api/data' });
    }

    function asError(value: unknown): Error | undefined {
    return value instanceof Error ? value : undefined;
    }
    interface Logger {
        scope: string;
        debug(message: string, data?: LogData): void;
        error(message: string, error?: Error, data?: LogData): void;
        info(message: string, data?: LogData): void;
        warn(message: string, data?: LogData): void;
    }
    Index

    Properties

    Methods

    Properties

    scope: string

    The scope/category for this logger instance

    Methods

    • Beta

      Logs a debug message

      Use for detailed diagnostic information useful during development and troubleshooting. Debug logs are typically disabled in production and should include technical details like internal state, intermediate values, or execution flow.

      Parameters

      • message: string

        The log message

      • Optionaldata: LogData

        Optional additional data to include with the log entry

      Returns void

      import {
      createLogger,
      PlatformServiceName,
      } from '@limetech/lime-web-components';

      const logger = createLogger('my-component');
      const http = platform.get(PlatformServiceName.Http);
      const cache = new Map<string, unknown>();

      const cacheKey = 'user:123';
      let user = cache.get(cacheKey);

      if (user === undefined) {
      logger.debug('Cache miss, fetching from API', { key: cacheKey });

      user = await http.get('user/123');
      cache.set(cacheKey, user);
      }

      logger.debug('Rendering component', {
      limetype: context.limetype,
      id: context.id,
      });
    • Beta

      Logs an error message

      Use for failures and exceptions that prevent normal operation or indicate something has gone wrong. Error logs should always describe what failed and include relevant context to aid in diagnosis.

      Parameters

      • message: string

        The log message

      • Optionalerror: Error

        Optional error object

      • Optionaldata: LogData

        Optional additional data to include with the log entry

      Returns void

      import {
      createLogger,
      PlatformServiceName,
      } from '@limetech/lime-web-components';

      const logger = createLogger('my-component');
      const http = platform.get(PlatformServiceName.Http);

      const userId = 123;

      try {
      await http.get(`user/${userId}`);
      } catch (error) {
      logger.error('Failed to fetch user data', asError(error), { userId });
      }

      const invalidConfig = { retries: -1 };

      if (invalidConfig.retries < 0) {
      logger.error('Invalid configuration detected', undefined, {
      config: invalidConfig,
      });
      }

      function asError(value: unknown): Error | undefined {
      return value instanceof Error ? value : undefined;
      }
    • Beta

      Logs an informational message

      Use for significant application events that represent normal behavior. Info logs should capture key milestones, successful operations, or state transitions that are useful for understanding application flow in production.

      Parameters

      • message: string

        The log message

      • Optionaldata: LogData

        Optional additional data to include with the log entry

      Returns void

      import {
      createLogger,
      PlatformServiceName,
      } from '@limetech/lime-web-components';

      const logger = createLogger('my-component');
      const application = platform.get(PlatformServiceName.Application);
      const user = application.getCurrentUser();

      if (user) {
      logger.info('User authenticated', { userId: user.id });
      }

      logger.info('File uploaded successfully', {
      filename: 'report.pdf',
      size: 2048,
      });
    • Beta

      Logs a warning message

      Use for unexpected situations that don't prevent the application from functioning but may indicate potential issues, deprecated usage, or suboptimal conditions. Warnings should be actionable and suggest something that may need attention.

      Parameters

      • message: string

        The log message

      • Optionaldata: LogData

        Optional additional data to include with the log entry

      Returns void

      import {
      createLogger,
      PlatformServiceName,
      } from '@limetech/lime-web-components';

      const logger = createLogger('my-component');
      const http = platform.get(PlatformServiceName.Http);

      const threshold = 3000;
      const startedAt = Date.now();

      await http.get('deal');

      const duration = Date.now() - startedAt;

      if (duration > threshold) {
      logger.warn('API response time exceeded threshold', {
      duration,
      threshold,
      });
      }

      logger.warn('Using deprecated configuration option', {
      option: 'legacy_mode',
      });