LogService

class wvc.LogService()

Stateless log service that bridges the HOOPS Web Viewer with external log consumers.

The service intercepts viewer callbacks (errors, warnings, timeouts, etc.) and normalizes them into LogEntry objects dispatched as hoops-log-service-entry custom events. It does not store log entries — consumers subscribe to events and decide how to persist or display them.

The service can also be used independently of the web viewer to emit application-level log entries via the log, debug, info, warn, and error methods. Custom log levels are supported through the log method by passing any string as the level field.

The callback map can be replaced at runtime to customize which viewer events are captured and how they are translated into log entries.

Examples

const logService = new LogService(webViewer);
logService.addEventListener('hoops-log-service-entry', (e) => {
  const entry = e.detail;
  showSnackbar(entry.level, entry.message);
});

// Log application-level messages (no web viewer required)
logService.info('User opened settings panel');

// Use a custom log level
logService.log({ level: 'trace', message: 'Entered rendering loop', context: { fps: 60 } });

Events

hoops-log-service-entry

Emitted for every log entry with an LogEntry detail payload

hoops-log-service-reset

Emitted when the web viewer instance is changed

Index

Constructors

Properties

Accessors

Methods

Constructors

wvc.LogService.constructor()
LogService(webViewer: IWebViewer): LogService

Constructs a new LogService instance.

Parameters

webViewer: IWebViewer

Optional web viewer instance to bind to immediately

Returns: LogService

Examples

// Create with immediate binding
const logService = new LogService(viewer);

// Create without binding (can be set later)
const logService = new LogService();
logService.webViewer = viewer;

Properties

wvc.LogService.serviceName

readonly

serviceName: “LogService”

The service identifier used for registry lookup.

Accessors

wvc.LogService.callbackMap()
get callbackMap(): Readonly

Gets the current callback map registered on the web viewer.

Returns: Readonly

A read-only reference to the active callback map
set callbackMap(callbackMap: CallbackMap): void

Replaces the callback map used to intercept web viewer events.

Unbinds the previous map and binds the new one if a web viewer is set.

Parameters

callbackMap: CallbackMap

The new callback map to register

Returns: void

wvc.LogService.webViewer()
get webViewer(): (undefined | IWebViewer)

Gets the current web viewer instance.

Returns: (undefined | IWebViewer)

The web viewer instance, or undefined if not set
set webViewer(webViewer: (undefined | IWebViewer)): void

Sets the web viewer instance.

Unbinds from the previous viewer (if any), updates the reference, and binds to the new viewer. Dispatches a hoops-log-service-reset event on change.

Parameters

webViewer: (undefined | IWebViewer)

The new web viewer instance, or undefined to unbind

Returns: void

Events

hoops-log-service-reset

When the web viewer reference changes

Methods

static wvc.LogService.getDefaultCallbackMap()

static

getDefaultCallbackMap(logger: LogService): CallbackMap

Creates the default callback map that translates web viewer events into log entries.

Handles: info, missingModel, modelLoadFailure, timeout, timeoutWarning, webGlContextLost, websocketConnectionClosed, and XHRonerror.

Parameters

logger: LogService

The LogService instance used to emit log entries

Returns: CallbackMap

A CallbackMap suitable for registration on a web viewer
wvc.LogService.debug()
debug(message: string, context: Record): void

Emits a debug-level log entry.

Parameters

message: string

Human-readable debug message

context: Record

Optional structured context for additional metadata

Returns: void

wvc.LogService.error()
error(message: string, context: Record): void

Emits an error-level log entry.

Parameters

message: string

Human-readable error message

context: Record

Optional structured context for additional metadata

Returns: void

wvc.LogService.info()
info(message: string, context: Record): void

Emits an info-level log entry.

Parameters

message: string

Human-readable informational message

context: Record

Optional structured context for additional metadata

Returns: void

wvc.LogService.log()
log(entry: Omit): void

Emits a log entry event with an automatically generated timestamp.

Parameters

entry: Omit

Log entry without the timestamp field

Returns: void

Events

hoops-log-service-entry

Dispatched with the complete LogEntry as detail
wvc.LogService.warn()
warn(message: string, context: Record): void

Emits a warn-level log entry.

Parameters

message: string

Human-readable warning message

context: Record

Optional structured context for additional metadata

Returns: void