From 1b98513015a5241909222c3a8057aa68dd57491f Mon Sep 17 00:00:00 2001 From: Stijn de Witt Date: Mon, 26 Sep 2016 01:13:39 +0200 Subject: [PATCH] 0.1.0: Initial working version with tests --- .gitignore | 37 +- .travis.yml | 11 + LICENSE.md | 161 ++++++++ README.md | 214 ++++++++++- browser.js | 14 + microscopical.spec.js | 10 + node.js | 79 ++++ package.json | 62 +++ test/browser-source-map-support.js | 89 +++++ test/index.html | 11 + ulog.js | 82 ++++ ulog.min.js | 1 + ulog.min.js.map | 1 + ulog.min.js.zip | Bin 0 -> 1129 bytes ulog.png | Bin 0 -> 17637 bytes ulog.spec.js | 580 +++++++++++++++++++++++++++++ ulog.umd.js | 165 ++++++++ ulog.umd.js.map | 1 + webpack.config.js | 20 + 19 files changed, 1501 insertions(+), 37 deletions(-) create mode 100644 .travis.yml create mode 100644 LICENSE.md create mode 100644 browser.js create mode 100644 microscopical.spec.js create mode 100644 node.js create mode 100644 package.json create mode 100644 test/browser-source-map-support.js create mode 100644 test/index.html create mode 100644 ulog.js create mode 100644 ulog.min.js create mode 100644 ulog.min.js.map create mode 100644 ulog.min.js.zip create mode 100644 ulog.png create mode 100644 ulog.spec.js create mode 100644 ulog.umd.js create mode 100644 ulog.umd.js.map create mode 100644 webpack.config.js diff --git a/.gitignore b/.gitignore index 5148e52..66fd66c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,37 +1,2 @@ -# Logs -logs -*.log -npm-debug.log* - -# Runtime data -pids -*.pid -*.seed - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (http://nodejs.org/api/addons.html) -build/Release - -# Dependency directories node_modules -jspm_packages - -# Optional npm cache directory -.npm - -# Optional REPL history -.node_repl_history +npm-debug.log* diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..a1d9faf --- /dev/null +++ b/.travis.yml @@ -0,0 +1,11 @@ +language: node_js +node_js: + - "node" + - "6" + - "5" + - "4" + - "4" + - "0.12" + - "0.11" + - "0.10" + - "iojs" diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..1dec0b0 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,161 @@ +## creative commons + +# Attribution 4.0 International + +Creative Commons Corporation (“Creative Commons”) is not a law firm and does not provide legal services or legal advice. Distribution of Creative Commons public licenses does not create a lawyer-client or other relationship. Creative Commons makes its licenses and related information available on an “as-is” basis. Creative Commons gives no warranties regarding its licenses, any material licensed under their terms and conditions, or any related information. Creative Commons disclaims all liability for damages resulting from their use to the fullest extent possible. + +### Using Creative Commons Public Licenses + +Creative Commons public licenses provide a standard set of terms and conditions that creators and other rights holders may use to share original works of authorship and other material subject to copyright and certain other rights specified in the public license below. The following considerations are for informational purposes only, are not exhaustive, and do not form part of our licenses. + +* __Considerations for licensors:__ Our public licenses are intended for use by those authorized to give the public permission to use material in ways otherwise restricted by copyright and certain other rights. Our licenses are irrevocable. Licensors should read and understand the terms and conditions of the license they choose before applying it. Licensors should also secure all rights necessary before applying our licenses so that the public can reuse the material as expected. Licensors should clearly mark any material not subject to the license. This includes other CC-licensed material, or material used under an exception or limitation to copyright. [More considerations for licensors](http://wiki.creativecommons.org/Considerations_for_licensors_and_licensees#Considerations_for_licensors). + +* __Considerations for the public:__ By using one of our public licenses, a licensor grants the public permission to use the licensed material under specified terms and conditions. If the licensor’s permission is not necessary for any reason–for example, because of any applicable exception or limitation to copyright–then that use is not regulated by the license. Our licenses grant only permissions under copyright and certain other rights that a licensor has authority to grant. Use of the licensed material may still be restricted for other reasons, including because others have copyright or other rights in the material. A licensor may make special requests, such as asking that all changes be marked or described. Although not required by our licenses, you are encouraged to respect those requests where reasonable. [More considerations for the public](http://wiki.creativecommons.org/Considerations_for_licensors_and_licensees#Considerations_for_licensees). + +## Creative Commons Attribution 4.0 International Public License + +By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions. + +### Section 1 – Definitions. + +a. __Adapted Material__ means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image. + +b. __Adapter's License__ means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this Public License. + +c. __Copyright and Similar Rights__ means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. + +d. __Effective Technological Measures__ means those measures that, in the absence of proper authority, may not be circumvented under laws fulfilling obligations under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, and/or similar international agreements. + +e. __Exceptions and Limitations__ means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material. + +f. __Licensed Material__ means the artistic or literary work, database, or other material to which the Licensor applied this Public License. + +g. __Licensed Rights__ means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license. + +h. __Licensor__ means the individual(s) or entity(ies) granting rights under this Public License. + +i. __Share__ means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them. + +j. __Sui Generis Database Rights__ means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world. + +k. __You__ means the individual or entity exercising the Licensed Rights under this Public License. Your has a corresponding meaning. + +### Section 2 – Scope. + +a. ___License grant.___ + + 1. Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to: + + A. reproduce and Share the Licensed Material, in whole or in part; and + + B. produce, reproduce, and Share Adapted Material. + + 2. __Exceptions and Limitations.__ For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions. + + 3. __Term.__ The term of this Public License is specified in Section 6(a). + + 4. __Media and formats; technical modifications allowed.__ The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section 2(a)(4) never produces Adapted Material. + + 5. __Downstream recipients.__ + + A. __Offer from the Licensor – Licensed Material.__ Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License. + + B. __No downstream restrictions.__ You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material. + + 6. __No endorsement.__ Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i). + +b. ___Other rights.___ + + 1. Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise. + + 2. Patent and trademark rights are not licensed under this Public License. + + 3. To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties. + +### Section 3 – License Conditions. + +Your exercise of the Licensed Rights is expressly made subject to the following conditions. + +a. ___Attribution.___ + + 1. If You Share the Licensed Material (including in modified form), You must: + + A. retain the following if it is supplied by the Licensor with the Licensed Material: + + i. identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated); + + ii. a copyright notice; + + iii. a notice that refers to this Public License; + + iv. a notice that refers to the disclaimer of warranties; + + v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable; + + B. indicate if You modified the Licensed Material and retain an indication of any previous modifications; and + + C. indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License. + + 2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information. + + 3. If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable. + + 4. If You Share Adapted Material You produce, the Adapter's License You apply must not prevent recipients of the Adapted Material from complying with this Public License. + +### Section 4 – Sui Generis Database Rights. + +Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material: + +a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database; + +b. if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material; and + +c. You must comply with the conditions in Section 3(a) if You Share all or a substantial portion of the contents of the database. + +For the avoidance of doubt, this Section 4 supplements and does not replace Your obligations under this Public License where the Licensed Rights include other Copyright and Similar Rights. + +### Section 5 – Disclaimer of Warranties and Limitation of Liability. + +a. __Unless otherwise separately undertaken by the Licensor, to the extent possible, the Licensor offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You.__ + +b. __To the extent possible, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this Public License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You.__ + +c. The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability. + +### Section 6 – Term and Termination. + +a. This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically. + +b. Where Your right to use the Licensed Material has terminated under Section 6(a), it reinstates: + + 1. automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or + + 2. upon express reinstatement by the Licensor. + + For the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License. + +c. For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License. + +d. Sections 1, 5, 6, 7, and 8 survive termination of this Public License. + +### Section 7 – Other Terms and Conditions. + +a. The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed. + +b. Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License. + +### Section 8 – Interpretation. + +*a. For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License. + +b. To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions. + +c. No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor. + +d. Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority. + +``` +Creative Commons is not a party to its public licenses. Notwithstanding, Creative Commons may elect to apply one of its public licenses to material it publishes and in those instances will be considered the “Licensor.” Except for the limited purpose of indicating that material is shared under a Creative Commons public license or as otherwise permitted by the Creative Commons policies published at [creativecommons.org/policies](http://creativecommons.org/policies), Creative Commons does not authorize the use of the trademark “Creative Commons” or any other trademark or logo of Creative Commons without its prior written consent including, without limitation, in connection with any unauthorized modifications to any of its public licenses or any other arrangements, understandings, or agreements concerning use of licensed material. For the avoidance of doubt, this paragraph does not form part of the public licenses. + +Creative Commons may be contacted at creativecommons.org +``` \ No newline at end of file diff --git a/README.md b/README.md index 72fa49c..ccba478 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,214 @@ -# ulog +# ulog v0.1.0 Microscopically small universal logging library + +[![npm](https://img.shields.io/npm/v/ulog.svg)](https://npmjs.com/package/ulog) +[![license](https://img.shields.io/npm/l/ulog.svg)](https://creativecommons.org/licenses/by/4.0/) +[![travis](https://img.shields.io/travis/Download/ulog.svg)](https://travis-ci.org/Download/ulog) +[![greenkeeper](https://img.shields.io/david/Download/ulog.svg)](https://greenkeeper.io/) +![mind BLOWN](https://img.shields.io/badge/mind-BLOWN-ff69b4.svg) + +. + +![logo](https://cdn.rawgit.com/download/ulog/0.1.0/ulog.png) + +Ulog builds on the experience gained building and using [Picolog](https://npmjs.com/package/picolog), +possibly the smallest universal logging library on NPM that supports levels, and adds some features +from [debug](https://npmjs.com/package/debug) that I missed. 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/0.1.0/ulog.umd.js) (~2kB, source) +* [ulog.min.js](https://cdn.rawgit.com/download/ulog/0.1.0/ulog.min.js) (~1.1kB, minified) + +## Install +```sh +npm install --save ulog +``` + +## Include in your app + +### require +*my-module.js* +```js +var ulog = require('ulog') +var log = ulog('my-module') +// or, shorthand +var log = require('ulog')('my-module') +``` + +### import +*my-module.js* +```sh +import ulog from 'ulog' +const log = ulog('my-module') +``` + +### AMD +*my-module.js* +```js +define(['ulog'], function(ulog){ + var log = ulog('my-module') +}); +``` + +### Script tag +```html + +``` + +## Logging methods +ulog defines 6 logging methods, which correspond with available log levels: +```js +log.error('This logs an ERROR message'); +log.warn('This logs a WARN message'); +log.info('This logs an INFO message'); +log.log('This logs a LOG message'); +log.debug('This logs a DEBUG message'); +log.trace('This logs a TRACE message'); +``` +ulog does **not** mess with your stacktrace or line numbers. Line numbers shown in the console +will be from your code, not from some wrapper function.. + +## Logging levels +ulog defines 6 logging levels, which correspond with the available logging methods: +```js +log.ERROR; // 1 +log.WARN; // 2 +log.INFO; // 3 +log.LOG; // 4 +log.DEBUG; // 5 +log.TRACE; // 6 +``` +In addition, there is a 7th level that completely disables all logging: +```js +log.NONE; // 0 +``` +To get or set the log level, we use the `log.level` property: +```js +if (log.level >= log.INFO) { + log.info('This message will be logged'); +} +log.level = log.WARN; +log.info('This info message will NOT be logged.'); +log.warn('This warning message WILL be logged.'); +log.level = log.NONE; +log.error('Logging is completely disabled.'); +``` + + +## Default log level +I've found that it makes sense to have different default log levels in the browser +and in Node. In Node, logging is often the only UI we have available and we (the devs) +are the only ones that will see that logging. In the browser, we have an alternative +UI (the webpage itself), so logging will be less useful for normal users. + +### In Node +In Node, the log level defaults to `log.INFO`. This allows you to use INFO, WARN and ERROR +when informing the user of stuff that happened. With Picolog I found I had to resort +to logging informational messages at WARN because I wanted them to be visible with the +default settings and this did not feel right. + +### In the browser +In the browser the log level defaults to `log.WARN`. This means INFO messages will be excluded, +but for most users these messages won't be relevant anyway and we can easily change the +log level in the browser using a query parameter in the URL. + +## Changing the log level +Changing the log level can be done in two ways: + 1. Programmatically, through the API + 2. Via a startup parameter + +### Changing the log level via the API +We can set the global log level directly on the `ulog` function: +```js +var ulog = require('ulog') +// ... +ulog.level = ulog.DEBUG +``` + +We can set the level of a specific module in much the same way: +```js +var log = ulog('my-module') +// ... +log.level = ulog.DEBUG +``` + +### Changing the log level via a startup paramter +We can set the initial global log level with a startup parameter. In Node we use +an environment variable, whereas in the browser we use a querystring parameter in the url. + +#### Environment variable +Set the environment variable `LOG` to the desired log level. + +```sh +$ LOG=info && node ./myapp.js +``` +or, in Windows: +```sh +$ set LOG=INFO && node ./myapp.js +``` + +#### Querystring parameter +Add the parameter `log` to the querystring of the page: + +`http://www.example.com/?`**`log=debug`** + +Both the uppercase and lowercase names of the log levels work, +as well as their numerical value. + +### Setting modules to DEBUG with a startup parameter +We can set some modules to DEBUG using a startup parameter. In this mode, they +will log any messages of level DEBUG or higher. + +#### Environment variable +Set the environment variable `DEBUG` to the module names: + +```sh +$ DEBUG=my-module && node ./myapp.js +``` +or, in Windows: +```sh +$ set DEBUG=my-module && node ./myapp.js +``` + +#### Querystring parameter +Add the parameter `debug` to the querystring of the page: + +`http://www.example.com/?`**`debug=my-module`** + +The `*` character may be used as a wildcard. Suppose for example your module has +loggers named "connect:bodyParser", "connect:compress" and "connect:session". +Instead of listing all three with `DEBUG=connect:bodyParser,connect:compress,connect:session`, +you may simply do `DEBUG=connect:*`. + +You can also exclude specific loggers by prefixing them with a "-" character. +For example, `DEBUG=*,-connect:*` would include all debuggers except those +starting with "connect:". + +## Using ulog as a polyfill +ulog supports all functions in the [NodeJS Console API](https://nodejs.org/api/console.html), +so you should be able to use it as a polyfill in environments where there is no `console` available (e.g. Nashorn): +```js +// assuming you already made sure there is a `global` object +global.console = log; +console.info('Nashorn can do logging to!'); +``` + +## Performance considerations +The logging methods on the `log` object that correspond to a log level which is higher than the +currently set level, are replaced by no-op methods. As such, you generally don't have to worry +about the performance overhead of leaving the log statements in the production code. There is +one exception to this rule though. If preparing the message itself is a costly operation, you +may want to surround the log code with an `if (log.level >= myLevel)` statement: +```js +if (log.level >= log.INFO) { + var message = doLotsOfWorkToGenerateLogMessage(); + log.info(message); +} +``` + +## Copyright +Copyright 2016 by [Stijn de Witt](http://StijnDeWitt.com). Some rights reserved. + +## License +Licensed under the [Creative Commons Attribution 4.0 International (CC-BY-4.0)](https://creativecommons.org/licenses/by/4.0/) Open Source license. diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..cd6f67b --- /dev/null +++ b/browser.js @@ -0,0 +1,14 @@ +var log = require('./ulog'), + qs = location.search.substring(1), + args = qs && qs.split('&'), + lvl, dbg, i, m + +for (i=0; m=args && args[i] && args[i].split('='); i++) { + (m[0] == 'log') && (lvl = m[1]) + (m[0] == 'debug') && (dbg = m[1]) +} + +log.con = function(){return window.console && console} +dbg && log.enable(dbg) +module.exports = log() +log.level = lvl || log.WARN diff --git a/microscopical.spec.js b/microscopical.spec.js new file mode 100644 index 0000000..1542ddf --- /dev/null +++ b/microscopical.spec.js @@ -0,0 +1,10 @@ +var expect = require('chai').expect +var fs = require('fs') +var node = typeof window != 'object' + +describe('ulog', function(){ + it('is microscopically small (less than 2000 bytes minified, about 1kB when gzipped)', function(){ + var stats = fs.statSync("ulog.min.js") + expect(stats.size).to.be.below(2000) + }) +}) diff --git a/node.js b/node.js new file mode 100644 index 0000000..c993ec0 --- /dev/null +++ b/node.js @@ -0,0 +1,79 @@ +var log = require('./ulog') + +var level, debug + +if (process.env.LOG ) {level = process.env.LOG} +if (process.env.DEBUG) {debug = process.env.DEBUG} + +var fd = process.env.DEBUG_FD && parseInt(process.env.DEBUG_FD, 10), + c = console; +if (typeof fd == 'number') { + var stream = createWritableStdioStream(fd), + logger = function(){stream.write(util.format.apply(this, arguments) + '\n')} + c = {error:logger, warn:logger, info:logger, log:logger, trace:logger} +} + +log.con = function(){return c} +if (debug) {log.enable(debug)} +module.exports = log() +log.level = level || log.INFO + +// SEE https://github.com/visionmedia/debug/blob/2.2.0/node.js#L144 +function createWritableStdioStream (fd) { + var stream; + var tty_wrap = process.binding('tty_wrap'); + + switch (tty_wrap.guessHandleType(fd)) { + case 'TTY': + stream = new tty.WriteStream(fd); + stream._type = 'tty'; + + // Hack to have stream not keep the event loop alive. + // See https://github.com/joyent/node/issues/1726 + if (stream._handle && stream._handle.unref) { + stream._handle.unref(); + } + break; + + case 'FILE': + var fs = require('fs'); + stream = new fs.SyncWriteStream(fd, { autoClose: false }); + stream._type = 'fs'; + break; + + case 'PIPE': + case 'TCP': + var net = require('net'); + stream = new net.Socket({ + fd: fd, + readable: false, + writable: true + }); + + // FIXME Should probably have an option in net.Socket to create a + // stream from an existing fd which is writable only. But for now + // we'll just add this hack and set the `readable` member to false. + // Test: ./node test/fixtures/echo.js < /etc/passwd + stream.readable = false; + stream.read = null; + stream._type = 'pipe'; + + // FIXME Hack to have stream not keep the event loop alive. + // See https://github.com/joyent/node/issues/1726 + if (stream._handle && stream._handle.unref) { + stream._handle.unref(); + } + break; + + default: + // Probably an error on in uv_guess_handle() + throw new Error('Implement me. Unknown stream file type!'); + } + + // For supporting legacy API we put the FD here. + stream.fd = fd; + + stream._isStdio = true; + + return stream; +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..7da0b16 --- /dev/null +++ b/package.json @@ -0,0 +1,62 @@ +{ + "name": "ulog", + "version": "0.1.0", + "description": "Microscopically small universal logging library", + "main": "node.js", + "browser": "browser.js", + "scripts": { + "clean": "rimraf ulog.umd.js && rimraf ulog.min.js", + "build-umd": "webpack --optimize-occurence-order --devtool source-map --output-path . --output-filename ulog.umd.js --output-library-target umd \"./browser.js\" ", + "build-min": "webpack -p --devtool hidden-source-map --output-path . --output-filename ulog.min.js --output-library-target this \"./browser.js\" ", + "build-all": "npm run -S build-umd && npm run -S build-min", + "build": "cross-env NODE_ENV=production npm run -S build-all", + "release": "npm run -S clean && npm run -S build", + "test": "mocha *.spec.js", + "test-dev": "webpack-dev-server --output-path test --output-filename ulog.spec.js \"mocha!./ulog.spec.js\" --content-base test --port 8888" + }, + "keywords": [ + "universal-components", + "microscopically small", + "small", + "tiny", + "universal", + "isomorphic", + "logging", + "logger", + "browser", + "node", + "nashorn", + "console", + "polyfill", + "1kB" + ], + "author": { + "name": "Stijn de Witt", + "email": "StijnDeWitt@hotmail.com", + "url": "http://StijnDeWitt.com" + }, + "copyright": "Copyright 2016 by [Stijn de Witt](http://StijnDeWitt.com). Some rights reserved.", + "license": "CC-BY-4.0", + "licenseUrl": "https://creativecommons.org/licenses/by/4.0/", + "repository": { + "type": "git", + "url": "https://github.com/download/ulog.git" + }, + "bugs": { + "url": "https://github.com/download/ulog/issues" + }, + "homepage": "http://github.com/download/ulog", + "devDependencies": { + "chai": "^3.4.1", + "cross-env": "^1.0.8", + "mocha": "^2.3.4", + "mocha-loader": "^0.7.1", + "path": "^0.12.7", + "rimraf": "^2.5.4", + "rollup": "^0.36.0", + "sinon": "^2.0.0-pre", + "webpack": "^1.12.12", + "webpack-dev-server": "^1.14.1" + }, + "dependencies": {} +} diff --git a/test/browser-source-map-support.js b/test/browser-source-map-support.js new file mode 100644 index 0000000..acb55fa --- /dev/null +++ b/test/browser-source-map-support.js @@ -0,0 +1,89 @@ +/* + * Support for source maps in V8 stack traces + * https://github.com/evanw/node-source-map-support + */ +(this.define||function(K,N){this.sourceMapSupport=N()})("browser-source-map-support",function(K){(function n(w,t,e){function r(g,b){if(!t[g]){if(!w[g]){var f="function"==typeof require&&require;if(!b&&f)return f(g,!0);if(l)return l(g,!0);throw Error("Cannot find module '"+g+"'");}f=t[g]={exports:{}};w[g][0].call(f.exports,function(b){var a=w[g][1][b];return r(a?a:b)},f,f.exports,n,w,t,e)}return t[g].exports}for(var l="function"==typeof require&&require,m=0;me)return-1;if(58>e)return e-48+52;if(91>e)return e-65;if(123>e)return e-97+26}var l="undefined"!==typeof Uint8Array?Uint8Array:Array;e.toByteArray=function(e){function g(a){c[d++]=a}var b,f,k,a,c;if(0>18&63)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(k>>12&63)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(k>>6&63)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(k&63),f+=k;switch(b){case 1:k=e[e.length-1];f+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(k>>2);f+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(k<< +4&63);f+="==";break;case 2:k=(e[e.length-2]<<8)+e[e.length-1],f+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(k>>10),f+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(k>>4&63),f+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(k<<2&63),f+="="}return f}})("undefined"===typeof t?this.base64js={}:t)},{}],4:[function(n,w,t){},{}],5:[function(n,w,t){function e(h,q,c){if(!(this instanceof e))return new e(h,q,c);var a=typeof h; +if("base64"===q&&"string"===a)for(h=h.trim?h.trim():h.replace(/^\s+|\s+$/g,"");0!==h.length%4;)h+="=";var d;if("number"===a)d=F(h);else if("string"===a)d=e.byteLength(h,q);else if("object"===a)d=F(h.length);else throw Error("First argument needs to be a number, array or string.");var b;e._useTypedArrays?b=e._augment(new Uint8Array(d)):(b=this,b.length=d,b._isBuffer=!0);if(e._useTypedArrays&&"number"===typeof h.byteLength)b._set(h);else{var f=h;if(E(f)||e.isBuffer(f)||f&&"object"===typeof f&&"number"=== +typeof f.length)for(q=0;q=a))return c?(c=h[q],q+ +1=a)){var d;c?(q+2>>0)):(q+1>>0);return d}}function g(h,q,a,c){c||(p("boolean"===typeof a,"missing or invalid endian"), +p(void 0!==q&&null!==q,"missing offset"),p(q+1=h.length))return h=l(h,q,a,!0),h&32768?-1*(65535-h+1):h}function b(h,q,a,c){c||(p("boolean"===typeof a,"missing or invalid endian"),p(void 0!==q&&null!==q,"missing offset"),p(q+3=h.length))return h=m(h,q,a,!0),h&2147483648?-1*(4294967295-h+1):h}function f(h,q,a,c){c||(p("boolean"===typeof a,"missing or invalid endian"),p(q+3=f))for(b=0,f=Math.min(f-c,2);b>>8* +(d?b:1-b)}function c(h,a,c,d,b){b||(p(void 0!==a&&null!==a,"missing value"),p("boolean"===typeof d,"missing or invalid endian"),p(void 0!==c&&null!==c,"missing offset"),p(c+3=f))for(b=0,f=Math.min(f-c,4);b>>8*(d?b:3-b)&255}function d(h,c,d,b,f){f||(p(void 0!==c&&null!==c,"missing value"),p("boolean"===typeof b,"missing or invalid endian"),p(void 0!==d&&null!==d,"missing offset"),p(d+1=h.length||(0<=c?a(h,c,d,b,f):a(h,65535+c+1,d,b,f))}function y(h,a,d,b,f){f||(p(void 0!==a&&null!==a,"missing value"),p("boolean"===typeof b,"missing or invalid endian"),p(void 0!==d&&null!==d,"missing offset"),p(d+3=h.length||(0<=a?c(h,a,d,b,f):c(h,4294967295+a+1,d,b,f))}function x(h,a,c,d,b){b||(p(void 0!==a&&null!==a,"missing value"),p("boolean"===typeof d, +"missing or invalid endian"),p(void 0!==c&&null!==c,"missing offset"),p(c+3=h.length||I.write(h,a,c,d,23,4)}function A(h,c,a,d,b){b||(p(void 0!==c&&null!==c,"missing value"),p("boolean"===typeof d,"missing or invalid endian"),p(void 0!==a&&null!==a,"missing offset"),p(a+7=h.length||I.write(h, +c,a,d,52,8)}function B(h,a,c){if("number"!==typeof h)return c;h=~~h;if(h>=a)return a;if(0<=h)return h;h+=a;return 0<=h?h:0}function F(h){h=~~Math.ceil(+h);return 0>h?0:h}function E(h){return(Array.isArray||function(h){return"[object Array]"===Object.prototype.toString.call(h)})(h)}function G(h){return 16>h?"0"+h.toString(16):h.toString(16)}function u(h){for(var a=[],c=0;c=d)a.push(h.charCodeAt(c));else{var b=c;55296<=d&&57343>=d&&c++;d=encodeURIComponent(h.slice(b, +c+1)).substr(1).split("%");for(b=0;b=c.length||b>=h.length);b++)c[b+a]=h[b];return b}function D(h){try{return decodeURIComponent(h)}catch(c){return String.fromCharCode(65533)}}function H(h,c){p("number"===typeof h,"cannot write a non-number as a number");p(0<=h,"specified a negative value for writing an unsigned value");p(h<= +c,"value is larger than maximum value for type");p(Math.floor(h)===h,"value has a fractional component")}function L(h,c,a){p("number"===typeof h,"cannot write a non-number as a number");p(h<=c,"value larger than maximum allowed value");p(h>=a,"value smaller than minimum allowed value");p(Math.floor(h)===h,"value has a fractional component")}function M(h,c,a){p("number"===typeof h,"cannot write a non-number as a number");p(h<=c,"value larger than maximum allowed value");p(h>=a,"value smaller than minimum allowed value")} +function p(h,c){if(!h)throw Error(c||"Failed assertion");}var J=n("base64-js"),I=n("ieee754");t.Buffer=e;t.SlowBuffer=e;t.INSPECT_MAX_BYTES=50;e.poolSize=8192;e._useTypedArrays=function(){try{var h=new ArrayBuffer(0),c=new Uint8Array(h);c.foo=function(){return 42};return 42===c.foo()&&"function"===typeof c.subarray}catch(a){return!1}}();e.isEncoding=function(h){switch(String(h).toLowerCase()){case "hex":case "utf8":case "utf-8":case "ascii":case "binary":case "base64":case "raw":case "ucs2":case "ucs-2":case "utf16le":case "utf-16le":return!0; +default:return!1}};e.isBuffer=function(h){return!(null===h||void 0===h||!h._isBuffer)};e.byteLength=function(h,c){var a;h+="";switch(c||"utf8"){case "hex":a=h.length/2;break;case "utf8":case "utf-8":a=u(h).length;break;case "ascii":case "binary":case "raw":a=h.length;break;case "base64":a=J.toByteArray(h).length;break;case "ucs2":case "ucs-2":case "utf16le":case "utf-16le":a=2*h.length;break;default:throw Error("Unknown encoding");}return a};e.concat=function(h,c){p(E(h),"Usage: Buffer.concat(list, [totalLength])\nlist should be an Array."); +if(0===h.length)return new e(0);if(1===h.length)return h[0];var a;if("number"!==typeof c)for(a=c=0;ab&&(a=b)):a=b;d=String(d||"utf8").toLowerCase();switch(d){case "hex":c=Number(c)||0;d=this.length-c;a?(a=Number(a),a>d&&(a=d)):a=d;d= +h.length;p(0===d%2,"Invalid hex string");a>d/2&&(a=d/2);for(d=0;d>8,f%=256,b.push(f),b.push(d);h=e._charsWritten=z(b,this,c,a);break;default:throw Error("Unknown encoding");}return h};e.prototype.toString=function(a,c,d){a=String(a||"utf8").toLowerCase();c=Number(c)||0;d=void 0!==d?Number(d):d=this.length;if(d===c)return"";switch(a){case "hex":a=this.length;if(!c||0>c)c=0;if(!d||0>d||d>a)d=a;for(a="";c=this[c]?(a+=D(b)+String.fromCharCode(this[c]), +b=""):b+="%"+this[c].toString(16);d=a+D(b);break;case "ascii":d=r(this,c,d);break;case "binary":d=r(this,c,d);break;case "base64":d=0===c&&d===this.length?J.fromByteArray(this):J.fromByteArray(this.slice(c,d));break;case "ucs2":case "ucs-2":case "utf16le":case "utf-16le":d=this.slice(c,d);c="";for(a=0;a=d,"sourceEnd < sourceStart"),p(0<=c&&cthis.length&&(b=this.length),a.length-cb||!e._useTypedArrays)for(var f=0;f=this.length))return this[a]};e.prototype.readUInt16LE=function(a,c){return l(this,a,!0,c)};e.prototype.readUInt16BE=function(a,c){return l(this,a,!1,c)};e.prototype.readUInt32LE=function(a,c){return m(this,a,!0,c)};e.prototype.readUInt32BE=function(a,c){return m(this,a,!1,c)};e.prototype.readInt8=function(a,c){c||(p(void 0!==a&&null!==a,"missing offset"),p(a= +this.length))return this[a]&128?-1*(255-this[a]+1):this[a]};e.prototype.readInt16LE=function(a,c){return g(this,a,!0,c)};e.prototype.readInt16BE=function(a,c){return g(this,a,!1,c)};e.prototype.readInt32LE=function(a,c){return b(this,a,!0,c)};e.prototype.readInt32BE=function(a,c){return b(this,a,!1,c)};e.prototype.readFloatLE=function(a,c){return f(this,a,!0,c)};e.prototype.readFloatBE=function(a,c){return f(this,a,!1,c)};e.prototype.readDoubleLE=function(a,c){return k(this,a,!0,c)};e.prototype.readDoubleBE= +function(a,c){return k(this,a,!1,c)};e.prototype.writeUInt8=function(a,c,d){d||(p(void 0!==a&&null!==a,"missing value"),p(void 0!==c&&null!==c,"missing offset"),p(c=this.length||(this[c]=a)};e.prototype.writeUInt16LE=function(c,d,b){a(this,c,d,!0,b)};e.prototype.writeUInt16BE=function(c,d,b){a(this,c,d,!1,b)};e.prototype.writeUInt32LE=function(a,d,b){c(this,a,d,!0,b)};e.prototype.writeUInt32BE=function(a,d,b){c(this,a,d,!1,b)};e.prototype.writeInt8= +function(a,c,d){d||(p(void 0!==a&&null!==a,"missing value"),p(void 0!==c&&null!==c,"missing offset"),p(c=this.length||(0<=a?this.writeUInt8(a,c,d):this.writeUInt8(255+a+1,c,d))};e.prototype.writeInt16LE=function(a,c,b){d(this,a,c,!0,b)};e.prototype.writeInt16BE=function(a,c,b){d(this,a,c,!1,b)};e.prototype.writeInt32LE=function(a,c,d){y(this,a,c,!0,d)};e.prototype.writeInt32BE=function(a,c,d){y(this,a,c,!1,d)};e.prototype.writeFloatLE= +function(a,c,d){x(this,a,c,!0,d)};e.prototype.writeFloatBE=function(a,c,d){x(this,a,c,!1,d)};e.prototype.writeDoubleLE=function(a,c,d){A(this,a,c,!0,d)};e.prototype.writeDoubleBE=function(a,c,d){A(this,a,c,!1,d)};e.prototype.fill=function(a,c,d){a||(a=0);c||(c=0);d||(d=this.length);"string"===typeof a&&(a=a.charCodeAt(0));p("number"===typeof a&&!isNaN(a),"value is not a number");p(d>=c,"end < start");if(d!==c&&0!==this.length)for(p(0<=c&&c"};e.prototype.toArrayBuffer=function(){if("undefined"!==typeof Uint8Array){if(e._useTypedArrays)return(new e(this)).buffer;for(var a=new Uint8Array(this.length),c=0,d=a.length;c>1,a=-7;g=l?g-1:0;var c=l?-1:1,d=e[r+g];g+=c;l=d&(1<<-a)-1;d>>=-a;for(a+=b;0>=-a;for(a+=m;0>1,d=23===g?Math.pow(2,-24)-Math.pow(2,-77):0;b=m?0:b-1;var y=m?1:-1,x=0>r||0===r&&0>1/r?1:0;r=Math.abs(r);isNaN(r)||Infinity===r?(r=isNaN(r)?1:0,m=a):(m=Math.floor(Math.log(r)/Math.LN2),1>r*(f=Math.pow(2,-m))&&(m--,f*=2),r=1<=m+c?r+d/f:r+d*Math.pow(2,1-c),2<=r*f&&(m++,f/=2),m+c>=a?(r=0,m=a):1<=m+c?(r=(r*f-1)*Math.pow(2,g),m+=c):(r=r*Math.pow(2,c-1)*Math.pow(2,g),m=0));for(;8<=g;e[l+b]=r&255,b+=y,r/=256,g-=8);m=m<d?[]:a.slice(c,d-c+1)}b=t.resolve(b).substr(1);f=t.resolve(f).substr(1);for(var a=e(b.split("/")),c=e(f.split("/")),d=Math.min(a.length,c.length),g=d,x=0;xf&&(f=b.length+f);return b.substr(f,e)}}).call(this,n("node_modules/process/browser.js"))}, +{"node_modules/process/browser.js":8}],8:[function(n,w,t){function e(){}n=w.exports={};n.nextTick=function(){if("undefined"!==typeof window&&window.setImmediate)return function(e){return window.setImmediate(e)};if("undefined"!==typeof window&&window.postMessage&&window.addEventListener){var e=[];window.addEventListener("message",function(l){var m=l.source;m!==window&&null!==m||"process-tick"!==l.data||(l.stopPropagation(),0b?(-b<<1)+1:(b<<1)+0;do b=k&31,k>>>=5,0=k)throw Error("Expected more digits in base 64 VLQ value.");y=g.decode(b.charAt(e++));d=!!(y&32);y&=31;a+=y<>1;return{value:1===(a&1)?-k:k,rest:b.slice(e)}}})},{"./base64":12,amdefine:2}],12:[function(n,w,t){if("function"!==typeof e)var e=n("amdefine")(w,n);e(function(e,l,m){var g={},b={};"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("").forEach(function(e, +k){g[e]=k;b[k]=e});l.encode=function(e){if(e in b)return b[e];throw new TypeError("Must be between 0 and 63: "+e);};l.decode=function(b){if(b in g)return g[b];throw new TypeError("Not a valid base 64 digit: "+b);}})},{amdefine:2}],13:[function(n,w,t){if("function"!==typeof e)var e=n("amdefine")(w,n);e(function(e,l,m){function g(b,e,k,a,c){var d=Math.floor((e-b)/2)+b,y=c(k,a[d],!0);return 0===y?a[d]:0b?null:a[b]}l.search=function(b,e,k){return 0=a[b])throw new TypeError("Line must be greater than or equal to 1, got "+a[b]);if(0>a[e])throw new TypeError("Column must be greater than or equal to 0, got "+ +a[e]);return f.search(a,d,g)};g.prototype.originalPositionFor=function(a){a={generatedLine:b.getArg(a,"line"),generatedColumn:b.getArg(a,"column")};if(a=this._findMapping(a,this._generatedMappings,"generatedLine","generatedColumn",b.compareByGeneratedPositions)){var d=b.getArg(a,"source",null);d&&this.sourceRoot&&(d=b.join(this.sourceRoot,d));return{source:d,line:b.getArg(a,"originalLine",null),column:b.getArg(a,"originalColumn",null),name:b.getArg(a,"name",null)}}return{source:null,line:null,column:null, +name:null}};g.prototype.sourceContentFor=function(a){if(!this.sourcesContent)return null;this.sourceRoot&&(a=b.relative(this.sourceRoot,a));if(this._sources.has(a))return this.sourcesContent[this._sources.indexOf(a)];var d;if(this.sourceRoot&&(d=b.urlParse(this.sourceRoot))){var e=a.replace(/^file:\/\//,"");if("file"==d.scheme&&this._sources.has(e))return this.sourcesContent[this._sources.indexOf(e)];if((!d.path||"/"==d.path)&&this._sources.has("/"+a))return this.sourcesContent[this._sources.indexOf("/"+ +a)]}throw Error('"'+a+'" is not in the SourceMap.');};g.prototype.generatedPositionFor=function(a){a={source:b.getArg(a,"source"),originalLine:b.getArg(a,"line"),originalColumn:b.getArg(a,"column")};this.sourceRoot&&(a.source=b.relative(this.sourceRoot,a.source));return(a=this._findMapping(a,this._originalMappings,"originalLine","originalColumn",b.compareByOriginalPositions))?{line:b.getArg(a,"generatedLine",null),column:b.getArg(a,"generatedColumn",null)}:{line:null,column:null}};g.GENERATED_ORDER= +1;g.ORIGINAL_ORDER=2;g.prototype.eachMapping=function(a,d,e){d=d||null;switch(e||g.GENERATED_ORDER){case g.GENERATED_ORDER:e=this._generatedMappings;break;case g.ORIGINAL_ORDER:e=this._originalMappings;break;default:throw Error("Unknown order of iteration.");}var f=this.sourceRoot;e.map(function(a){var c=a.source;c&&f&&(c=b.join(f,c));return{source:c,generatedLine:a.generatedLine,generatedColumn:a.generatedColumn,originalLine:a.originalLine,originalColumn:a.originalColumn,name:a.name}}).forEach(a, +d)};l.SourceMapConsumer=g})},{"./array-set":10,"./base64-vlq":11,"./binary-search":13,"./util":17,amdefine:2}],15:[function(n,w,t){if("function"!==typeof e)var e=n("amdefine")(w,n);e(function(e,l,m){function g(a){this._file=f.getArg(a,"file");this._sourceRoot=f.getArg(a,"sourceRoot",null);this._sources=new k;this._names=new k;this._mappings=[];this._sourcesContents=null}var b=e("./base64-vlq"),f=e("./util"),k=e("./array-set").ArraySet;g.prototype._version=3;g.fromSourceMap=function(a){var c=a.sourceRoot, +d=new g({file:a.file,sourceRoot:c});a.eachMapping(function(a){var b={generated:{line:a.generatedLine,column:a.generatedColumn}};a.source&&(b.source=a.source,c&&(b.source=f.relative(c,b.source)),b.original={line:a.originalLine,column:a.originalColumn},a.name&&(b.name=a.name));d.addMapping(b)});a.sources.forEach(function(c){var b=a.sourceContentFor(c);b&&d.setSourceContent(c,b)});return d};g.prototype.addMapping=function(a){var c=f.getArg(a,"generated"),d=f.getArg(a,"original",null),b=f.getArg(a,"source", +null);a=f.getArg(a,"name",null);this._validateMapping(c,d,b,a);b&&!this._sources.has(b)&&this._sources.add(b);a&&!this._names.has(a)&&this._names.add(a);this._mappings.push({generatedLine:c.line,generatedColumn:c.column,originalLine:null!=d&&d.line,originalColumn:null!=d&&d.column,source:b,name:a})};g.prototype.setSourceContent=function(a,c){var d=a;this._sourceRoot&&(d=f.relative(this._sourceRoot,d));null!==c?(this._sourcesContents||(this._sourcesContents={}),this._sourcesContents[f.toSetString(d)]= +c):(delete this._sourcesContents[f.toSetString(d)],0===Object.keys(this._sourcesContents).length&&(this._sourcesContents=null))};g.prototype.applySourceMap=function(a,c){c||(c=a.file);var d=this._sourceRoot;d&&(c=f.relative(d,c));var b=new k,e=new k;this._mappings.forEach(function(g){if(g.source===c&&g.originalLine){var k=a.originalPositionFor({line:g.originalLine,column:g.originalColumn});null!==k.source&&(g.source=d?f.relative(d,k.source):k.source,g.originalLine=k.line,g.originalColumn=k.column, +null!==k.name&&null!==g.name&&(g.name=k.name))}(k=g.source)&&!b.has(k)&&b.add(k);(g=g.name)&&!e.has(g)&&e.add(g)},this);this._sources=b;this._names=e;a.sources.forEach(function(c){var b=a.sourceContentFor(c);b&&(d&&(c=f.relative(d,c)),this.setSourceContent(c,b))},this)};g.prototype._validateMapping=function(a,c,d,b){if(!(a&&"line"in a&&"column"in a&&0f)-(e",a=this.getLineNumber(),null!=a&&(b+=":"+a,(a=this.getColumnNumber())&&(b+=":"+a)));a="";var c=this.getFunctionName(),d=!0,e=this.isConstructor();if(this.isToplevel()||e)e?a+="new "+(c||""):c?a+=c:(a+=b,d=!1);else{var e=this.getTypeName(),f=this.getMethodName();c?(e&&0!=c.indexOf(e)&&(a+=e+"."),a+=c,f&&c.indexOf("."+ +f)!=c.length-f.length-1&&(a+=" [as "+f+"]")):a+=e+"."+(f||"")}d&&(a+=" ("+b+")");return a}function c(b){var c={};Object.getOwnPropertyNames(Object.getPrototypeOf(b)).forEach(function(a){c[a]=/^(?:is|get)/.test(a)?function(){return b[a].call(b)}:b[a]});c.toString=a;return c}function d(a){var b=a.getFileName()||a.getScriptNameOrSourceURL();if(b){var d=a.getLineNumber(),e=a.getColumnNumber()-1;1!==d||l()||a.isEval()||(e-=62);var g=f({source:b,line:d,column:e});a=c(a);a.getFileName=function(){return g.source}; +a.getLineNumber=function(){return g.line};a.getColumnNumber=function(){return g.column+1};a.getScriptNameOrSourceURL=function(){return g.source};return a}var m=a.isEval()&&a.getEvalOrigin();m&&(m=k(m),a=c(a),a.getEvalOrigin=function(){return m});return a}function w(a,b){u&&(z={},D={});return a+b.map(function(a){return"\n at "+d(a)}).join("")}function x(a){var b=/\n at [^(]+ \((.*):(\d+):(\d+)\)/.exec(a.stack);if(b){a=b[1];var c=+b[2],b=+b[3],d=z[a];!d&&E.existsSync(a)&&(d=E.readFileSync(a,"utf8")); +if(d&&(d=d.split(/(?:\r\n|\r|\n)/)[c-1]))return a+":"+c+"\n"+d+"\n"+Array(b).join(" ")+"^"}return null}function A(){var a=e.emit;e.emit=function(b){if("uncaughtException"===b){var c=arguments[1]&&arguments[1].stack,d=0 + + + ulog + + + + + + + \ No newline at end of file diff --git a/ulog.js b/ulog.js new file mode 100644 index 0000000..fac0a8c --- /dev/null +++ b/ulog.js @@ -0,0 +1,82 @@ +function log(name){ + return name + ? (mods[name] ? mods[name] : (mods[name] = enhance({name:name}, log))) + : (log.debug ? log : enhance(log)) +} + +log.ulog = {version:'0.1.0'} + +log.enable = function(str) { + var i, split = (str || '').split(/[\s,]+/); + for (i=0; i= 0 && lvl <= 6) {level = lvl} + } + patch(o, parent) + if (!parent) {for (mod in mods) {patch(mods[mod], o)}} + } + }) + patch(o, parent) + o.dir = bnd('dir') || nop + o.time = bnd('time') || nop + o.timeEnd = bnd('timeEnd') || nop + o.assert = function(){ + var a=[].concat.apply([], arguments), ok=a.shift() + if (!ok) {o.error.apply(o, a)} + } + return o +} + +function patch(o, parent) { + var lvl = Math.max(o.name && log.enabled(o.name) && o.DEBUG || o.level, o.level) + for (var i=0,name; name=names[i]; i++) { + o[name] = lvl <= i + ? nop + : ( + bnd(name) || + (typeof print == 'function' && print) || + function(){ + if (log.con()) { + patch(o) + o[name].apply(o, arguments) + } + } + ) + } +} + +function bnd(n,c){return (c = log.con()) && (c[n]||c.log).bind(c)} +function nop(){} diff --git a/ulog.min.js b/ulog.min.js new file mode 100644 index 0000000..35432d0 --- /dev/null +++ b/ulog.min.js @@ -0,0 +1 @@ +!function(e,n){for(var r in n)e[r]=n[r]}(this,function(e){function n(t){if(r[t])return r[t].exports;var o=r[t]={exports:{},id:t,loaded:!1};return e[t].call(o.exports,o,o.exports,n),o.loaded=!0,o.exports}var r={};return n.m=e,n.c=r,n.p="",n(0)}([function(e,n,r){var t,o,i,u,l=r(1),a=location.search.substring(1),f=a&&a.split("&");for(i=0;u=f&&f[i]&&f[i].split("=");i++)"log"==u[0]&&(t=u[1])("debug"==u[0])&&(o=u[1]);l.con=function(){return window.console&&console},o&&l.enable(o),e.exports=l(),l.level=t||l.WARN},function(e,n){function r(e){return e?f[e]?f[e]:f[e]=t({name:e},r):r.debug?r:t(r)}function t(e,n,r){e.NONE=0;for(var t in l)e[t]=l[t];return Object.defineProperty(e,"level",{get:function(){return void 0!==r?r:n&&n.level},set:function(t){if(void 0===t&&n)r=void 0;else{var i=t&&(Number(t)!==Number(t)?e[t.toUpperCase()]:Number(t));i>=0&&i<=6&&(r=i)}if(o(e,n),!n)for(mod in f)o(f[mod],e)}}),o(e,n),e.dir=i("dir")||u,e.time=i("time")||u,e.timeEnd=i("timeEnd")||u,e.assert=function(){var n=[].concat.apply([],arguments),r=n.shift();r||e.error.apply(e,n)},e}function o(e,n){for(var t,l=Math.max(e.name&&r.enabled(e.name)&&e.DEBUG||e.level,e.level),f=0;t=a[f];f++)e[t]=l<=f?u:i(t)||"function"==typeof print&&print||function(){r.con()&&(o(e),e[t].apply(e,arguments))}}function i(e,n){return(n=r.con())&&(n[e]||n.log).bind(n)}function u(){}r.ulog={version:"0.1.0"},r.enable=function(e){var n,t=(e||"").split(/[\s,]+/);for(n=0;n= 0 && lvl <= 6) {level = lvl}\r\n\t\t\t\t}\r\n\t\t\t\tpatch(o, parent)\r\n\t\t\t\tif (!parent) {for (mod in mods) {patch(mods[mod], o)}}\r\n\t\t\t}\r\n\t\t})\r\n\t\tpatch(o, parent)\r\n\t\to.dir = bnd('dir') || nop\r\n\t\to.time = bnd('time') || nop\r\n\t\to.timeEnd = bnd('timeEnd') || nop\r\n\t\to.assert = function(){\r\n\t\t\tvar a=[].concat.apply([], arguments), ok=a.shift()\r\n\t\t\tif (!ok) {o.error.apply(o, a)}\r\n\t\t}\r\n\t\treturn o\r\n\t}\r\n\t\r\n\tfunction patch(o, parent) {\r\n\t\tvar lvl = Math.max(o.name && log.enabled(o.name) && o.DEBUG || o.level, o.level)\r\n\t\tfor (var i=0,name; name=names[i]; i++) {\r\n\t\t\to[name] = lvl <= i\r\n\t\t\t\t? nop\r\n\t\t\t\t: (\r\n\t\t\t\t\tbnd(name) ||\r\n\t\t\t\t\t(typeof print == 'function' && print) ||\r\n\t\t\t\t\tfunction(){\r\n\t\t\t\t\t\tif (log.con()) {\r\n\t\t\t\t\t\t\tpatch(o)\r\n\t\t\t\t\t\t\to[name].apply(o, arguments)\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t)\r\n\t\t}\r\n\t}\r\n\t\r\n\tfunction bnd(n,c){return (c = log.con()) && (c[n]||c.log).bind(c)}\r\n\tfunction nop(){}\r\n\n\n/***/ }\n/******/ ])));\n\n\n/** WEBPACK FOOTER **\n ** ulog.min.js\n **/"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap fb172776aaa97a4cd275\n **/","var log = require('./ulog'),\r\n\t\tqs = location.search.substring(1),\r\n\t\targs = qs && qs.split('&'),\r\n\t\tlvl, dbg, i, m\r\n\r\nfor (i=0; m=args && args[i] && args[i].split('='); i++) {\r\n\t(m[0] == 'log') && (lvl = m[1])\r\n\t(m[0] == 'debug') && (dbg = m[1])\r\n}\r\n\r\nlog.con = function(){return window.console && console}\r\ndbg && log.enable(dbg)\r\nmodule.exports = log()\r\nlog.level = lvl || log.WARN\r\n\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./browser.js\n ** module id = 0\n ** module chunks = 0\n **/","function log(name){\r\n\treturn name\r\n\t\t? (mods[name] ? mods[name] : (mods[name] = enhance({name:name}, log)))\r\n\t\t: (log.debug ? log : enhance(log))\r\n}\r\n\r\nlog.ulog = {version:'0.1.0'}\r\n\r\nlog.enable = function(str) {\r\n\tvar i, split = (str || '').split(/[\\s,]+/);\r\n\tfor (i=0; i= 0 && lvl <= 6) {level = lvl}\r\n\t\t\t}\r\n\t\t\tpatch(o, parent)\r\n\t\t\tif (!parent) {for (mod in mods) {patch(mods[mod], o)}}\r\n\t\t}\r\n\t})\r\n\tpatch(o, parent)\r\n\to.dir = bnd('dir') || nop\r\n\to.time = bnd('time') || nop\r\n\to.timeEnd = bnd('timeEnd') || nop\r\n\to.assert = function(){\r\n\t\tvar a=[].concat.apply([], arguments), ok=a.shift()\r\n\t\tif (!ok) {o.error.apply(o, a)}\r\n\t}\r\n\treturn o\r\n}\r\n\r\nfunction patch(o, parent) {\r\n\tvar lvl = Math.max(o.name && log.enabled(o.name) && o.DEBUG || o.level, o.level)\r\n\tfor (var i=0,name; name=names[i]; i++) {\r\n\t\to[name] = lvl <= i\r\n\t\t\t? nop\r\n\t\t\t: (\r\n\t\t\t\tbnd(name) ||\r\n\t\t\t\t(typeof print == 'function' && print) ||\r\n\t\t\t\tfunction(){\r\n\t\t\t\t\tif (log.con()) {\r\n\t\t\t\t\t\tpatch(o)\r\n\t\t\t\t\t\to[name].apply(o, arguments)\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t)\r\n\t}\r\n}\r\n\r\nfunction bnd(n,c){return (c = log.con()) && (c[n]||c.log).bind(c)}\r\nfunction nop(){}\r\n\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./ulog.js\n ** module id = 1\n ** module chunks = 0\n **/"],"sourceRoot":""} \ No newline at end of file diff --git a/ulog.min.js.zip b/ulog.min.js.zip new file mode 100644 index 0000000000000000000000000000000000000000..31fcc6a698c52a630c7952cf7d83d1ba8b9f0980 GIT binary patch literal 1129 zcmV-v1eW_yO9KQH000080F1ghNsI?<$;|@*096M701E&B0Cj9{XD)4NZZ2wbZBo0YyB&)2@cA5U%E#Qq+tdxZ#&GMu{K&H922Sinfbe zo-U5GI7$R1a%pj`B_UkXC2MJNjhS0^3O7AIQt^f>Y3UutGpS6T1tZ}gv-v@|X6L-E z^ggIdnMF}1T&*fkNkrHxWUi9SRU^wNDw8Vh*U?0xNwruoqRgI1*(6IepdJr*QbtJu zyJnO#RG40|QX)56UgBk^0o#vC7v@J$I-?+phC|Cu6e$5Z+bN)iaTv2B6=hrr1>ZqQ ze?BYm>B;tO%l|0}MU zG`=XYxR2#BimFHQAv&Igv;_G{Tj7ePE6M@{A&rtFF?9VRW4G%y9}EV8;*zi5*3%AC!p3g`bYmMzqyU1D&Q(4WQgTiCOyvh7Q9J8MkMBqgf*@1z@AVEfhc)of1@g=(N ztHXyqw9<0rWtNobs$47vRy>mBx``|55g8fZCRny#HJEZ%V;^Fny6t?vrbGZryADDI z^Wf|PWP;4v2~QR9j9j8x4jzIFjbuNcwZN8TVuu|^^%cJxe6F>kL9IM}2kTH6lcl&L zmZarl3Z`PfPz~-S1w=*IFdJ?spB+yZxBD5QF&+Am$L#36KddyS#3woo3y|R;EYvE? zf!_Xn^Y)$-adS-=C$}&;5^#E~ov0gkpc;P6wy@v)tSR|I7SPYHFxwX724O7D|8Li8 zhgdFj#fPz#Cs@V5xUQmi*U@7exDdAo=h3+TLtI7sI7O2;7jnpjTA z^`Nue|3=BvX1jg2jqmU<=;FKl)!P^E;(Pq{yO;5O-jOkWz&~uCJln(%Tb%d9^!WzA z990bYT+<2TGz@VByf#0^5zq$y;=e4H*i#OdHpSfi22e`@0zUv0000080F1ghNsI?< z$;|@*096M701E&l000000000W000000001WY;R{SZE0>UYI6zzAOHXW000317y#sK v;-7LC(gAY{;Gc3A(g7hkXIbtQ(g9FQ1qJ{B000310RUY9008y_00000Tdf5Q literal 0 HcmV?d00001 diff --git a/ulog.png b/ulog.png new file mode 100644 index 0000000000000000000000000000000000000000..fb95649fcd78c9f82f03f168ab37929fdb62d1b1 GIT binary patch literal 17637 zcmV)sK$yRYP)zAkdgxf19*IktE;R60s>D^RRaS9Z*p{|rl$%E z4n{~#Mny%tyufjDcNiNYmY0|i5fg8AZ%M0H0-Ml(r!N=ZmHO@dHPO*c`7Qc_Yn zRf|khc~(|dKwFYpSy^9SUq@q{W@Th&XlPAqr)+I)QE;+lZIW?ua#MA>b#-@Fc)@sh zc3FDIdV73ad(38f!(M&Tet&>qfY@q&%z}Y`V}agmf7OG8g>Hb_e}tijhJ$c`;Ae&3 zYlGl#g5ZdVhH`@7Ylh%&h2VjVjdFzGiHeJhiidEA;ChMFjg5|gi@SJ?-H?%zl$4Z| zmYA2Anu?Uum6xoTnwx}}-J6@7oSdDGoW`A`?jiM5oZrKXgl z+@+_gsHv)|tF5N1!mX~apRDDguII3_vZb)-v9rCZvel-t;j^^0&9jBKx45*p$E~*P zxVpT%yuG}=z`wx5y1?PW!^FkL$H&OZ%FE5o&d|!v;?U94(9_w~*4EV4+|}6K*V^CN z+S=IL;M&~b+uq{b-{alj<=)`q-r?on;pgGu;^5-t;N$1wE-3+gMO><>%|>=jrF?=;-L^=jiO`>FVj}>FMd~=<4n2>g?+4?d$97 z>g(?7?CtCA@9pjF?d|XF?(gpI@bB;N@bU8V^Yi-p`v3p`tE^Lq0000?bW%=J00RgM z4-*$4AtEX?G&VUxOH5KyWMpM#Yj=Huf{KfckCT;}p{lU7yuH4^z{1JR&Ct=))YRD9 z-{Ioo+bIF@A2{U`TYL=RF3qa002QqNkltCOZ(S?9FVtm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OwfG%t!}2ZNF})0SXz5Pu;5(+I=}xHVL&~qYAm?h*>=88jAHZ>EVL$R{7U#w zcN7=!pyjx@0_+`XvE^5_xJmf$T@RwaJ>9xsZ8{|Qy(7WK9S?rrd`8@__B}m_eG+8A zx{pml?<(`BOc3?=xVS~*`w`q@A)VSQ?nCjus@Q+%kXXD42?+@a2?+@a2?+@a3BA!@ Y0f->4i)53a=l}o!07*qoM6N<$f?tp^DgXcg literal 0 HcmV?d00001 diff --git a/ulog.spec.js b/ulog.spec.js new file mode 100644 index 0000000..32c860f --- /dev/null +++ b/ulog.spec.js @@ -0,0 +1,580 @@ +var expect = require('chai').expect +var sinon = require('sinon') + +var isNode = typeof window != 'object' + +var testConsole = { + error: sinon.spy(console.error.bind(console)), + warn: sinon.spy(console.warn.bind(console)), + info: sinon.spy(console.info.bind(console)), + log: sinon.spy(console.log.bind(console)), + debug: sinon.spy(console.log.bind(console)), + trace: sinon.spy(console.trace.bind(console)), + assert: sinon.spy(console.assert.bind(console)), + reset: function(){ + testConsole.error.reset() + testConsole.warn.reset() + testConsole.info.reset() + testConsole.log.reset() + testConsole.debug.reset() + testConsole.trace.reset() + testConsole.assert.reset() + } +} + +var log = require('./') +log.con = function(){return testConsole} +log.level = log.level // trigger patch +var named = require('./')('my-module-name') + + +describe('var log = require(\'ulog\')', function(){ + it('yields a function `log`', function(){ + expect(log).to.be.a('function') + }) +}) + +describe('log', function(){ + it('implements the Console API', function(){ + expect(log).to.have.a.property('error') + expect(log.error).to.be.a('function') + expect(log).to.have.a.property('warn') + expect(log.warn).to.be.a('function') + expect(log).to.have.a.property('info') + expect(log.info).to.be.a('function') + expect(log).to.have.a.property('log') + expect(log.log).to.be.a('function') + expect(log).to.have.a.property('trace') + expect(log.trace).to.be.a('function') + expect(log).to.have.a.property('dir') + expect(log.dir).to.be.a('function') + expect(log).to.have.a.property('time') + expect(log.time).to.be.a('function') + expect(log).to.have.a.property('timeEnd') + expect(log.timeEnd).to.be.a('function') + expect(log).to.have.a.property('assert') + expect(log.assert).to.be.a('function') + }) + + it('has an additional logging method named `debug`', function(){ + expect(log).to.have.a.property('debug') + expect(log.debug).to.be.a('function') + }) + + it('can log messages using methods `error`, `warn`, `info`, `log`, `debug` and `trace`', function(){ + testConsole.reset() + expect(log.level).to.equal(isNode ? log.INFO : log.WARN) + expect(testConsole.error.callCount).to.equal(0) + log.error('Message logged with log.error') + expect(testConsole.error.callCount).to.equal(1) + + log.warn('Message logged with log.warn') + expect(testConsole.warn.callCount).to.equal(1) + + log.info('Message logged with log.info') + expect(testConsole.info.callCount).to.equal(isNode ? 1 : 0) // because of different default log levels + + log.log('Message logged with log.log') + expect(testConsole.log.callCount).to.equal(0) // below log level + + log.debug('Message logged with log.debug') + expect(testConsole.debug.callCount).to.equal(0) // below log level + + log.trace('Message logged with log.trace') + expect(testConsole.trace.callCount).to.equal(0) // below log level + + testConsole.reset() + }) + + it('has constants for the log levels `ERROR`, `WARN`, `INFO`, `LOG`, `DEBUG` and `TRACE`', function(){ + expect(log).to.have.a.property('ERROR') + expect(log.ERROR).to.equal(1) + expect(log).to.have.a.property('WARN') + expect(log.WARN).to.equal(2) + expect(log).to.have.a.property('INFO') + expect(log.INFO).to.equal(3) + expect(log).to.have.a.property('LOG') + expect(log.LOG).to.equal(4) + expect(log).to.have.a.property('DEBUG') + expect(log.DEBUG).to.equal(5) + expect(log).to.have.a.property('TRACE') + expect(log.TRACE).to.equal(6) + }) + + it('has an additional constant for the special log level `NONE`, which suppresses all logging', function(){ + expect(log).to.have.a.property('NONE') + expect(log.NONE).to.equal(0) + }) + + it('has a property `level`', function(){ + expect(log).to.have.a.property('level') + }) + + it('`level` defaults to ' + (isNode ? 'INFO' : 'WARN') + ' when running in ' + (isNode ? 'Node' : 'the browser'), function(){ + expect(log.level).to.equal(isNode ? log.INFO : log.WARN) + }) + + it('`level` can be assigned a different logging level', function(){ + testConsole.reset() + var oldLevel = log.level + log.level = log.ERROR + expect(log.level).to.equal(log.ERROR) + log.error('Message logged with log.error, after level was set to ERROR') + expect(testConsole.error.callCount).to.equal(1) + log.warn('Message logged with log.warn, after level was set to ERROR') + expect(testConsole.warn.callCount).to.equal(0) + log.info('Message logged with log.info, after level was set to ERROR') + expect(testConsole.info.callCount).to.equal(0) + log.log('Message logged with log.log, after level was set to ERROR') + expect(testConsole.log.callCount).to.equal(0) + log.debug('Message logged with log.debug, after level was set to ERROR') + expect(testConsole.debug.callCount).to.equal(0) + log.trace('Message logged with log.trace, after level was set to ERROR') + expect(testConsole.trace.callCount).to.equal(0) + testConsole.reset() + log.level = log.WARN + expect(log.level).to.equal(log.WARN) + log.error('Message logged with log.error, after level was set to WARN') + expect(testConsole.error.callCount).to.equal(1) + log.warn('Message logged with log.warn, after level was set to WARN') + expect(testConsole.warn.callCount).to.equal(1) + log.info('Message logged with log.info, after level was set to WARN') + expect(testConsole.info.callCount).to.equal(0) + log.log('Message logged with log.log, after level was set to WARN') + expect(testConsole.log.callCount).to.equal(0) + log.debug('Message logged with log.debug, after level was set to WARN') + expect(testConsole.debug.callCount).to.equal(0) + log.trace('Message logged with log.trace, after level was set to WARN') + expect(testConsole.trace.callCount).to.equal(0) + testConsole.reset() + log.level = log.INFO + expect(log.level).to.equal(log.INFO) + log.error('Message logged with log.error, after level was set to INFO') + expect(testConsole.error.callCount).to.equal(1) + log.warn('Message logged with log.warn, after level was set to INFO') + expect(testConsole.warn.callCount).to.equal(1) + log.info('Message logged with log.info, after level was set to INFO') + expect(testConsole.info.callCount).to.equal(1) + log.log('Message logged with log.log, after level was set to INFO') + expect(testConsole.log.callCount).to.equal(0) + log.debug('Message logged with log.debug, after level was set to INFO') + expect(testConsole.debug.callCount).to.equal(0) + log.trace('Message logged with log.trace, after level was set to INFO') + expect(testConsole.trace.callCount).to.equal(0) + testConsole.reset() + log.level = log.LOG + expect(log.level).to.equal(log.LOG) + log.error('Message logged with log.error, after level was set to LOG') + expect(testConsole.error.callCount).to.equal(1) + log.warn('Message logged with log.warn, after level was set to LOG') + expect(testConsole.warn.callCount).to.equal(1) + log.info('Message logged with log.info, after level was set to LOG') + expect(testConsole.info.callCount).to.equal(1) + log.log('Message logged with log.log, after level was set to LOG') + expect(testConsole.log.callCount).to.equal(1) + log.debug('Message logged with log.debug, after level was set to LOG') + expect(testConsole.debug.callCount).to.equal(0) + log.trace('Message logged with log.trace, after level was set to LOG') + expect(testConsole.trace.callCount).to.equal(0) + testConsole.reset() + log.level = log.DEBUG + expect(log.level).to.equal(log.DEBUG) + log.error('Message logged with log.error, after level was set to DEBUG') + expect(testConsole.error.callCount).to.equal(1) + log.warn('Message logged with log.warn, after level was set to DEBUG') + expect(testConsole.warn.callCount).to.equal(1) + log.info('Message logged with log.info, after level was set to DEBUG') + expect(testConsole.info.callCount).to.equal(1) + log.log('Message logged with log.log, after level was set to DEBUG') + expect(testConsole.log.callCount).to.equal(1) + log.debug('Message logged with log.debug, after level was set to DEBUG') + expect(testConsole.debug.callCount).to.equal(1) + log.trace('Message logged with log.trace, after level was set to DEBUG') + expect(testConsole.trace.callCount).to.equal(0) + testConsole.reset() + log.level = log.TRACE + expect(log.level).to.equal(log.TRACE) + log.error('Message logged with log.error, after level was set to TRACE') + expect(testConsole.error.callCount).to.equal(1) + log.warn('Message logged with log.warn, after level was set to TRACE') + expect(testConsole.warn.callCount).to.equal(1) + log.info('Message logged with log.info, after level was set to TRACE') + expect(testConsole.info.callCount).to.equal(1) + log.log('Message logged with log.log, after level was set to TRACE') + expect(testConsole.log.callCount).to.equal(1) + log.debug('Message logged with log.debug, after level was set to TRACE') + expect(testConsole.debug.callCount).to.equal(1) + log.trace('Message logged with log.trace, after level was set to TRACE') + expect(testConsole.trace.callCount).to.equal(1) + testConsole.reset() + log.level = log.NONE + expect(log.level).to.equal(log.NONE) + log.error('Message logged with log.error, after level was set to NONE') + expect(testConsole.error.callCount).to.equal(0) + log.warn('Message logged with log.warn, after level was set to NONE') + expect(testConsole.warn.callCount).to.equal(0) + log.info('Message logged with log.info, after level was set to NONE') + expect(testConsole.info.callCount).to.equal(0) + log.log('Message logged with log.log, after level was set to NONE') + expect(testConsole.log.callCount).to.equal(0) + log.debug('Message logged with log.debug, after level was set to NONE') + expect(testConsole.debug.callCount).to.equal(0) + log.trace('Message logged with log.trace, after level was set to NONE') + expect(testConsole.trace.callCount).to.equal(0) + testConsole.reset() + log.level = oldLevel + log.error('Message logged with log.error, after original level was restored') + expect(testConsole.error.callCount).to.equal(1) + log.warn('Message logged with log.warn, after original level was restored') + expect(testConsole.warn.callCount).to.equal(1) + log.info('Message logged with log.info, after original level was restored') + expect(testConsole.info.callCount).to.equal(isNode ? 1 : 0) // because of different default log levels + log.log('Message logged with log.log, after original level was restored') + expect(testConsole.log.callCount).to.equal(0) + log.debug('Message logged with log.debug, after original level was restored') + expect(testConsole.debug.callCount).to.equal(0) + log.trace('Message logged with log.trace, after original level was restored') + expect(testConsole.trace.callCount).to.equal(0) + testConsole.reset() + }) + + + it('has a method `enabled`', function(){ + expect(log).to.have.a.property('enabled') + expect(log.enabled).to.be.a('function') + }) + + it('has a method `enable`', function(){ + expect(log).to.have.a.property('enable') + expect(log.enable).to.be.a('function') + }) + + it('has a method `disable`', function(){ + expect(log).to.have.a.property('disable') + expect(log.disable).to.be.a('function') + }) +}) + +describe('var log = require(\'ulog\')(\'my-module-name\')', function(){ + it('yields a named log object', function(){ + expect(named).to.be.an('object') + expect(named).to.have.a.property('name') + expect(named.name).to.equal('my-module-name') + }) +}) + +describe('log (named)', function(){ + it('implements the Console API', function(){ + expect(named).to.have.a.property('error') + expect(named.error).to.be.a('function') + expect(named).to.have.a.property('warn') + expect(named.warn).to.be.a('function') + expect(named).to.have.a.property('info') + expect(named.info).to.be.a('function') + expect(named).to.have.a.property('log') + expect(named.log).to.be.a('function') + expect(named).to.have.a.property('trace') + expect(named.trace).to.be.a('function') + expect(named).to.have.a.property('dir') + expect(named.dir).to.be.a('function') + expect(named).to.have.a.property('time') + expect(named.time).to.be.a('function') + expect(named).to.have.a.property('timeEnd') + expect(named.timeEnd).to.be.a('function') + expect(named).to.have.a.property('assert') + expect(named.assert).to.be.a('function') + }) + + it('has an additional logging method named `debug`', function(){ + expect(named).to.have.a.property('debug') + expect(named.debug).to.be.a('function') + }) + + it('can log messages using methods `error`, `warn`, `info`, `log`, `debug` and `trace`', function(){ + testConsole.reset() + named.error('Message logged with log.error') + expect(testConsole.error.callCount).to.equal(1) + named.warn('Message logged with log.warn') + expect(testConsole.warn.callCount).to.equal(1) + named.info('Message logged with log.info') + expect(testConsole.info.callCount).to.equal(isNode ? 1 : 0) // defaults differ + named.log('Message logged with log.log') + expect(testConsole.log.callCount).to.equal(0) + named.debug('Message logged with log.debug') + expect(testConsole.debug.callCount).to.equal(0) + named.trace('Message logged with log.trace') + expect(testConsole.trace.callCount).to.equal(0) + testConsole.reset() + }) + + it('has constants for the log levels `ERROR`, `WARN`, `INFO`, `LOG`, `DEBUG` and `TRACE`', function(){ + expect(named).to.have.a.property('ERROR') + expect(named.ERROR).to.equal(1) + expect(named).to.have.a.property('WARN') + expect(named.WARN).to.equal(2) + expect(named).to.have.a.property('INFO') + expect(named.INFO).to.equal(3) + expect(named).to.have.a.property('LOG') + expect(named.LOG).to.equal(4) + expect(named).to.have.a.property('DEBUG') + expect(named.DEBUG).to.equal(5) + expect(named).to.have.a.property('TRACE') + expect(named.TRACE).to.equal(6) + }) + + it('has an additional constant for the special log level `NONE`, which suppresses all logging', function(){ + expect(named).to.have.a.property('NONE') + expect(named.NONE).to.equal(0) + }) + + it('has a property `level`', function(){ + expect(named).to.have.a.property('level') + }) + + it('`level` defaults to the global log level', function(){ + expect(named.level).to.equal(log.level) + }) + + it('`level` can be assigned a different logging level', function(){ + testConsole.reset() + named.level = log.ERROR + expect(named.level).to.equal(log.ERROR) + named.error('Message logged with named.error, after named.level was set to ERROR') + expect(testConsole.error.callCount).to.equal(1) + named.warn('Message logged with named.warn, after named.level was set to ERROR') + expect(testConsole.warn.callCount).to.equal(0) + named.info('Message logged with named.info, after named.level was set to ERROR') + expect(testConsole.info.callCount).to.equal(0) + named.log('Message logged with named.log, after named.level was set to ERROR') + expect(testConsole.log.callCount).to.equal(0) + named.debug('Message logged with named.debug, after named.level was set to ERROR') + expect(testConsole.debug.callCount).to.equal(0) + named.trace('Message logged with named.trace, after named.level was set to ERROR') + expect(testConsole.trace.callCount).to.equal(0) + log.error('Message logged with log.error, after named.level was set to ERROR') + expect(testConsole.error.callCount).to.equal(2) + log.warn('Message logged with log.warn, after named.level was set to ERROR') + expect(testConsole.warn.callCount).to.equal(1) + log.info('Message logged with log.info, after named.level was set to ERROR') + expect(testConsole.info.callCount).to.equal(isNode ? 1 : 0) + log.log('Message logged with log.log, after named.level was set to ERROR') + expect(testConsole.log.callCount).to.equal(0) + log.debug('Message logged with log.debug, after named.level was set to ERROR') + expect(testConsole.debug.callCount).to.equal(0) + log.trace('Message logged with log.trace, after named.level was set to ERROR') + expect(testConsole.trace.callCount).to.equal(0) + testConsole.reset() + named.level = log.WARN + expect(named.level).to.equal(log.WARN) + named.error('Message logged with named.error, after named.level was set to WARN') + expect(testConsole.error.callCount).to.equal(1) + named.warn('Message logged with named.warn, after named.level was set to WARN') + expect(testConsole.warn.callCount).to.equal(1) + named.info('Message logged with named.info, after named.level was set to WARN') + expect(testConsole.info.callCount).to.equal(0) + named.log('Message logged with named.log, after named.level was set to WARN') + expect(testConsole.log.callCount).to.equal(0) + named.debug('Message logged with named.debug, after named.level was set to WARN') + expect(testConsole.debug.callCount).to.equal(0) + named.trace('Message logged with named.trace, after named.level was set to WARN') + expect(testConsole.trace.callCount).to.equal(0) + log.error('Message logged with log.error, after named.level was set to WARN') + expect(testConsole.error.callCount).to.equal(2) + log.warn('Message logged with log.warn, after named.level was set to WARN') + expect(testConsole.warn.callCount).to.equal(2) + log.info('Message logged with log.info, after named.level was set to WARN') + expect(testConsole.info.callCount).to.equal(isNode ? 1 : 0) + log.log('Message logged with log.log, after named.level was set to WARN') + expect(testConsole.log.callCount).to.equal(0) + log.debug('Message logged with log.debug, after named.level was set to WARN') + expect(testConsole.debug.callCount).to.equal(0) + log.trace('Message logged with log.trace, after named.level was set to WARN') + expect(testConsole.trace.callCount).to.equal(0) + testConsole.reset() + named.level = log.INFO + expect(named.level).to.equal(log.INFO) + named.error('Message logged with named.error, after named.level was set to INFO') + expect(testConsole.error.callCount).to.equal(1) + named.warn('Message logged with named.warn, after named.level was set to INFO') + expect(testConsole.warn.callCount).to.equal(1) + named.info('Message logged with named.info, after named.level was set to INFO') + expect(testConsole.info.callCount).to.equal(1) + named.log('Message logged with named.log, after named.level was set to INFO') + expect(testConsole.log.callCount).to.equal(0) + named.debug('Message logged with named.debug, after named.level was set to INFO') + expect(testConsole.debug.callCount).to.equal(0) + named.trace('Message logged with named.trace, after named.level was set to INFO') + expect(testConsole.trace.callCount).to.equal(0) + log.error('Message logged with log.error, after named.level was set to INFO') + expect(testConsole.error.callCount).to.equal(2) + log.warn('Message logged with log.warn, after named.level was set to INFO') + expect(testConsole.warn.callCount).to.equal(2) + log.info('Message logged with log.info, after named.level was set to INFO') + expect(testConsole.info.callCount).to.equal(isNode ? 2 : 1) + log.log('Message logged with log.log, after named.level was set to INFO') + expect(testConsole.log.callCount).to.equal(0) + log.debug('Message logged with log.debug, after named.level was set to INFO') + expect(testConsole.debug.callCount).to.equal(0) + log.trace('Message logged with log.trace, after named.level was set to INFO') + expect(testConsole.trace.callCount).to.equal(0) + testConsole.reset() + var orgLevel = log.level + log.level = log.DEBUG + named.level = log.INFO + expect(named.level).to.equal(log.INFO) + named.error('Message logged with named.error, after named.level was set to LOG and log.level was set to DEBUG') + expect(testConsole.error.callCount).to.equal(1) + named.warn('Message logged with named.warn, after named.level was set to LOG and log.level was set to DEBUG') + expect(testConsole.warn.callCount).to.equal(1) + named.info('Message logged with named.info, after named.level was set to LOG and log.level was set to DEBUG') + expect(testConsole.info.callCount).to.equal(1) + named.log('Message logged with named.log, after named.level was set to LOG and log.level was set to DEBUG') + expect(testConsole.log.callCount).to.equal(0) + named.debug('Message logged with named.debug, after named.level was set to LOG and log.level was set to DEBUG') + expect(testConsole.debug.callCount).to.equal(0) + named.trace('Message logged with named.trace, after named.level was set to LOG and log.level was set to DEBUG') + expect(testConsole.trace.callCount).to.equal(0) + log.error('Message logged with log.error, after named.level was set to LOG and log.level was set to DEBUG') + expect(testConsole.error.callCount).to.equal(2) + log.warn('Message logged with log.warn, after named.level was set to LOG and log.level was set to DEBUG') + expect(testConsole.warn.callCount).to.equal(2) + log.info('Message logged with log.info, after named.level was set to LOG and log.level was set to DEBUG') + expect(testConsole.info.callCount).to.equal(2) + log.log('Message logged with log.log, after named.level was set to LOG and log.level was set to DEBUG') + expect(testConsole.log.callCount).to.equal(1) + log.debug('Message logged with log.debug, after named.level was set to LOG and log.level was set to DEBUG') + expect(testConsole.debug.callCount).to.equal(1) + log.trace('Message logged with log.trace, after named.level was set to LOG and log.level was set to DEBUG') + expect(testConsole.trace.callCount).to.equal(0) + testConsole.reset() + named.level = log.DEBUG + expect(named.level).to.equal(log.DEBUG) + named.error('Message logged with named.error, after named.level was set to DEBUG') + expect(testConsole.error.callCount).to.equal(1) + named.warn('Message logged with named.warn, after named.level was set to DEBUG') + expect(testConsole.warn.callCount).to.equal(1) + named.info('Message logged with named.info, after named.level was set to DEBUG') + expect(testConsole.info.callCount).to.equal(1) + named.log('Message logged with named.log, after named.level was set to DEBUG') + expect(testConsole.log.callCount).to.equal(1) + named.debug('Message logged with named.debug, after named.level was set to DEBUG') + expect(testConsole.debug.callCount).to.equal(1) + named.trace('Message logged with named.trace, after named.level was set to DEBUG') + expect(testConsole.trace.callCount).to.equal(0) + log.error('Message logged with log.error, after named.level was set to DEBUG') + expect(testConsole.error.callCount).to.equal(2) + log.warn('Message logged with log.warn, after named.level was set to DEBUG') + expect(testConsole.warn.callCount).to.equal(2) + log.info('Message logged with log.info, after named.level was set to DEBUG') + expect(testConsole.info.callCount).to.equal(2) + log.log('Message logged with log.log, after named.level was set to DEBUG') + expect(testConsole.log.callCount).to.equal(2) + log.debug('Message logged with log.debug, after named.level was set to DEBUG') + expect(testConsole.debug.callCount).to.equal(2) + log.trace('Message logged with log.trace, after named.level was set to DEBUG') + expect(testConsole.trace.callCount).to.equal(0) + testConsole.reset() + named.level = log.TRACE + expect(named.level).to.equal(log.TRACE) + named.error('Message logged with named.error, after named.level was set to TRACE') + expect(testConsole.error.callCount).to.equal(1) + named.warn('Message logged with named.warn, after named.level was set to TRACE') + expect(testConsole.warn.callCount).to.equal(1) + named.info('Message logged with named.info, after named.level was set to TRACE') + expect(testConsole.info.callCount).to.equal(1) + named.log('Message logged with named.log, after named.level was set to TRACE') + expect(testConsole.log.callCount).to.equal(1) + named.debug('Message logged with named.debug, after named.level was set to TRACE') + expect(testConsole.debug.callCount).to.equal(1) + named.trace('Message logged with named.trace, after named.level was set to TRACE') + expect(testConsole.trace.callCount).to.equal(1) + testConsole.reset() + log.error('Message logged with log.error, after named.level was set to TRACE') + expect(testConsole.error.callCount).to.equal(1) + log.warn('Message logged with log.warn, after named.level was set to TRACE') + expect(testConsole.warn.callCount).to.equal(1) + log.info('Message logged with log.info, after named.level was set to TRACE') + expect(testConsole.info.callCount).to.equal(1) + log.log('Message logged with log.log, after named.level was set to TRACE') + expect(testConsole.log.callCount).to.equal(1) + log.debug('Message logged with log.debug, after named.level was set to TRACE') + expect(testConsole.debug.callCount).to.equal(1) + log.trace('Message logged with log.trace, after named.level was set to TRACE') + expect(testConsole.trace.callCount).to.equal(0) + testConsole.reset() + named.level = log.NONE + expect(named.level).to.equal(log.NONE) + expect(log.level).to.equal(log.DEBUG) + named.error('Message logged with named.error, after named.level was set to NONE') + expect(testConsole.error.callCount).to.equal(0) + named.warn('Message logged with named.warn, after named.level was set to NONE') + expect(testConsole.warn.callCount).to.equal(0) + named.info('Message logged with named.info, after named.level was set to NONE') + expect(testConsole.info.callCount).to.equal(0) + named.log('Message logged with named.log, after named.level was set to NONE') + expect(testConsole.log.callCount).to.equal(0) + named.debug('Message logged with named.debug, after named.level was set to NONE') + expect(testConsole.debug.callCount).to.equal(0) + named.trace('Message logged with named.trace, after named.level was set to NONE') + expect(testConsole.trace.callCount).to.equal(0) + log.error('Message logged with log.error, after named.level was set to NONE') + expect(testConsole.error.callCount).to.equal(1) + log.warn('Message logged with log.warn, after named.level was set to NONE') + expect(testConsole.warn.callCount).to.equal(1) + log.info('Message logged with log.info, after named.level was set to NONE') + expect(testConsole.info.callCount).to.equal(1) + log.log('Message logged with log.log, after named.level was set to NONE') + expect(testConsole.log.callCount).to.equal(1) + log.debug('Message logged with log.debug, after named.level was set to NONE') + expect(testConsole.debug.callCount).to.equal(1) + log.trace('Message logged with log.trace, after named.level was set to NONE') + expect(testConsole.trace.callCount).to.equal(0) + testConsole.reset() + named.level = undefined + expect(named.level).to.equal(log.DEBUG) // inherit parent level + named.error('Message logged with named.error, after named.level was reset') + expect(testConsole.error.callCount).to.equal(1) + named.warn('Message logged with named.warn, after named.level was reset') + expect(testConsole.warn.callCount).to.equal(1) + named.info('Message logged with named.info, after named.level was reset') + expect(testConsole.info.callCount).to.equal(1) + named.log('Message logged with named.log, after named.level was set reset') + expect(testConsole.log.callCount).to.equal(1) + named.debug('Message logged with named.debug, after named.level was reset') + expect(testConsole.debug.callCount).to.equal(1) + named.trace('Message logged with named.trace, after named.level was reset') + expect(testConsole.trace.callCount).to.equal(0) + log.error('Message logged with log.error, after named.level was reset') + expect(testConsole.error.callCount).to.equal(2) + log.warn('Message logged with log.warn, after named.level was reset') + expect(testConsole.warn.callCount).to.equal(2) + log.info('Message logged with log.info, after named.level was reset') + expect(testConsole.info.callCount).to.equal(2) + log.log('Message logged with log.log, after named.level was reset') + expect(testConsole.log.callCount).to.equal(2) + log.debug('Message logged with log.debug, after named.level was reset') + expect(testConsole.debug.callCount).to.equal(2) + log.trace('Message logged with log.trace, after named.level was reset') + expect(testConsole.trace.callCount).to.equal(0) + log.level = orgLevel + testConsole.reset() + }) + + it('can be `enabled` by its name', function(){ + testConsole.reset() + expect(named.level).to.equal(log.level) + expect(log.level).to.equal(isNode ? log.INFO : log.WARN) + expect(log.enabled('my-module-name')).to.not.equal(true) + log.log('Message logged with log.log before named module is enabled') + expect(testConsole.log.callCount).to.equal(0) + named.log('Message logged with named.log before named module is enabled') + expect(testConsole.log.callCount).to.equal(0) + log.enable('my-module-name') + log.log('Message logged with log.log after named module is enabled') + expect(testConsole.log.callCount).to.equal(0) + named.log('Message logged with named.log after named module is enabled') + expect(testConsole.log.callCount).to.equal(1) + testConsole.reset() + }) +}) + diff --git a/ulog.umd.js b/ulog.umd.js new file mode 100644 index 0000000..a66d035 --- /dev/null +++ b/ulog.umd.js @@ -0,0 +1,165 @@ +(function webpackUniversalModuleDefinition(root, factory) { + if(typeof exports === 'object' && typeof module === 'object') + module.exports = factory(); + else if(typeof define === 'function' && define.amd) + define([], factory); + else { + var a = factory(); + for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i]; + } +})(this, function() { +return /******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; +/******/ +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.loaded = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ function(module, exports, __webpack_require__) { + + var log = __webpack_require__(1), + qs = location.search.substring(1), + args = qs && qs.split('&'), + lvl, dbg, i, m + + for (i=0; m=args && args[i] && args[i].split('='); i++) { + (m[0] == 'log') && (lvl = m[1]) + (m[0] == 'debug') && (dbg = m[1]) + } + + log.con = function(){return window.console && console} + dbg && log.enable(dbg) + module.exports = log() + log.level = lvl || log.WARN + + +/***/ }, +/* 1 */ +/***/ function(module, exports) { + + function log(name){ + return name + ? (mods[name] ? mods[name] : (mods[name] = enhance({name:name}, log))) + : (log.debug ? log : enhance(log)) + } + + log.ulog = {version:'0.1.0'} + + log.enable = function(str) { + var i, split = (str || '').split(/[\s,]+/); + for (i=0; i= 0 && lvl <= 6) {level = lvl} + } + patch(o, parent) + if (!parent) {for (mod in mods) {patch(mods[mod], o)}} + } + }) + patch(o, parent) + o.dir = bnd('dir') || nop + o.time = bnd('time') || nop + o.timeEnd = bnd('timeEnd') || nop + o.assert = function(){ + var a=[].concat.apply([], arguments), ok=a.shift() + if (!ok) {o.error.apply(o, a)} + } + return o + } + + function patch(o, parent) { + var lvl = Math.max(o.name && log.enabled(o.name) && o.DEBUG || o.level, o.level) + for (var i=0,name; name=names[i]; i++) { + o[name] = lvl <= i + ? nop + : ( + bnd(name) || + (typeof print == 'function' && print) || + function(){ + if (log.con()) { + patch(o) + o[name].apply(o, arguments) + } + } + ) + } + } + + function bnd(n,c){return (c = log.con()) && (c[n]||c.log).bind(c)} + function nop(){} + + +/***/ } +/******/ ]) +}); +; +//# sourceMappingURL=ulog.umd.js.map \ No newline at end of file diff --git a/ulog.umd.js.map b/ulog.umd.js.map new file mode 100644 index 0000000..67c407e --- /dev/null +++ b/ulog.umd.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap 423020b2e2347c521423","webpack:///./browser.js","webpack:///./ulog.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;ACVA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;ACtCA;AACA;AACA;AACA;;AAEA,UAAS,yCAAyC;AAClD;AACA;AACA;;AAEA,sBAAqB;AACrB;AACA;AACA;;;;;;;ACbA;AACA;AACA,uDAAsD,UAAU;AAChE;AACA;;AAEA,aAAY;;AAEZ;AACA;AACA,WAAU,gBAAgB;AAC1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,WAAU,mBAAmB;AAC7B;AACA,WAAU,kBAAkB;AAC5B,+BAA8B;AAC9B;;AAEA;;AAEA;;AAEA,YAAW,iDAAiD;AAC5D,4CAA2C,uBAAuB;AAClE,YAAW;;AAEX;AACA;AACA,wBAAuB;AACvB;AACA,mBAAkB,4DAA4D;AAC9E;AACA,sCAAqC;AACrC;AACA;AACA,gCAA+B;AAC/B;AACA;AACA,kBAAiB,mBAAmB;AACpC;AACA,GAAE;AACF;AACA;AACA;AACA;AACA;AACA;AACA,aAAY;AACZ;AACA;AACA;;AAEA;AACA;AACA,oBAAmB,eAAe;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,mBAAkB;AAClB","file":"ulog.umd.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse {\n\t\tvar a = factory();\n\t\tfor(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n\t}\n})(this, function() {\nreturn \n\n\n/** WEBPACK FOOTER **\n ** webpack/universalModuleDefinition\n **/"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap 423020b2e2347c521423\n **/","var log = require('./ulog'),\r\n\t\tqs = location.search.substring(1),\r\n\t\targs = qs && qs.split('&'),\r\n\t\tlvl, dbg, i, m\r\n\r\nfor (i=0; m=args && args[i] && args[i].split('='); i++) {\r\n\t(m[0] == 'log') && (lvl = m[1])\r\n\t(m[0] == 'debug') && (dbg = m[1])\r\n}\r\n\r\nlog.con = function(){return window.console && console}\r\ndbg && log.enable(dbg)\r\nmodule.exports = log()\r\nlog.level = lvl || log.WARN\r\n\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./browser.js\n ** module id = 0\n ** module chunks = 0\n **/","function log(name){\r\n\treturn name\r\n\t\t? (mods[name] ? mods[name] : (mods[name] = enhance({name:name}, log)))\r\n\t\t: (log.debug ? log : enhance(log))\r\n}\r\n\r\nlog.ulog = {version:'0.1.0'}\r\n\r\nlog.enable = function(str) {\r\n\tvar i, split = (str || '').split(/[\\s,]+/);\r\n\tfor (i=0; i= 0 && lvl <= 6) {level = lvl}\r\n\t\t\t}\r\n\t\t\tpatch(o, parent)\r\n\t\t\tif (!parent) {for (mod in mods) {patch(mods[mod], o)}}\r\n\t\t}\r\n\t})\r\n\tpatch(o, parent)\r\n\to.dir = bnd('dir') || nop\r\n\to.time = bnd('time') || nop\r\n\to.timeEnd = bnd('timeEnd') || nop\r\n\to.assert = function(){\r\n\t\tvar a=[].concat.apply([], arguments), ok=a.shift()\r\n\t\tif (!ok) {o.error.apply(o, a)}\r\n\t}\r\n\treturn o\r\n}\r\n\r\nfunction patch(o, parent) {\r\n\tvar lvl = Math.max(o.name && log.enabled(o.name) && o.DEBUG || o.level, o.level)\r\n\tfor (var i=0,name; name=names[i]; i++) {\r\n\t\to[name] = lvl <= i\r\n\t\t\t? nop\r\n\t\t\t: (\r\n\t\t\t\tbnd(name) ||\r\n\t\t\t\t(typeof print == 'function' && print) ||\r\n\t\t\t\tfunction(){\r\n\t\t\t\t\tif (log.con()) {\r\n\t\t\t\t\t\tpatch(o)\r\n\t\t\t\t\t\to[name].apply(o, arguments)\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t)\r\n\t}\r\n}\r\n\r\nfunction bnd(n,c){return (c = log.con()) && (c[n]||c.log).bind(c)}\r\nfunction nop(){}\r\n\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./ulog.js\n ** module id = 1\n ** module chunks = 0\n **/"],"sourceRoot":""} \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..fc3f983 --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,20 @@ +var path = require('path'); +var webpack = require('webpack'); + +module.exports = { + // The base directory (absolute path!) for resolving the entry option. + // If output.pathinfo is set, the included pathinfo is shortened to this directory. + context: path.resolve('.'), + + module: { + noParse: /\.min\.js/, + }, + + devtool: 'inline-source-map', + + devServer: { + stats: { + chunks: false, + } + } +};