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.
- git clone the repository
- install packages
npm install
- install latest sciter sdk
npm run install-sdk
- start the demo
npm run scapp
- A recent version of Node.js
node
(tested with 16 LTS) and its package managernpm
.- On Windows download and run the installer
- On Linux check the installation guide
- install package
npm install sciter-logger
-
add the
src
dir to your project -
add to
<script type="module">
import Logger from "node_modules/sciter-logger/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");
Console is enhanced with new methods
console.debug("test debug");
console.exception("test exception");
console.note("test note");
console.line();
console.debug({
a: 1,
b: {
alpha: "test",
beta: "yet another test"
},
c: 3,
});
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" />
Logger.subscribe(function(level, message) {
});
- as each
Window
has its own console, you will need to use theconsole
object 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();
iframe
s behave just like Window
s in that aspect.
- open log file only once? would require non-exclusive rights to the file
- spawn a separate logging window
- add icons for each channel