anylogger

Get a logger. Any logger.

MIT License

Downloads
46.1K
Stars
33
Committers
4

Bot releases are hidden (Show)

anylogger - v1.0.11 Latest Release

Published by Download over 3 years ago

Updated dependencies, added Typescript tests

  • Removed unused dev-dependency on lodash
  • Updated all dev-dependencies to latest versions
  • Added a small test for the typescript definitions
anylogger - v1.0.10

Published by Download almost 4 years ago

Fixed named logger creation to avoid unsafe-eval

  • Updated anylogger.new to avoid eval entirely
  • Saved ~40 bytes in the process
  • Updated all dependencies
  • Updated copyright year in license file
anylogger - v1.0.9

Published by Download almost 4 years ago

unpkg does not like trailing slash

  • Updated README
  • Modified build script
anylogger - v1.0.8

Published by Download almost 4 years ago

Added unpkg entry to package.json, updated README, removed commented code

anylogger - v1.0.7

Published by Download almost 4 years ago

Updated README

anylogger - v1.0.6

Published by Download almost 4 years ago

Updated deps, only noop, fallback for unsafe_eval, README

  • Updated all dependencies, fixing some security issues in dev dependencies
  • Only support noop functions, factored console support out into anylogger_console
  • Wrap creation of loggers in try-catch and include fallback for unsafe_eval #14
  • Updated README to mention anylogger_console
anylogger - v1.0.5

Published by Download about 4 years ago

Don't publish as an ES Module

anylogger - v1.0.4

Published by Download over 4 years ago

Updated dependencies, README, copyright year

anylogger - v1.0.3

Published by Download over 4 years ago

Update Travis CI badge in README

  • hoping it will start to reflect the actual build status
anylogger - v1.0.2

Published by Download over 4 years ago

anylogger - v1.0.1

Published by Download over 4 years ago

anylogger - v1.0.0

Published by Download over 4 years ago

Anylogger 1.0.0

anylogger - v0.21.0

Published by Download almost 5 years ago

No code changes

Updated the README and the copyright statement

anylogger - v0.20.0

Published by Download almost 5 years ago

Simplified peer dependencies

For 0.x versions, NPM uses a different setup for caret and tilde.
I really don't want to go to 1.0 just yet, but also want peer dependencies to be simple.
So I changed the instructions to use ">=0.20.0" i.s.o. "^0.20.0" because it will be ok for 1.x and further as well.

anylogger - v0.19.0

Published by Download almost 5 years ago

API updated

Loggers now get a method enabledFor to test whether a level is enabled:

import anylogger from 'anylogger'
const log = anylogger('test')
if (log.enabledFor('info')) {
  log.info('message', withExpensiveCalculations())
}

By default, this method always returns true. When using an adapter, this method should be hooked into the level system of the logger framework the adapter is for, if any.

I am hoping this will be the last API change before 1.0.

Dependencies updated

The development dependencies Mocha, Sinon and Uglify JS were updated to the latest versions, fixing some potential vulnerabilities in the process.

Made logger instantiation more robust and safe

I was seeing some weird error messages in the wild related to anylogger.new. That method has some very weird and evil stuff going on, because we want to create a named function, having the name property of the function match the one we were given, and that is actually tricky on old browsers (IE, Safari). These browsers have trouble understanding this JS syntax:

var name = 'some:test-logger' // note that this name has characters that are illegal in identifiers
var fn = {[name]: function(){}}[name] // fn.name == 'some:test-logger'

So instead, I was doing

var r, name = 'some:test-logger'
eval("r={'" + name + "':function(){}}[name]")

which does work on these old browsers... but eval is evil right?
In addition, IE still did not set the name, so after the eval statement I was doing:

// IE support: if the function name is not set, add a property manually
return r.name ? r : Object.defineProperty(r, 'name', {get:function(){return name}})

However it seems this lead to Uncaught TypeError: Cannot redefine property: name errors in some rare situations. Looking at the original code I still don't quitte understand how, but I hope the new version is more robust:

a.new = function(n,c,r) {
  r = (new Function('a', 'n', "return {'" + n + "':function(){a.log(n,[].slice.call(arguments))}}[n]"))(a,n)
  try {Object.defineProperty(r, 'name', {get:function(){return n}})} catch(e) {}
  return r
  // return {[n]: function(){a.log(n,[].slice.call(arguments))}}[n]
}

We now use new Function() instead of eval. Still not great, but at least not as evil. We wrap the defineProperty call in try ... catch and, because we wrapped it anyway, we can drop the test and just always try to define it.

The last, commented out, statement gives a glimp into the future... this is what it can look like in a modern browser. But this is a logger, and loggers should support all platforms that all libraries using the logger need to support, so it will be some time before we drop support for IE and Safari in anylogger.

anylogger - 0.18.0

Published by Download about 5 years ago

Added TypeScript support

A big thanks to Jakub Jirutka who contributed TypeScript type declarations.

anylogger -

Published by Download about 5 years ago

anylogger -

Published by Download about 5 years ago

anylogger - v0.9.0

Published by Download over 5 years ago

anylogger - v0.8.0

Published by Download over 5 years ago