Teardown

Logging

Configure structured logging in the Teardown SDK.

The SDK includes a structured logging system for debugging and monitoring.

Log Levels

type LogLevel = 'none' | 'error' | 'warn' | 'info' | 'verbose';
LevelPriorityDescription
none0No logging
error1Only errors
warn2Errors and warnings
info3General information
verbose4Detailed debug output

Setting Log Level

const teardown = new TeardownCore({
  // ...options
});

// Set log level (default is 'verbose' during development)
teardown.setLogLevel('verbose');

Log Output

Each client logs with a prefix for easy filtering:

[Teardown:TeardownCore] TeardownCore initialized
[Teardown:IdentityClient] Identifying user with persona: John
[Teardown:ForceUpdateClient] Version status: up_to_date
[Teardown:DeviceClient] Device ID: 550e8400-e29b-41d4...

Log Methods

The internal Logger class provides these methods:

MethodLevel RequiredConsole Method
error()errorconsole.error
warn()warnconsole.warn
info()infoconsole.log
debug()verboseconsole.debug
trace()verboseconsole.trace

Debug Variants

Additional debug methods for categorized output:

logger.debugError('Something went wrong', { error });   // Error: [prefix] ...
logger.debugWarn('Warning message');                     // Warning: [prefix] ...
logger.debugInfo('Info message');                        // Info: [prefix] ...
logger.debugVerbose('Verbose details');                  // Verbose: [prefix] ...

Production Logging

For production builds, set log level to none or error:

const teardown = new TeardownCore({ /* ... */ });

if (__DEV__) {
  teardown.setLogLevel('verbose');
} else {
  teardown.setLogLevel('error');
}

Filtering Logs

Use the [Teardown: prefix to filter SDK logs in your console:

React Native Debugger:

Filter: [Teardown:

Xcode Console:

[Teardown:

Android Logcat:

adb logcat | grep "\[Teardown:"

Internal Architecture

The logging system consists of two classes:

LoggingClient

Central log level management:

class LoggingClient {
  setLogLevel(level: LogLevel): void;
  getLogLevel(): LogLevel;
  shouldLog(level: LogLevel): boolean;
  createLogger(options: { name: string }): Logger;
}

Logger

Individual logger instance with bound console methods:

class Logger {
  get prefix(): string;  // [Teardown:ClientName]
  info(message: string, ...args: unknown[]): void;
  error(message: string, ...args: unknown[]): void;
  warn(message: string, ...args: unknown[]): void;
  debug(message: string, ...args: unknown[]): void;
  trace(message: string, ...args: unknown[]): void;
}

Best Practices

  1. Use verbose in development - See all SDK activity
  2. Use error in production - Minimize noise, catch issues
  3. Filter by prefix - Isolate SDK logs from app logs
  4. Check log level first - Avoid expensive string operations:
if (core.logging.shouldLog('verbose')) {
  console.log('Complex debug:', JSON.stringify(largeObject));
}