Registry / observability / jsnlog

jsnlog

JSON →
library2.30.0jsnpmunverified

JSNLog.js is a compact (2kb min+gz) JavaScript logging library, currently at version 2.30.0, designed for both client-side and Node.js server-side environments. Its primary utility lies in enabling client-side log messages (such as exceptions or AJAX timeouts) to be sent and stored in existing server-side logging infrastructures, including .Net (supporting Log4net, Nlog, Elmah), PHP, and Node.js (via Winston transports). The library is notable for its extensive configuration options, allowing developers to precisely control and filter log data to minimize network traffic and storage, ensuring only relevant information is processed. Despite its utility and robust feature set, the project has been in maintenance mode for approximately five years, with no new releases or significant commits during that period, indicating an inactive development status, though it continues to be downloaded and used in existing projects. It ships with TypeScript type definitions, facilitating its use in modern TypeScript-based applications.

npm install jsnlog
INSTALL
IMPORT
SIG · JSNLOG
J
jsnlog
observabilityjavascriptv2.30.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

JL
✓ import { JL } from 'jsnlog';
✗ import JL from 'jsnlog';
JSNLog exports 'JL' as a named export. Attempting a default import will result in a runtime error. This applies to consuming JSNLog in an ESM context.
JL (CommonJS)
✓ const JL = require('jsnlog').JL;
✗ const JSNLog = require('jsnlog'); JSNLog.JL().debug('message');
For CommonJS environments, the main JL logger instance is available as a property of the module export.
JL (Global)
✓ // With <script> tag inclusion: <script src="path/to/jsnlog.min.js"></script> JL().debug('message from global JL');
When JSNLog is included directly via a script tag in HTML, it exposes the 'JL' object globally. This is common for client-side usage without a module bundler.

This quickstart demonstrates setting up JSNLog for client-side logging, configuring it to send logs to a Node.js server, and integrating with a Winston logger on the server to process and store these client-side messages.

import { JL } from 'jsnlog'; import express from 'express'; import winston from 'winston'; import { JSNLogMiddleware } from 'jsnlog-nodejs'; // Assuming jsnlog-nodejs is installed for server-side // --- Client-side (in your frontend application) --- // Configure JSNLog to send logs to the /jsnlog endpoint on your server JL.setOptions({ "appenders": [ { "name": "ajaxAppender", "type": "ajax", "url": "/jsnlog", "level": "DEBUG", // Send all debug+ messages "bufferSize": 1, "batchSize": 5, "batchTimeout": 1000 } ], "defaultLogger": { "appenders": ["ajaxAppender"] } }); console.log('Client-side JSNLog configured. Sending logs to /jsnlog.'); // Example client-side logging JL().debug('This is a debug message from the client'); JL().info('An informational message from the client'); try { throw new Error('Something went wrong on the client!'); } catch (e: any) { JL().fatalException('Caught a client-side error!', e); } // --- Server-side (in your Node.js application) --- const app = express(); const PORT = process.env.PORT || 3000; // Configure Winston logger for server-side logging const serverLogger = winston.createLogger({ level: 'info', format: winston.format.json(), transports: [ new winston.transports.Console(), new winston.transports.File({ filename: 'combined.log' }), ], }); // Integrate JSNLog with Express and Winston app.use(JSNLogMiddleware(serverLogger)); app.get('/', (req, res) => { res.send('JSNLog example running. Check your client console and server logs!'); }); app.listen(PORT, () => { console.log(`Server listening on port ${PORT}`); console.log('Open your browser to http://localhost:3000 and check the network tab/console for client logs being sent.'); serverLogger.info('Server started and JSNLog middleware active.'); }); // To run this example: // 1. npm install jsnlog express winston jsnlog-nodejs // 2. Add "type": "module" to your package.json for ESM support if not already present. // 3. run `npx ts-node your-file.ts` (if using ts-node) or compile and run.
Debug
Known issues
gotchaJSNLog has been in an inactive maintenance state for approximately five years, with no new releases or significant commits. While stable, active development and new features are not expected.
fix
Be aware that community support may be limited and consider the long-term implications for new projects. Review the codebase for any potential unaddressed security concerns if integrating into critical systems.
affects: >=2.30.0
breakingWhen using ES Modules (ESM), importing JSNLog with a default import (e.g., `import JL from 'jsnlog';`) will result in a runtime `TypeError: jsnlog_1.JL is not a function`.
fix
Always use a named import for `JL`: `import { JL } from 'jsnlog';`.
affects: All versions supporting ESM (likely >=v2)
gotchaEffective client-side logging to a server requires a corresponding server-side handler (e.g., for Node.js, .Net, or PHP). The `jsnlog` npm package only provides the client-side library; server-side integration components (like `jsnlog-nodejs` for Winston) must be separately installed and configured.
fix
Refer to the JSNLog documentation (jsnlog.com / nodejs.jsnlog.com) for instructions on setting up the appropriate server-side handler for your backend technology.
affects: All versions
Errors
Common errors & fixes
TypeError: jsnlog_1.JL is not a function
Attempting to use `JL()` after importing JSNLog as a default ES module import (e.g., `import JL from 'jsnlog';`).
fix
Change the import statement to a named import: `import { JL } from 'jsnlog';`.
JL is not defined
The JSNLog library was not loaded or imported correctly in the current scope, or the script tag for client-side usage was placed after code attempting to use `JL`.
fix
Ensure JSNLog is either imported using `import { JL } from 'jsnlog';` in a module environment or that `jsnlog.min.js` is included via a `<script>` tag before any code that calls `JL()` in a global script environment.
Client-side logs are not appearing in server logs (e.g., Winston files)
The server-side JSNLog handler (e.g., `jsnlog-nodejs`) is not correctly installed, configured, or integrated with your server's logging framework (e.g., Winston), or the client-side `url` option for the AjaxAppender is incorrect.
fix
Verify that `jsnlog-nodejs` (or equivalent server-side package) is installed, its middleware is applied to your Express/Koa app, and it's correctly configured to use your Winston logger. Also, confirm the `url` in `JL.setOptions` matches your server's JSNLog endpoint.
Upgrade
Version history
2.30.0latest on npm
Audit
Dependencies
winstonoptionalRequired for Node.js server-side integration to handle and store client-side logs using Winston transports.
Agent activity
22 hits · last 30 days
node
18
OpenAI (training)
2
Resources
jsnlog — npm install jsnlog · libregistry