.. role:: clio-readonly
   :class: clio-flag clio-flag-readonly

.. role:: clio-static
   :class: clio-flag clio-flag-static


##########
LogService
##########

.. js: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 :js:data:`LogEntry <wvc.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.
   
   .. rubric:: Examples
   
   
   .. code-block:: typescript
   
      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 } });
   
   .. rubric:: Events
   
   
   **hoops-log-service-entry**
   
   
      Emitted for every log entry with an :js:data:`LogEntry <wvc.LogEntry>` detail payload
   
   
   **hoops-log-service-reset**
   
   
      Emitted when the web viewer instance is changed
   
   
   
   Index
   =====
   
   .. rubric:: Constructors
   
   
   .. rst-class:: api-xref-list
   
   
   * :js:func:`~wvc.LogService.constructor`
   
   .. rubric:: Properties
   
   
   .. rst-class:: api-xref-list
   
   
   * :js:data:`~wvc.LogService.serviceName`
   
   .. rubric:: Accessors
   
   
   .. rst-class:: api-xref-list
   
   
   * :js:func:`~wvc.LogService.callbackMap`
   * :js:func:`~wvc.LogService.webViewer`
   
   .. rubric:: Methods
   
   
   .. rst-class:: api-xref-list
   
   
   * :js:meth:`~static wvc.LogService.getDefaultCallbackMap`
   * :js:meth:`~wvc.LogService.debug`
   * :js:meth:`~wvc.LogService.error`
   * :js:meth:`~wvc.LogService.info`
   * :js:meth:`~wvc.LogService.log`
   * :js:meth:`~wvc.LogService.warn`
   
   



.. rst-class:: kind-group kind-constructors

.. rubric:: Constructors
   :class: kind-group-title


.. js:method:: wvc.LogService.constructor

      .. rst-class:: sig-pretty-signature
      
         | LogService(**webViewer**\ : *IWebViewer*\ ): :js:class:`LogService <wvc.LogService>`
      
      Constructs a new LogService instance.
      
      **Parameters**
      
      
         **webViewer**\ : *IWebViewer*
      
      
            Optional web viewer instance to bind to immediately
      
      
      
      **Returns**\ : :js:class:`LogService <wvc.LogService>`
      
      .. rubric:: Examples
      
      
      .. code-block:: typescript
      
         // Create with immediate binding
         const logService = new LogService(viewer);
         
         // Create without binding (can be set later)
         const logService = new LogService();
         logService.webViewer = viewer;
      



.. rst-class:: kind-group kind-properties

.. rubric:: Properties
   :class: kind-group-title


.. js:data:: wvc.LogService.serviceName

      .. rst-class:: clio-flags
      
         :clio-readonly:`readonly`
      
      .. rst-class:: sig-pretty-signature
      
         | serviceName: *"LogService"*
      
      The service identifier used for registry lookup.
      



.. rst-class:: kind-group kind-accessors

.. rubric:: Accessors
   :class: kind-group-title


.. js:method:: wvc.LogService.callbackMap

      .. rst-class:: sig-pretty-signature
      
         | *get* callbackMap(): *Readonly*
      
      Gets the current callback map registered on the web viewer.
      
      **Returns**\ : *Readonly*
      
      
         A read-only reference to the active callback map
      
      
      .. rst-class:: sig-pretty-signature
      
         | *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*
      



.. js:method:: wvc.LogService.webViewer

      .. rst-class:: sig-pretty-signature
      
         | *get* webViewer(): (*undefined* | *IWebViewer*\ )
      
      Gets the current web viewer instance.
      
      **Returns**\ : (*undefined* \| *IWebViewer*\ )
      
      
         The web viewer instance, or undefined if not set
      
      
      .. rst-class:: sig-pretty-signature
      
         | *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*
      
      .. rubric:: Events
      
      
      **hoops-log-service-reset**
      
      
         When the web viewer reference changes
      
      



.. rst-class:: kind-group kind-methods

.. rubric:: Methods
   :class: kind-group-title


.. js:method:: static wvc.LogService.getDefaultCallbackMap

      .. rst-class:: clio-flags
      
         :clio-static:`static`
      
      .. rst-class:: sig-pretty-signature
      
         | getDefaultCallbackMap(**logger**\ : :js:class:`LogService <wvc.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**\ : :js:class:`LogService <wvc.LogService>`
      
      
            The LogService instance used to emit log entries
      
      
      
      **Returns**\ : *CallbackMap*
      
      
         A CallbackMap suitable for registration on a web viewer
      
      



.. js:method:: wvc.LogService.debug

      .. rst-class:: sig-pretty-signature
      
         | 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*
      



.. js:method:: wvc.LogService.error

      .. rst-class:: sig-pretty-signature
      
         | 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*
      



.. js:method:: wvc.LogService.info

      .. rst-class:: sig-pretty-signature
      
         | 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*
      



.. js:method:: wvc.LogService.log

      .. rst-class:: sig-pretty-signature
      
         | 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*
      
      .. rubric:: Events
      
      
      **hoops-log-service-entry**
      
      
         Dispatched with the complete :js:data:`LogEntry <wvc.LogEntry>` as detail
      
      



.. js:method:: wvc.LogService.warn

      .. rst-class:: sig-pretty-signature
      
         | 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*
      




