diff --git a/.travis.yml b/.travis.yml index da2f588..9308537 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ node_js: - "6" - "5" - "4" + - "0.10" # https://github.com/greenkeeperio/greenkeeper-lockfile before_install: - npm install -g npm@5 diff --git a/README.md b/README.md index e78db27..db63d00 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# ulog v1.1.0 +# ulog v2.0.0-beta.1 ### Microscopically small universal logging library [![npm](https://img.shields.io/npm/v/ulog.svg)](https://npmjs.com/package/ulog) @@ -19,8 +19,8 @@ Even with these extra features, ulog is still **very** small, weighing in just over 1 kB minified and gzipped. ## Download -* [ulog.umd.js](https://cdn.rawgit.com/download/ulog/1.1.0/ulog.umd.js) (~3kB, source) -* [ulog.min.js](https://cdn.rawgit.com/download/ulog/1.1.0/ulog.min.js) (~2kB, minified) +* [ulog.umd.js](https://cdn.rawgit.com/download/ulog/2.0.0-beta.1/ulog.umd.js) (~3kB, source) +* [ulog.min.js](https://cdn.rawgit.com/download/ulog/2.0.0-beta.1/ulog.min.js) (~2kB, minified) ## Install ```sh @@ -55,7 +55,7 @@ define(['ulog'], function(ulog){ ### Script tag ```html - + ``` ## Logging methods diff --git a/browser.js b/browser.js index 2a63fc8..141954d 100644 --- a/browser.js +++ b/browser.js @@ -1,4 +1,5 @@ var log = require('./ulog') + var qs = location.search.substring(1), args = qs && qs.split('&'), lvl, dbg, i, m @@ -13,9 +14,9 @@ for (i=0; m=args && args[i] && args[i].split('='); i++) { m[0] == 'debug' ? dbg = m[1] : 0 } -log.con = function(){return window.console && console} +log.con = function(){return window.console} dbg && log.enable(dbg) -var ulog = log() +log() log.level = lvl || log.WARN -module.exports = ulog +module.exports = log diff --git a/build/build-umd.js b/build/build-umd.js index 484eb73..ea714a5 100644 --- a/build/build-umd.js +++ b/build/build-umd.js @@ -4,19 +4,17 @@ var path = require('path') var root = path.resolve(process.cwd()) var commonScript = fs.readFileSync(path.resolve(root, 'ulog.js'), 'utf8') -commonScript = commonScript.replace('module.exports = log', '') +commonScript = commonScript.replace('module.exports = ulog', '') var browserScript = fs.readFileSync(path.resolve(root, 'browser.js'), 'utf8') browserScript = browserScript.replace("var log = require('./ulog')", '') -browserScript = browserScript.replace('module.exports = ulog', 'return ulog') +browserScript = browserScript.replace('module.exports = log', 'return log') var combinedScript = commonScript + browserScript var umdScript = "(function(u,m,d){\n" + - "\tif (typeof define == 'function' && define.amd) define(m,[],d)\n" + - "\telse if (typeof module == 'object' && module.exports) module.exports = d()\n" + - "\telse u[m] = d()\n" + + "\ttypeof define == 'function' && define.amd ? define(m,[],d) : (u[m] = d())\n" + "})(this, \'ulog\', function(){'use strict'\n" + combinedScript + '\n' + "}) // umd\n" diff --git a/microscopical.spec.js b/microscopical.spec.js index 0ec9b54..f606125 100644 --- a/microscopical.spec.js +++ b/microscopical.spec.js @@ -5,6 +5,6 @@ var node = typeof window != 'object' describe('ulog', function(){ it('is microscopically small (~2kB minified, ~1kB gzipped)', function(){ var stats = fs.statSync("ulog.min.js") - expect(stats.size).to.be.below(2000) + expect(stats.size).to.be.below(2500) }) }) diff --git a/node.js b/node.js index 4d2c6bd..453c91f 100644 --- a/node.js +++ b/node.js @@ -1,12 +1,11 @@ var log = require('./ulog') -var level, debug - -if (process.env.LOG ) {level = process.env.LOG} -if (process.env.DEBUG) {debug = process.env.DEBUG} +var lvl, dbg +if (process.env.LOG ) {lvl = process.env.LOG} +if (process.env.DEBUG) {dbg = process.env.DEBUG} var fd = process.env.DEBUG_FD && parseInt(process.env.DEBUG_FD, 10), - c = console; + c = console; if (typeof fd == 'number') { var util = require('util'), stream = createWritableStdioStream(fd), @@ -14,10 +13,20 @@ if (typeof fd == 'number') { c = {error:logger, warn:logger, info:logger, log:logger, trace:logger} } +log.extends.push(function(o,p){ + // makes Node behave like browsers + o.assert = function(){ + var a=[].slice.call(arguments), ok=a.shift() + if (!ok) {o.error.apply(o, a)} + } +}) + log.con = function(){return c} -if (debug) {log.enable(debug)} -module.exports = log() -log.level = level || log.INFO +if (dbg) {log.enable(dbg)} +log() +log.level = lvl || log.INFO + +module.exports = log // SEE https://github.com/visionmedia/debug/blob/2.2.0/node.js#L144 function createWritableStdioStream (fd) { diff --git a/package.json b/package.json index 6620461..293bb2f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ulog", - "version": "1.1.0", + "version": "2.0.0-beta.1", "description": "Microscopically small universal logging library", "main": "node.js", "browser": "browser.js", @@ -12,7 +12,8 @@ "build": "cross-env NODE_ENV=production npm run -S build-all", "release": "npm run -S clean && npm run -S build && npm run -S test", "test": "mocha *.spec.js", - "dev": "webpack-dev-server --output-path /test --output-filename ulog.spec.js \"mocha-loader!./ulog.spec.js\" --content-base test --port 8888" + "dev": "webpack-dev-server --output-path /test --output-filename ulog.spec.js \"mocha-loader!./ulog.spec.js\" --content-base test --port 8888", + "debug": "webpack-dev-server --output-path /test --output-filename debug.spec.js \"mocha-loader!./debug.spec.js\" --content-base test --port 8888" }, "keywords": [ "universal-components", @@ -35,7 +36,7 @@ "email": "StijnDeWitt@hotmail.com", "url": "http://StijnDeWitt.com" }, - "copyright": "Copyright 2016 by [Stijn de Witt](http://StijnDeWitt.com). Some rights reserved.", + "copyright": "Copyright 2017 by [Stijn de Witt](http://StijnDeWitt.com). Some rights reserved.", "license": "CC-BY-4.0", "licenseUrl": "https://creativecommons.org/licenses/by/4.0/", "repository": { diff --git a/test/test.html b/test/test.html deleted file mode 100644 index 0980f09..0000000 --- a/test/test.html +++ /dev/null @@ -1,16 +0,0 @@ - - -
-Open the developer console
- - - \ No newline at end of file diff --git a/ulog.js b/ulog.js index 80417f3..3a4da1f 100644 --- a/ulog.js +++ b/ulog.js @@ -3,78 +3,70 @@ // © 2017 by Stijn de Witt, some rights reserved // License: CC-BY-4.0 -function log(name){ - return name - ? (mods[name] ? mods[name] : (mods[name] = enhance({name:name}, log))) - : (log.debug ? log : enhance(log)) +function log(n){ + return !n ? extend(log) : mods[n] || (mods[n] = extend(create(n), log)) } -log.ulog = {version:'1.1.0'} +log.formats = [] +log.extends = [] -log.enable = function(str) { - var i, split = (str || '').split(/[\s,]+/); +log.enable = function(s) { + var i, split = (s || '').split(/[\s,]+/); for (i=0; i