Security News
NVD Backlog Tops 20,000 CVEs Awaiting Analysis as NIST Prepares System Updates
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
universal javascript logger with contextual logging, leglevel, timing, colors and more
Logex is a js log module that use variables as base structure. it has instances support, coloring, and. its kinda universal through browserify. minified version is available in dist directory.
Installation:
npm install logex --save
*note: all of the options are optional
Log({/* options */})
var logger = Log('namedInstance', {/* options */})
Log levels (by priority):
var Log = require('logex'); // or window.Log in the browser
// change level on the default instance
Log.level = "info";
Log.debug('i will not appear');
// changing log level via option declaration
Log({level: 'verbose'});
Log.debug("I am %s off", 'showing');
// patch an object to be a logex instance
Log.patch(console);
console.log("Work is %s!", 'Done', {a:1}, false, null, 1, function tester(){});
// print method bypasses the default format and allow to dynamically declare one
// each % sign will pass one argument to the variable handler
Log.print('info', "{C LVL}[{LVL}]{/C} {C GREEN}my {C RED}red{/C} text{/C}");
function sum(x ,y) {
if (!x || !y) {
Log.userWarn("invalid arguments. (I point 1 invoker up the stack) and not on myself");
return
}
return x + y;
}
sum(1);
// instances
var firstInstance = Log("first instance");
var secondInstance = Log("Second instance");
// global declaration
firstInstance.variables.TEST = 123;
firstInstance.variables.STATUS = 'GLOBAL';
// instance specific declaration
firstInstance.STATUS = 'firstInstance';
secondInstance.STATUS = 'secondInstance';
firstInstance.print("{ID }{STATUS} {TEST}");
secondInstance.print("{ID }{STATUS} {TEST}");
Log.print("{ID }{STATUS} {TEST}");
all level methods have an single letter alias (for android addicts)
Log.error("I am an 'error' level message")
Log.warn("I am a 'warn' level message")
Log.log("I am an 'info' level message")
Log.info("I am an 'info' level message")
Log.debug("I am a 'debug' level message")
Log.verbose("I am a 'verbose' level message")
Log.d("I am a 'debug' level message")
default log level is: production-info, development/debugging-debug
Log.level = 'debug'
// same as
Log({level: 'debug'})
default format is: {LVL}:{CONTEXT}: {ID }{MSG}
*note: ID
variable will print nothing for the default instance
Log({format: '{LVL}:{CONTEXT}: {ID }{MSG}'})
// named instances must provide their name when changing options
Log('myInstance', {format: '{LVL}:{CONTEXT}: {ID }{MSG}'})
// same as
Log({
id: 'myInstance'
format: '{LVL}:{CONTEXT}: {ID }{MSG}'
})
special method to use a custom format directly. if log level is not defined, the default one is used
print([options|level], format, ..args)
you can use the current format through Log.options.format
Log.print("{LVL_LOWER}: [{TIME}] {PT}/{PID} {MEM} i am %s!", "groot");
Log.print('debug', "{LVL_LOWER}: [{TIME}] {PT}/{PID} {MEM}");
// or define custom call specific options
Log.print({level: 'debug'}, "[{LVL_ONE}] {HOUR} {CONTEXT} %s", "this is my message");
alias Log.uw
user warning is meant to inform the user he misused you function. the context variable will point one call higher then itslef.
its a shortcut for
Log.print({skip: 1}, Log.options.format, "your message", "and other args")
exmaple.js
1 function sum(x ,y) {
2 if (!x || !y) {
3 Log.warn("invalid arguments. (I point myself)"); // CONTEXT is 'example.js:3:9'
4 Log.userWarn("invalid arguments. (I point 1 invoker up the stack)"); // CONTEXT is 'example.js:10:1'
5 return
6 }
7 return x + y;
8 }
9
10 sum(1); // context
This will patch the console object with the selcted methods
.patch(object, methodsArray)
default methodsArray: ['error', 'warn', 'log', 'info', 'debug']
Log.patch(console)
console.log("i am actually a %s method", 'logex')
// will print: INFO:exmaple.js:1:1 i am actually a logex method
var obj = {}
// will patch only the given methods even if they don't originaly exist on the target object
Log.patch(obj, ['debug', 'verbose'])
obj.verbose("I am a logger too!")
This will print trace using the console or will print an error stack if trace method is not natively supported
These are methods and properties that exist on the logger object but generally speaking there is no reason to use them at the moment
Log.dateFormat([dateObject], "mask", {boolean} UTC) // returns formatted date string
Log.formats // predefined common formats (there arn't many... suggestions are welcome!)
Log.inspect(obj, options) // reference to 'util' module method
Log.format(...args) // reference to 'util' module method
Log.console // reference to the original console object
Simple var {NAME}
Var with params {NAME params 123}
Closing var {/NAME} | {/NAME params 123}
Var with arguments {NAME %} | {NAME params 123%}
*note: never use '%' sign in parameter. use only to assign arguments.
{LVL}
- Log level. example: INFO, WARN, ERROR etc{LVL_LOWER}
- Log level in lower case. example: info, warn, error etc{LVL_ONE}
- Log level in a single upper case letter. example: E, W, D etc{CONTEXT 5}
- The location in which the log invoked. example: 'app.js:21:7'{MSG}
- The log message{PID}
- process.pid. example: 1725{PT}
- process.title. example: node{ENV}
- environment derived from process.env.NODE_ENV. example: 'development', 'production'' (feel free to override this or to write your own variable){ID}
- Identifier of the logger instance. the default is 'default'. Unlike any other var, it prints it paramters (not including the first space) to avoid redundant spaces when printing the var in the default loggerDate parameters:
{BUMP}
- time since last Bump (per instance). example: +1753ms
{BUMP anyName FLAG}
- named bump (namepsace is per instance) with flag. empty name = 'default'.
Flags:
START - reset start time to now and print 0ms
TOTAL - prints the total time from the first bump (or reset). exmaple: 7801ms, 35.4s
RESET - prints time diff from last bump and reset start time. exmaple: +2345ms
CLEAR - prints time diff from last bump and clear the namespace. this is good to avoid memory leaks
END - prints time diff from the last bump and clear the namespace
RESET_TOTAL - same as RESET but prints total time instaed
CLEAR_TOTAL - same is CLEAR but prints total time
END_TOTAL - same as END but prints total time
see Bump exmaple
{STAMP}
- timestamp. example: 1420063200000
{HOUR}
- time in 24 hours. example: 16:45:41.178
{TIME}
- time in 24 hours. example: "16:45:41 GMT-0500 (EST)"
{UTC}
- time in 24 hours. example: Wed, 31 Dec 2015 16:45:41 GMT
{DATE}
- Default full date. example: 31/Dec/2015:16:45:41 -0500
{DATE formatString}
- custom Date. see docs/DATE_FORMAT.md. example: yyyy-mm-dd'T'HH:MM:ss -> 2015-12-31T16:45:41
Colors: You can use any of the listed colors inside curly brackets
Example: {C LVL}[{LVL}]{/C} {C BLUE}my {C RED}red{/C} text{/C}
Default
{PT}/{PID}{LVL}:[{HOUR}]:{CONTEXT}: {MSG}
// Static
Log.variables.STATUS = 'Listening';
var obj = {status: 'Listening'}
// object reference - practically dynamic
Log.variables.STATUS = obj;
// function
Log.variables.STATUS = function (state, params, closing) {
// this points the current instance (the one that used the variable);
this.data.myData = 'per instance safe space to store data';
return this.name + ':' + getDynamicStatus()
}
// Static
Log.STATUS = 'Listening';
// Dynamic
Log.STATUS = function (state, params, closing) {
// this points the current instance
return this.name + ':' + getDynamicStatus()
}
// define custom variable. 4th argument and up passed by the caller
Log.variables.REQUEST = function (state, params, closing, extraArg1) {
return extraArg1.method + ' ' + extraArg1.url;
};
// simulate request object
var httpRequest = {
url: '/home',
method: 'GET'
};
// use % to pass 1 argument
Log.print('debug', "[{LVL_ONE}] {REQUEST %}", httpRequest);
// will print: [D] GET /home
## Bump
Log.print("#1 total:{BUMP myTimer TOTAL} diff: {BUMP}");
setTimeout(function () {
Log.print("#2 total:{BUMP myTimer TOTAL} diff: {BUMP}");
}, 1235);
setTimeout(function () {
Log.print("#3(reset) total:{BUMP myTimer RESET_TOTAL} diff: {BUMP RESET}");
}, 2435);
setTimeout(function () {
Log.print("#4 total:{BUMP myTimer TOTAL} diff: {BUMP} counted relative to last call");
}, 3286);
setTimeout(function () {
Log.print("#5(clear) total:{BUMP myTimer CLEAR_TOTAL} diff: {BUMP CLEAR} clear the counter");
}, 4386);
setTimeout(function () {
Log.print("#6 total:{BUMP myTimer TOTAL} diff: {BUMP} passively starts the timer again");
}, 5286);
will print:
#1 total:0ms diff: +0ms
#2 total:1237ms diff: +1237ms
#3(reset) total:2438ms diff: +1201ms
#4 total:850ms diff: +850ms counted relative to last call
#5(clear) total:1950ms diff: +1100ms clear the counter
#6 total:0ms diff: +0ms passively starts the timer again
FAQs
universal javascript logger with contextual logging, leglevel, timing, colors and more
We found that logex demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.