New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

logule

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

logule - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

9

History.md

@@ -1,3 +0,10 @@

0.2.0 / 2011-11-25
0.3.0 / 2011-11-25
==================
* The `remove` method is now known as `suppress`
* The `get` method result no longer allows chaining into different log methods (bug)
* Bad fns requested to `suppress` and `get` will result in an internal log in such a way that you can determine quickly what you did wrong
* Everything is properly encapsulated so that you can not break out of `suppress` and `get`calls
0.2.0 / 2011-11-24
==================
* Multiple namespaces can be passed to constructor

@@ -4,0 +11,0 @@ * Padding option now set via the `pad` method

2

package.json

@@ -5,3 +5,3 @@ {

"description": "An advanced logger for nodejs",
"version": "0.2.0",
"version": "0.3.0",
"repository": {

@@ -8,0 +8,0 @@ "type": "git",

@@ -5,3 +5,3 @@ # Logule

Shortcut methods for the log levels are available as `log.error`, `log.warn`, `log.info` and `log.debug`.
Shortcut methods for the log levels are available as `log.error`, `log.warn`, `log.info`, `log.debug` and `log.trace`.
These methods are additionally chainable.

@@ -24,11 +24,11 @@

### Multiple Namespaces
Simply pass in more strings to get more namespaces prefixed.
Pass in more strings to get more namespaces prefixed
````javascript
var log = new Logger('CONNECTION', 'ESTABLISHMENT');
log.info('Accepted 192.168.0.160');
var log = new Logger('BUILD', 'COMPILE');
log.debug('Coffee app.coffee');
````
### Namespace Padding
Padding of the namespace can be done by calling the pad method on the instance with the indentation level you want.
Call `.pad(size)` on a logger instance to specify a fixed indentation level for the namespaces.

@@ -39,39 +39,60 @@ ````javascript

Now, the actual log messages will all begin 16 characters after the prefix starts.
If the prefix is longer than the size limit, it will stand out from the crowd.
Messages will here begin 16 + delimiter size characters away from how it would log without a namespace.
Large namespaces (>specified size), will stand out from the crowd.
This is useful when different Logger instances is created in different places with different prefixes, and you want to line up the output.
This allows you to line up the output from multiple logger instances.
Note that namespace padding with multiple namespaces is almost impossible to get right (all namespaces pad to an equal length).
If you do enforce superstrict rules, however, the `pad` method will set the pad size for each namespace.
For multiple namespaces, the size applies to each (present) level. Padding will, in other words, only work with strict naming conventions.
## Passing log around
If using multiple namespaces, then having to write them all out in every module when changing the last is not optimal.
### Subclasses
Easiest with multiple namespaces; call `.sub()` and old namespaces will be preserved.
Therefore, it is possible to make a Logger 'subclass' using `sub()`.
````javascript
var log = new logule('BUILD');
var sublog = log.sub('COMPILE');
// pass sublog to the compilation sub-module
// use log in the hierarchy above
var log = new Logger('BUILD');
var sublog = log.sub('COMPILE'); // same as new Logger('BUILD', 'COMPILE')
````
If the same namespace is fine for another module to use, simply pass log to it.
A call to `.sub()` without arguments will simply maintain existing namespace(s).
This is better than creating brand new ones, because you can filter away certain log messages by simply filtering on the base logger at compile time.
Essentially: **Sub is a new Clone**:
`log.sub()` maintains all padding, suppress and namespace properties set on the original log.
### Filtering log
If you only want a submodule to be able to log debugs for instance, you can save typing and force this behaviour by calling `get` on log.
This will return the correctly closure bound log method and pass that down.
#### Standard Way
Suppressing logs from an instance is done in a very neat, propagating, and non-breaking way.
`.suppress(methods...)` returns a `sub()` suppresses output from specified methods, but still allows them to be called, and they still chain.
````javascript
var sublog = log.suppress('debug', 'info');
sublog.warn('works').info('suppressed').error('works!');
log.info('works');
````
#### Simple Function way
A debug module will only need `log.debug`. You can `.get('debug')` on an instance to return the correctly bound instance method to pass down.
````javascript
var debug = log.get('debug');
debug("this goes to log.debug - no other methods accessible through this var");
debug("same as log.debug - no other methods accessible through this var");
````
Alternatively, make a copy of the log instance by filtering out the methods you do not want to allow:
Note that if the instance have called `.suppress('debug')` earlier - or it is a `.sub()` of an instance that have called `.suppress('debug')`,
you would still get a working function from `.get('debug')`. It would simply not do anything.
### Global Log Levels
By only using `.sub()` instances inheriting from a single base instance, you can implement global log levels at compile time by calling `.suppress()`
on the base instance - or any branch point you would like - at compile time.
````javascript
var sublog = log.remove('debug', 'info');
sublog.warn('works').info('suppressed').error('works!');
log.info('works');
var log = new Logger('APP');
/**
* // Uncomment this globally suppress:
* log.suppress('info','debug');
**/
var modelsLog = log.sub('MODEL');
var eventsLog = log.sub('EVENT');
//pass the two log files down
````

@@ -78,0 +99,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc