Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# screenlog.js [![npm version](https://badge.fury.io/js/screenlog.svg)](http://badge.fury.io/js/screenlog)
# screenlogx (forked from https://github.com/chinchang/screenlog.js)

_Bring console.log, on the screen_

Expand Down Expand Up @@ -36,6 +36,8 @@ Initializes the screen logger. It creates a customizable panel on the screen.
- `fontSize` - Font size of logs. Default is `1em`(Your browser's default).
- `bgColor` - Background color of the log panel. Default is `black`.
- `releaseConsole` - By default console.log is overridden to log on screen. You can avoid this behaviour by setting `releaseConsole` to `true` and instead use `screenLog.log()` API. Default is `false`.
- `minLogLevel` - minimum log level that to be displayed on the screen. Can beL `log`, `info`, `warn`, `error`. Default is `warn`
- `getVisualArgs` - function to allow visual log param customisation: function(logLevel, args) { ... return newArguments; }

### screenLog.[log, warn, error, info](obj1 [, obj2, ..., objN])

Expand Down
5 changes: 0 additions & 5 deletions dist/screenlog.min.js

This file was deleted.

48 changes: 45 additions & 3 deletions screenlog.js → dist/screenlogx.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
/*! screenlogx - v0.3.2 - 2022-07-14
* https://github.com/gabriel-deliu/screenlog.js
* Copyright (c) 2022 Kushagra Gour; Licensed */

(function() {
var logEl,
isInitialized = false,
_console = {}; // backup console obj to contain references of overridden fns.
_options = {
var _options = {
bgColor: "black",
logColor: "lightgreen",
debugColor: "lightblue",
infoColor: "blue",
warnColor: "orange",
errorColor: "red",
fontSize: "1em",
freeConsole: false,
css: "",
autoScroll: true
autoScroll: true,
getVisualArgs: function(logLevel, args) { return [Date.now(), logLevel].concat(Array.prototype.slice.call(args)); },
minLogLevel: "info",
filterPattern: /^.*$/
};
var logLevel = {
log: 1,
debug: 2,
info: 3,
warn: 4,
error: 5
};

function createElement(tag, css) {
Expand Down Expand Up @@ -42,6 +57,7 @@
";color:" +
color
); // zebra lines

var val = [].slice.call(arguments).reduce(function(prev, arg) {
return (
prev + " " + (typeof arg === "object" ? JSON.stringify(arg) : arg)
Expand All @@ -66,6 +82,10 @@
return genericLogger(_options.logColor).apply(null, arguments);
}

function debug() {
return genericLogger(_options.debugColor).apply(null, arguments);
}

function info() {
return genericLogger(_options.infoColor).apply(null, arguments);
}
Expand Down Expand Up @@ -102,11 +122,13 @@
if (!_options.freeConsole) {
// Backup actual fns to keep it working together
_console.log = console.log;
_console.debug = console.debug;
_console.clear = console.clear;
_console.info = console.info;
_console.warn = console.warn;
_console.error = console.error;
console.log = originalFnCallDecorator(log, "log");
console.debug = originalFnCallDecorator(debug, "debug");
console.clear = originalFnCallDecorator(clear, "clear");
console.info = originalFnCallDecorator(info, "info");
console.warn = originalFnCallDecorator(warn, "warn");
Expand All @@ -117,6 +139,7 @@
function destroy() {
isInitialized = false;
console.log = _console.log;
console.debug = _console.debug;
console.clear = _console.clear;
console.info = _console.info;
console.warn = _console.warn;
Expand Down Expand Up @@ -154,7 +177,25 @@
*/
function originalFnCallDecorator(fn, fnName) {
return function() {
fn.apply(this, arguments);

var isMatch = false;

for(var key in arguments) {
if(typeof arguments[key] === "string") {
if(!_options.filterPattern || _options.filterPattern.test(arguments[key])) {
isMatch = true;
break;
}
}
}

if(!isMatch) {
return;
}

if(logLevel[_options.minLogLevel] && logLevel[fnName] >= logLevel[_options.minLogLevel]) {
fn.apply(this, _options.getVisualArgs(fnName, arguments));
}
if (typeof _console[fnName] === "function") {
_console[fnName].apply(console, arguments);
}
Expand All @@ -165,6 +206,7 @@
window.screenLog = {
init: init,
log: originalFnCallDecorator(checkInitDecorator(log), "log"),
debug: originalFnCallDecorator(checkInitDecorator(debug), "debug"),
clear: originalFnCallDecorator(checkInitDecorator(clear), "clear"),
info: originalFnCallDecorator(checkInitDecorator(clear), "info"),
warn: originalFnCallDecorator(checkInitDecorator(warn), "warn"),
Expand Down
5 changes: 5 additions & 0 deletions dist/screenlogx.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions example.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<title></title>
</head>
<body>
<script src="screenlog.js"></script>
<script src="screenlogx.js"></script>

<script>
screenLog.init({ autoScroll: false });
screenLog.init({ autoScroll: false, minLogLevel: 'debug' });
screenLog.log('String: Hello world');
screenLog.log('Numbers: ' + 124);
screenLog.log(21, 'multiple arguments');
Expand All @@ -20,6 +20,7 @@
var i = 10;
function log() {
console.log('Future log', Date.now());
console.debug('Future debug', Date.now());
console.error('Future error', Date.now());
console.warn('Future warn', Date.now());
console.info('Future info', Date.now());
Expand Down
Loading