1.2.1 • Published 8 months ago
sciter-logger v1.2.1
sciter logger
This is a sciter.js logger that listens to the console output and redirects it to a file and/or any html element.

This work was made possible thanks to https://2ality.com/2015/10/intercepting-method-calls.html.
demo
- git clone the repository
- install packages
npm install - install latest sciter sdk
npm run install-sdk - start the demo
npm run scapp
demo requirements
- A recent version of Node.js
node(tested with 22 LTS) and its package managernpm.- On Windows download and run the installer
- On Linux check the installation guide
add to your project
You can either add it to your project using npm or by copying the src directory.
using npm
- install package
npm install sciter-logger
copy source
- add the
srcdir to your project
add to <script type="module">
// npm
import Logger from "node_modules/sciter-logger/src/logger.js";
// or source copy
import Logger from "src/logger.js";
// initialize logger
Logger.init({
url: __DIR__ + "%DATE%.log",
clear: true,
});
// attach logger to console
Logger.attach();
// capture unhandled exceptions
Logger.capture();
// log
console.log("new logger test");enhanced console
Console is enhanced with new methods
console.debug("test debug");
console.exception("test exception");
console.note("test note");
console.line();objects can be logged
console.debug({
a: 1,
b: {
alpha: "test",
beta: "yet another test"
},
c: 3,
});redirect console output
Console output can be redirected to a plaintext element
Logger.plaintext(document.$("plaintext"));Output can be colored if you include the stylesheet
<style src="node_modules/sciter-logger/src/logger.css" />subscribe to logger
Logger.subscribe(function(level, message) {
});multiple windows and iframes
- as each
Windowhas its own console, you will need to use theconsoleobject from the parent window:
import Logger from "src/logger.js";
// get console from parent
Logger.setConsole();- unhandled exceptions must also be captured in every new
Window.
import Logger from "src/logger.js";
// capture unhandled exceptions
Logger.capture();iframes behave just like Windows in that aspect.
ideas
- open log file only once? would require non-exclusive rights to the file
- spawn a separate logging window
- add icons for each channel