Skip to main content

LoggerInstance.writeLog

Write a log entry. Accepts any number of arguments, which are serialized appropriately.

Syntax​

writeLog(...args: any[]): void

Parameters​

...args (required)​

Any number of arguments to log. The following types are handled:

  • Strings: Kept as-is
  • Errors: Serialized with message and stack trace
  • Objects: JSON stringified
  • Arrays: JSON stringified
  • Multiple arguments: Joined with spaces

Examples​

Simple Messages​

const appLogger = logger.createInstance('app');

appLogger.writeLog('Application started');
appLogger.writeLog('User logged in');
appLogger.writeLog('Processing payment');

With Data​

const apiLogger = logger.createInstance('api');

appLogger.writeLog('User ID:', 12345);
appLogger.writeLog('Status:', 'success');
appLogger.writeLog('Count:', 42);

Logging Errors​

const errorLogger = logger.createInstance('errors');

try {
riskyOperation();
} catch (error) {
errorLogger.writeLog('Operation failed:', error);
// Error message and stack trace are automatically captured
}

Logging Objects​

const apiLogger = logger.createInstance('api');

apiLogger.writeLog('User data:', {
id: 123,
name: 'John Doe',
email: 'john@example.com'
});

Logging Arrays​

const apiLogger = logger.createInstance('api');

apiLogger.writeLog('Items:', [1, 2, 3, 4, 5]);
apiLogger.writeLog('Users:', ['Alice', 'Bob', 'Charlie']);

Multiple Arguments​

const apiLogger = logger.createInstance('api');

apiLogger.writeLog('Request:', 'GET', '/api/users', { status: 200 });
apiLogger.writeLog('Error:', 'Network timeout', 'Retrying...');

Behavior​

  • If logging is disabled globally or for this instance, this method does nothing (unless console logging is enabled)
  • Logs are written asynchronously to IndexedDB (fire-and-forget)
  • Errors during storage are caught and logged to console
  • Logs are batched and written every 100ms for performance

Notes​

  • The method is synchronous but the actual storage operation is asynchronous
  • Logs are queued and written in batches
  • If the log limit is reached, oldest entries are automatically trimmed
  • Timestamps are added automatically if timestamps are enabled

See Also​