Logging

This SDK ships with a TypeScript/JavaScript logger. It gives you:

  • Consistent log levels (DEBUG, INFO, WARNING, ERROR)
  • A verbosity switch to filter what shows in the JS console
  • An optional delegate so you can forward logs anywhere (remote logging, in‑app console, etc.)
  • Optional bridging of native logs to the JS console with a single configuration call

Concepts

  • Log levels (severity): WASLogLevel.DEBUG | INFO | WARNING | ERROR
  • Verbose level (filter): WASVerboseLevel controls which severities are printed to the JS console.
    • OFF → nothing
    • ERRORS → only errors
    • WARNINGS → warnings, errors (default)
    • INFO → info, warnings, errors
    • DEBUG → all
  • Delegate: optional receiver of all/filtered logs that you can implement.
  • Native logger: you can start/configure a native logger so that its logs are also visible in JS and/or forwarded to your delegate.

Console messages are prefixed to indicate the origin:

  • [WAS-js:LEVEL] → for logs generated in TypeScript or JavaScript
  • [WAS-native:LEVEL] → for logs coming from the native layer (iOS / Android) when enabled

Quick start

// 1) Choose what you want to see in the JS console. By default, only warnings and errors are printed.
WASLogger.verboseLevel = WASVerboseLevel.DEBUG; // print everything

// 2) Optionally, forward logs to your own sink
class MyLogger implements WASLoggerDelegate {
  readonly wasFollowVerboseLevel = true; // set false to always receive all logs
  wasLog(message: string, level: WASLogLevel) {
    // e.g., send to your remote logging
    // remote.send({ message, level });
  }
}
WASLogger.delegate = new MyLogger();

// 3) Optionally, include native logs in the same stream
await WASLogger.configureNativeLogger({
  verboseLevel: WASVerboseLevel.DEBUG, // controls native logger verbosity
  delegateFollowsVerboseLevel: true,   // if native delegate should follow the filter
});

// 4) Use it
WASLogger.info("Activation flow started");
WASLogger.warning(() => `Lazy message example: expensive data = ${JSON.stringify({ a: 1 })}`);
WASLogger.error("Something failed");

Writing logs

You can log with four helpers or the generic log() method:

WASLogger.debug("Verbose diagnostic");
WASLogger.info("Regular progress info");
WASLogger.warning("Non-critical issue");
WASLogger.error("Something went wrong");

// Generic
WASLogger.log("Message", WASLogLevel.INFO);

Tip: Every logging method accepts either a string or a function returning string. The function form is evaluated only if the message is emitted, so you can avoid building expensive strings when they would be filtered out:

WASLogger.debug(() => `Heavy dump: ${buildLargeStringOnlyWhenNeeded()}`);

Controlling verbosity

Set the global filter for messages printed to the JS console:

WASLogger.verboseLevel = WASVerboseLevel.WARNINGS; // default
// Other options: OFF | ERRORS | INFO | DEBUG
  • The filter applies to what is printed to the console.
  • Your delegate can either follow this filter or receive everything (see below).

Forwarding logs via a delegate

Implement WASLoggerDelegate if you need to forward logs, e.g., to a remote server, a file, or an in‑app log view.

class RemoteLogger implements WASLoggerDelegate {
  // When true, delegate receives only messages allowed by WASLogger.verboseLevel.
  // When false, delegate receives ALL messages regardless of the filter.
  readonly wasFollowVerboseLevel = false; // capture everything

  wasLog(message: string, level: WASLogLevel): void {
    // Example: send to your backend
    // fetch("/log", { method: "POST", body: JSON.stringify({ message, level }) });
  }
}

WASLogger.delegate = new RemoteLogger();

Notes

  • Setting wasFollowVerboseLevel to false is useful when you want a quiet console but a complete telemetry stream.
  • If wasFollowVerboseLevel is true, the delegate receives the same subset you see in the console.

Including native logs

On supported platforms, you can include native logs in the same stream and control their verbosity. Use a single call that configures the native logger and bridges those messages back to JS:

await WASLogger.configureNativeLogger({
  verboseLevel: WASVerboseLevel.INFO,      // native verbosity
  delegateFollowsVerboseLevel: true,       // native delegate behavior
});

Behavior

  • Native logs are printed to the console with the [WAS-native:LEVEL] prefix.
  • If your TypeScript delegate sets wasFollowVerboseLevel to false, it will receive native logs regardless of the current verbose filter.
  • You can call configureNativeLogger any time to change native verbosity at runtime.

Security note

  • DEBUG logs may contain sensitive data. Use DEBUG only during development or when strictly necessary and protected.

End-to-end setup example

This example shows a pragmatic setup for an app that wants detailed logs locally and a complete remote stream:

import {
  WASLogger,
  WASLogLevel,
  WASVerboseLevel,
  type WASLoggerDelegate,
} from "cordova-activation-spawn";

class Telemetry implements WASLoggerDelegate {
  readonly wasFollowVerboseLevel = false; // collect everything
  wasLog(message: string, level: WASLogLevel): void {
    // send to your telemetry endpoint
    // telemetry.send({ level, message, ts: Date.now() });
  }
}

export async function bootstrapLogging() {
  // Quiet enough console for production, but keep delegate unfiltered
  WASLogger.verboseLevel = WASVerboseLevel.INFO;
  WASLogger.delegate = new Telemetry();

  // Make native layer align with your chosen verbosity
  await WASLogger.configureNativeLogger({
    verboseLevel: WASVerboseLevel.INFO,
    delegateFollowsVerboseLevel: true,
  });
}

// later in code
WASLogger.info("Activation code requested");
WASLogger.debug(() => `Payload: ${buildPotentiallyLargePayload()}`);

FAQs

  • Do I need a delegate? No. If you do nothing, logs are simply printed to the console according to WASLogger.verboseLevel.
  • Can I turn logs off completely? Yes: set WASLogger.verboseLevel = WASVerboseLevel.OFF and configureNativeLogger({ verboseLevel: WASVerboseLevel.OFF })
  • Can I change verbosity at runtime? Yes. Both TypeScript and native verbosity can be updated any time (call configureNativeLogger for native).
Last updated on Oct 24, 2025 (11:10) Edit on Github Send Feedback

2.0.x

Activation Spawn SDK JS