A very lightweight library to create a production debugger with custom errors readable for humans. Includes errors in table format, logger and search methods with dynamic filters.
This library with zero dependencies was designed for debug/capture errors in development or production environment and obtain errors in background, with a readable format for any developer, also can disable console logs any time.
- Basic Initialization
- Log
- Listen global errors
- Get logs
- Search / Filter logs
- Send logs to API
- Export and download logs
- View logs in console
- Clean logger
- Default data of logs
- Set max logs and size
Demos
Installation
npm installation:
npm i xdebugger
Or without npm:
<!-- In development environment --> <!-- In production environment -->
How to use
Use XDebugger is really easy and very flexible, it's possible define debug
, log
, datatypes
, action
, default
and max
variables for different logs requirements.
Can use for debug development or in production website. Also if you want for example can load debug parameters via API, like { debug: true, log: false }
and obtain errors or custom logs if you set.
In case use npm:
;
Basic initialization
// In development environmentconst debug = debug: true log: true ; // In production environmentconst debug = debug: true ;
Set { log: false }
disable completely console. That's mean XDebugger, clean console for not show any log, info, warn, table and error. If try log anything console show:
Console was cleared> console;"Developer mode is disabled."
How log
You can log any data you want, also XDebugger add by default time
as String and timestamp
format as Number.
// Obviously you need initialize before!!// Example log => debug
How to listen errors
window debug;
How to get logs
debuglogged // Output =>>
How to search / filter logs
Search was based in MongoDB queries for filter. XDebugger have 6 types of filters:
$eq
: Match value of log key with query value key$cnt
: Contains value of log key with query value key$lte
: Less or equal value of log key with query value key$gte
: More or equal value of log key with query value key$lt
: Less value of log key with query value key$gt
: More value of log key with query value key
$eq
search
// Implicit searchdebug; // Explicit searchdebug;
$cnt
search
debug;
$lte
search
debug;
$lt
search
debug;
$gte
search
debug;
$gt
search
debug;
How set and send log per log to a API
const debug = debug: true { // Here your code to POST log } ;
How export and download logs
You can export all logs and download in a JSON
file.
debug;
Also can export filtered logs as follow:
debug;
How console logs in readable format
The view
function accept Array
or Object
, that mean one or more logs.
debug;
How to clean debugger
This clean logger and console.
debug;
How set default data
default
key in object initialization parameter allow set default data like browser, version, internalCode, etc.
// 'library' as third party source functionality const debug = debug: true default: browser: librarybrowsername version: librarybrowserversion language: librarybrowserlang ...;
Also you can rewrite default time
and timestamp
:
const debug = debug: true default: time: mycustomtime timestamp: mycustomtime;
How set max records and size of values log
length
: set the max records logger can savesize
: set the max size value of log allowed in MB, Ex:{ key: "value value value value value value value " } => 80 Bytes
const debug = debug: true default: max: length: 60 size: 100 ;
datatypes
Not tested yet!!
Define allowed data type of log value.
Not tested with functions or other data type.
By default it allow
number
,string
,object
.
Try not use complex schema with console.table, that lose the readable format