A lightweight WebSocket client for sending logs to a remote logger server. Perfect for debugging frontend applications, mobile apps, or any JavaScript application where you need real-time log aggregation.
Note: This client requires the remote-logger-server to be running. This is a development tool intended for logging and debugging purposes.
- π Auto-reconnect - Automatically reconnects if the connection is lost (3-second retry)
- π Caller tracking - Automatically captures file, line, and column information
- π‘οΈ Fallback behavior - Falls back to
console.logwhen disconnected - π Simple API - Easy-to-use interface with method chaining
- π― Multi-app support - Tag logs with application names for better organization
- π¦ Zero configuration - Works out of the box with sensible defaults
npm install @khalidsheet/remote-logger-client
# or
pnpm add @khalidsheet/remote-logger-client
# or
yarn add @khalidsheet/remote-logger-clientMake sure you have the remote logger server running:
npm install -g remote-logger-server
remote-logger-serverThe server will start on port 4455 by default.
import { createLogger } from "@khalidsheet/remote-logger-client";
const logger = createLogger("MyApp");
logger.log("Hello, world!");
logger.log("User logged in:", { userId: 123, username: "john" });
logger.log("API response:", response);import { RemoteLoggerClient } from "@khalidsheet/remote-logger-client";
const logger = new RemoteLoggerClient("MyApp", 4455);
logger.log("Application started");logger.log("Step 1 complete").log("Step 2 complete").log("All steps done!");Factory function to create a new logger instance.
Parameters:
app(string, optional) - Application name to identify logs. Default:"default"port(number, optional) - WebSocket server port. Default:4455
Returns: RemoteLoggerClient instance
Example:
const logger = createLogger("MyApp", 4455);Constructor for creating a logger instance directly.
Parameters:
app(string, optional) - Application name. Default:"default"port(number, optional) - WebSocket server port. Default:4455
Example:
const logger = new RemoteLoggerClient("MyApp", 4455);Send logs to the remote server. Accepts any number of arguments of any type.
Parameters:
...args(any[]) - Values to log (same asconsole.log)
Returns: this (for method chaining)
Example:
logger.log("Simple message");
logger.log("Multiple", "arguments", 123, true);
logger.log("Object:", { foo: "bar" });
logger.log("Array:", [1, 2, 3]);- Connection: The client automatically connects to the WebSocket server on instantiation
- Logging: When you call
logger.log(), it sends the data to the server with:- Application name
- Log message(s)
- Caller information (file path, line, and column)
- Fallback: If disconnected, logs are sent to
console.loginstead - Auto-reconnect: The client automatically attempts to reconnect every 3 seconds if the connection is lost
The client sends logs in the following JSON format:
{
"app": "MyApp",
"message": ["Log message", { "data": "value" }],
"caller": "http://localhost:3000/src/App.tsx:42:15"
}When you send logs, they appear on the server console in this format:
12:34:56 PM [MyApp] [App.tsx:42:15] Log message { data: "value" }
If your remote logger server is running on a different port:
const logger = createLogger("MyApp", 8080);You can create separate loggers for different parts of your application:
const authLogger = createLogger("Auth");
const apiLogger = createLogger("API");
const uiLogger = createLogger("UI");
authLogger.log("User logged in");
apiLogger.log("Fetching data from /api/users");
uiLogger.log("Modal opened");Works in all modern browsers that support WebSocket:
- Chrome/Edge
- Firefox
- Safari
- Opera
- Modern JavaScript environment with WebSocket support
- Remote Logger Server running (usually on localhost:4455)
pnpm install
pnpm buildBuilds the project using tsdown and outputs to the dist/ directory in both CommonJS and ESM formats.
@khalidsheet/remote-logger-client/
βββ src/
β βββ main.ts # Client implementation
βββ dist/ # Built files
βββ package.json
βββ tsconfig.json
βββ tsdown.config.ts # Build configuration
-
Make sure the remote logger server is running:
remote-logger-server
-
Check the browser console for connection messages:
[@khalidsheet/remote-logger-client] [MyApp] Connected. -
Verify the port matches between client and server (default: 4455)
If you see constant reconnection attempts, the server might not be running or is unreachable. The client will fall back to console.log in the meantime.
MIT
- remote-logger-server - The server component for this client
Contributions are welcome! Feel free to open issues or submit pull requests.
Happy Hacking!