Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

anylogger

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

anylogger - npm Package Compare versions

Comparing version 0.6.0 to 0.7.0

79

any.js

@@ -15,3 +15,3 @@ /**

/**
* anylogger([name] [, options]) => function logger([level='log'] [, ...args])
* anylogger([name] [, config]) => function logger([level='log'] [, ...args])
*

@@ -24,12 +24,12 @@ * The main `anylogger` function creates a new or returns an existing logger

*/
a = function(n,o){
a = function(n,c){
// return the existing logger, or create a new one. if no name was given, return all loggers
return n ? m[n] || (m[n] = a.create(n,o)) : m
return n ? m[n] || (m[n] = a.create(n,c)) : m
}
/**
* The supported log levels.
*
* `anylogger.levels`
*
* An object containing a mapping of level names to level values.
* In anylogger, a higher level of logging means more verbose logging: more log messages.
*
* The lowest level of logging (none at all) has value `0`. Higher levels have

@@ -42,3 +42,3 @@ * higher values. To be compliant with the anylogger API, loggers should support

/**
* The anylogger console.
* `anylogger.out`
*

@@ -50,10 +50,10 @@ * Defaults to the native console or false if no native console is available.

*
* The anylogger console may be overridden by a different object to intercept
* `anylogger.out` may be overridden by a different object to intercept
* individual logging calls. For example this property could be overridden
* with an alternative console object that applies formatting.
* with an alternative object that applies formatting.
*
* When a method is not available on the anylogger console, but
* `anylogger.out.log` is defined, `anylogger.out.log` will be used. So you
* can define a level `silly` and it will create a method `silly()` which is
* an alias for `anylogger.out.log`.
* When a method is not available on `anylogger.out`, but `anylogger.out.log`
* is defined, `anylogger.out.log` will be used. So you can define a level
* `silly` and it will create a method `silly()` which would just be an alias
* for `anylogger.out.log`.
*/

@@ -64,19 +64,18 @@ a.out = typeof console != 'undefined' && console

/**
* Called when a logger needs to be created.
*
* `anylogger.create(name, options)`
*
* `anylogger.create(name, config)`
* Called when a logger needs to be created. *
* Creates a new logger by calling `anylogger.new`, then extends it by calling
* `anylogger.ext` on the result.
*
*
* You can replace this method with a custom factory, or leave this one in
* place and instead override `anylogger.ext` and/or `anylogger.new` separately.
*
*
* @param name String, The name of the logger to create
* @param options Object, An optional options object
*
* @returns A new logger with the given `name` and `options`.
* @param config Object, An optional config object
*
* @returns A new logger with the given `name` and `config`.
*/
a.create = function(n,o) {
return a.ext(a.new(n,o))
a.create = function(n,c) {
return a.ext(a.new(n,c,a.log),a.out)
}

@@ -86,14 +85,15 @@

*
* `anylogger.new(name, options)`
* `anylogger.new(name, config, log) => logger`
*
* Creates and returns a new named function that calls `anylogger.log` to
* perform the log call to the correct logger method based on the first
* argument given to it.
* Creates and returns a new named function that calls `log` to perform
* the log call to the correct logger method based on the first argument
* given to it.
*
* @param name String The name of the logger to create
* @param options Object An optional options object
* @param config Object An optional config object
* @param log Function The log function that will be called
*
* @return function log([level='log'], args...)
* @return logger function log([level='log'], args...)
*/
a.new = function(n,o,r) {
a.new = function(n,c,l,r) {
// use eval to create a named function, this method has best cross-browser

@@ -103,5 +103,3 @@ // support and allows us to create functions with names containing symbols

// the created function calls `anylogger.log` to call the actual log method
eval("r = {'" + n + "': function(){a.log(n, [].slice.call(arguments))}}[n]")
// if you want to do extra stuff inside the logger function, consider
// overriding `anylogger.log` instead of this method.
eval("r={'" + n + "':function(){l(n,[].slice.call(arguments))}}[n]")
// IE support: if the function name is not set, add a property manually

@@ -113,3 +111,3 @@ return r.name ? r : Object.defineProperty(r, 'name', {get:function(){return n}})

/**
* Called from the logger function created by `anylogger.new`.
* Default log function given to `anylogger.new`.
*

@@ -131,3 +129,3 @@ * `anylogger.log([level='log',] ...args)`

*
* `anylogger.ext(logger) => logger`
* `anylogger.ext(logger, out) => logger`
*

@@ -139,6 +137,11 @@ * This method must ensure that a log method is available on the logger for

* called multiple times on the same object without ill side-effects.
*
* @param logger Function The logger to be (re-)extended
* @param out The output to log to (by default, the console)
*
* @return The logger that was given, extended
*/
a.ext = function(l) {
a.ext = function(l,o) {
for (v in a.levels)
l[v] = a.out[v] || a.out.log || function(){}
l[v] = o[v] || o.log || function(){}
return l;

@@ -145,0 +148,0 @@ }

@@ -1,1 +0,1 @@

!function(m,a){m=Object.create(null),a=function(n,e){return n?m[n]||(m[n]=a.create(n,e)):m},a.levels={error:1,warn:2,info:3,log:4,debug:5,trace:6},a.out="undefined"!=typeof console&&console,a.create=function(n,e){return a.ext(a.new(n,e))},a.new=function(n,o,r){return eval("r = {'"+n+"': function(){a.log(n, [].slice.call(arguments))}}[n]"),r.name?r:Object.defineProperty(r,"name",{get:function(){return n}})},a.log=function(n,e){m[n][1<e.length&&a.levels[e[0]]?e.shift():"log"].apply(m[n],e)},a.ext=function(n){for(v in a.levels)n[v]=a.out[v]||a.out.log||function(){};return n},window.anylogger=a}();
!function(m,a){m=Object.create(null),a=function(n,e){return n?m[n]||(m[n]=a.create(n,e)):m},a.levels={error:1,warn:2,info:3,log:4,debug:5,trace:6},a.out="undefined"!=typeof console&&console,a.create=function(n,e){return a.ext(a.new(n,e,a.log),a.out)},a.new=function(n,c,l,r){return eval("r={'"+n+"':function(){l(n,[].slice.call(arguments))}}[n]"),r.name?r:Object.defineProperty(r,"name",{get:function(){return n}})},a.log=function(n,e){m[n][1<e.length&&a.levels[e[0]]?e.shift():"log"].apply(m[n],e)},a.ext=function(n,e){for(v in a.levels)n[v]=e[v]||e.log||function(){};return n},window.anylogger=a}();
{
"name": "anylogger",
"version": "0.6.0",
"version": "0.7.0",
"description": "Get a logger. Any logger.",

@@ -24,2 +24,3 @@ "main": "any.js",

"chai": "^4.2.0",
"gzip-size": "^5.0.0",
"mocha": "^5.2.0",

@@ -26,0 +27,0 @@ "sinon": "^7.2.3",

@@ -1,2 +0,2 @@

# anylogger <sub><sup>v0.6.0</sup></sub>
# anylogger <sub><sup>0.7.0</sup></sub>
### Get a logger. Any logger.

@@ -22,7 +22,7 @@

By choosing anylogger, you are explicitly not choosing any specific logging
framework, but instead are limiting yourself to the
[Anylogger API](#anylogger-api), a small API that only captures the bare
essentials for logging, but because of that, is compatible with nearly every
logging library out there.
> By choosing anylogger, you are explicitly not choosing any specific
> logging framework, but instead are limiting yourself to the
> [Anylogger API](#anylogger-api), a small API that only captures the
> bare essentials for logging, but because of that, is compatible with
> nearly every logging library out there.

@@ -33,8 +33,5 @@ ## What is this?

We, the Javascript community, really need a logging facade. Initially, the
native `console` object was not always available and it's API varied from
implementation to implementation. The community responded by creating
logging frameworks to deal with the complexity. Now there are dozens of logging
libraries around and we library authors face a dilemma. Which logger do we
pick? Should we make this configurable? Should we just not log? Use the
We, the Javascript community, really need a logging facade. There are dozens
of logging libraries around and we library authors face a dilemma. Which logger
do we pick? Should we make this configurable? Should we just not log? Use the
console directly? How do we deal with this complexity?

@@ -52,3 +49,3 @@

A tiny 0.5kB logging facade that you can include in your library to have
A tiny [366](#gzip-size) bytes logging facade that you can include in your library to have
logging 'just work', while at the same time allowing application developers

@@ -58,3 +55,3 @@ to plug in any logging framework they choose. Instead of building in your own

logging framework on your users, or just abandoning logging altogether, choose
`anylogger` and for just 0.5 kB shared between all libraries doing this, we can
`anylogger` and for just [366](#gzip-size) bytes shared between all libraries doing this, we can
plug in any framework of our choice and all libraries will automatically

@@ -72,4 +69,4 @@ start to use that framework. Wouldn't it be much better and easier?

* [any.js](https://unpkg.com/anylogger@0.6.0/any.js) (fully commented source ~5kB)
* [any.min.js](https://unpkg.com/anylogger@0.6.0/any.min.js) (minified and gzipped ~0.5 kB)
* [any.js](https://unpkg.com/anylogger@0.7.0/any.js) (fully commented source ~5kB)
* [any.min.js](https://unpkg.com/anylogger@0.7.0/any.min.js) (minified 601B, gzipped [366](#gzip-size)B)

@@ -81,3 +78,3 @@

```html
<script src="https://unpkg.com/anylogger@0.6.0/any.min.js"></script>
<script src="https://unpkg.com/anylogger@0.7.0/any.min.js"></script>
<script>(function(){ // IIFE

@@ -107,3 +104,3 @@ var log = anylogger('index.html')

"dependencies": {
"anylogger": ">= 0.6.0 < 2"
"anylogger": ">= 0.7.0 < 2"
}

@@ -114,4 +111,4 @@ }

I recommend to expand the version range here. By default NPM will set a
range looking like `"^0.6.0"`, which is equivalent to `"0.6.x"` or
`">= 0.6.0 < 0.7.0"`. This version range is probably too narrow. When
range looking like `"^0.7.0"`, which is equivalent to `"0.7.x"` or
`">= 0.7.0 < 0.7.0"`. This version range is probably too narrow. When
multiple libraries depend on the same library, if their version ranges overlap,

@@ -130,4 +127,4 @@ NPM will be able to make them all use the same version. But if their version

So I recommend accepting everything up to the second next major release.
That means that currently while at version `0.6.0`, we should set the version
range to everything equal to or above `0.6.0` and below `2.0.0`:
That means that currently while at version `0.7.0`, we should set the version
range to everything equal to or above `0.7.0` and below `2.0.0`:

@@ -137,3 +134,3 @@ ```json

"dependencies": {
"anylogger": ">= 0.6.0 < 2.0.0"
"anylogger": ">= 0.7.0 < 2.0.0"
}

@@ -426,3 +423,3 @@ }

Please have a look at the [source](https://unpkg.com/anylogger@0.6.0/any.js)
Please have a look at the [source](https://unpkg.com/anylogger@0.7.0/any.js)
it should make it more clear how to write an adapter. Also consider studying

@@ -453,1 +450,7 @@ the [available adapters](https://www.npmjs.com/search?q=keywords:anylogger)

Licensed under the [MIT Open Source license](https://opensource.org/licenses/MIT).
## gzip-size
The GZIP algorithm is available in different flavours and with different
possible compression settings. The sizes quoted in this README have been
measured using [gzip-size](https://npmjs.com/package/gzip-size)
by [Sindre Sorhus](https://github.com/sindresorhus), your mileage may vary.
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