โ† Back to Index ๐Ÿ” Login

JSWSLogClient

[ ] Denna sida รคr inte markerad som klar

Delegate log messages to WSLogRelayd centralized log server.

Declaration

class JSWSLogClient

Returns

Sends entries to log server.

If connection to server is lost, messages in calls to %name.log() are printed in the console.

Long Description

Meant to be used in development version of website client side.

Do not override console.log setting it to call JSWSLogClient.log(), leads to endless recursion.

JSWSLogClient autoconnects on disconnect.

JSWSLogClient sends the NETWORK_CONNECTION signal. It means [...]

Connection to server is considered established when server has confirmed the JSWSLogClient's role as sender by its protocol.

Features:

Design choice

If calls to JSWSLogClient.log() are done before connection to server is up, a queue can be used, but it adds complexity over the simpler solution of just refusing to send anything unless server has confirmed. The use case of printing logs at early load of page for example (before JSWSLogClient has had opportunity to connect over network) isn't great.

An internal queue would be intuitive, but is often surprisingly non-trivial to implement securely.

Usage:

Import and instantiate the class.

Suggestion: Bind to global function:

var logger = new JSWSLogClient(
  "wss://address",
  "your-token",
  "JSWSLogClient",
);
window.l = logger.log.bind(logger);

Then just use as l("My log message")

Metadata

UUID 0198236f-ef06-73ff-a59f-d5f04c98dda7
Project Dev stack: Diagnostics
Language js
File Path ./js/jswslogclient.js
Scope
Modifiers
Created 2025-07-19 16:08:57
Modified 2025-07-20 11:02:59