diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 25410ad..b3956e4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,7 +4,7 @@ on: pull_request: {} push: branches: - - master + - main # Allow manual runs if needed. workflow_dispatch: {} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fc461ee..d177033 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,7 +5,7 @@ If you'd like to file a bug or a feature request for loglevel, the best option i If you're filing a feature request, please remember: -* Feature requests significantly expanding the scope of loglevel outside the description in [the readme](https://github.com/pimterry/loglevel/blob/master/README.md) will probably be rejected. +* Feature requests significantly expanding the scope of loglevel outside the description in [the readme](https://github.com/pimterry/loglevel/blob/main/README.md) will probably be rejected. * Features that can't be meaningfully implemented in a cross-environment compatible manner won't be implemented. * Please check the previously opened issues to see if somebody else has suggested it first. * Consider submitting a pull request to add the feature instead, if you're confident it fits within the above. @@ -60,12 +60,12 @@ How to make your change and submit it 1. Ensure you have Node.js v14 or later (some tests can run on earlier versions, but the full suite requires this version). 2. Fork loglevel. 3. Clone your fork locally. -4. Create a branch from `master` for your change. +4. Create a branch from `main` for your change. 5. Write some tests in `test/` for your change, as relevant. 6. Make your code changes in `lib/loglevel.js`. 7. Check your code all passes (run `npm test`). If you have issues and need to debug the tests, see the details on ["running tests"](#running-tests) below. 8. Commit your changes. -9. Open a pull request back to `master` in loglevel. +9. Open a pull request back to `main` in loglevel. Running Tests ------------- diff --git a/README.md b/README.md index f6ba988..f641f46 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ [npm-image]: https://img.shields.io/npm/v/loglevel.svg?style=flat [npm-url]: https://npmjs.org/package/loglevel +⚠️ **You are looking at an in-development branch for Loglevel 2.0!** There will be a lot of breaking changes here. For release versions of Loglevel, check out the [`main` branch](https://github.com/pimterry/loglevel/tree/main). + > _Don't debug with logs alone - check out [HTTP Toolkit](https://httptoolkit.tech/javascript): beautiful, powerful & open-source tools for building, testing & debugging HTTP(S)_ Minimal lightweight simple logging for JavaScript (browsers, node.js or elsewhere). loglevel extends `console.log()` & friends with level-based logging and filtering, with none of console's downsides. @@ -45,8 +47,8 @@ Alternatively if you just want to grab the file yourself, you can download eithe Finally, if you want to tweak loglevel to your own needs or you immediately need the cutting-edge version, clone this repo and see [Developing & Contributing](#developing--contributing) below for build instructions. -[min]: https://raw.github.com/pimterry/loglevel/master/dist/loglevel.min.js -[max]: https://raw.github.com/pimterry/loglevel/master/dist/loglevel.js +[min]: https://raw.github.com/pimterry/loglevel/main/dist/loglevel.min.js +[max]: https://raw.github.com/pimterry/loglevel/main/dist/loglevel.js [cdn]: https://unpkg.com/loglevel/dist/loglevel.min.js ## Setting it up @@ -396,6 +398,11 @@ v1.9.1 - Fix a bug introduced in 1.9.0 that broke `setLevel()` in some ESM-focus v1.9.2 - Remove unnecessarily extra test & CI files from deployed package +v2.0.0 **(In development)** +- Removed support for Internet Explorer v10 and older. +- Calling `debug(msg)` shows up as an actual “debug” level message in browser consoles (in v1, it showed up as “log” or “info” depending on your browser). +- The `log()` method is now equivalent to `info()` instead of `debug()`. + ## `loglevel` for enterprise Available as part of the Tidelift Subscription. diff --git a/dist/loglevel.js b/dist/loglevel.js index a056e99..893e4cb 100644 --- a/dist/loglevel.js +++ b/dist/loglevel.js @@ -14,9 +14,6 @@ // Slightly dubious tricks to cut down minimized file size var noop = function() {}; var undefinedType = "undefined"; - var isIE = (typeof window !== undefinedType) && (typeof window.navigator !== undefinedType) && ( - /Trident\/|MSIE /.test(window.navigator.userAgent) - ); var logMethods = [ "trace", @@ -29,54 +26,17 @@ var _loggersByName = {}; var defaultLogger = null; - // Cross-browser bind equivalent that works at least back to IE6 - function bindMethod(obj, methodName) { - var method = obj[methodName]; - if (typeof method.bind === 'function') { - return method.bind(obj); - } else { - try { - return Function.prototype.bind.call(method, obj); - } catch (e) { - // Missing bind shim or IE8 + Modernizr, fallback to wrapping - return function() { - return Function.prototype.apply.apply(method, [obj, arguments]); - }; - } - } - } - - // Trace() doesn't print the message in IE, so for that case we need to wrap it - function traceForIE() { - if (console.log) { - if (console.log.apply) { - console.log.apply(console, arguments); - } else { - // In old IE, native console methods themselves don't have apply(). - Function.prototype.apply.apply(console.log, [console, arguments]); - } - } - if (console.trace) console.trace(); - } - // Build the best logging method possible for this env // Wherever possible we want to bind, not wrap, to preserve stack traces - function realMethod(methodName) { - if (methodName === 'debug') { - methodName = 'log'; + function defaultMethodFactory(methodName, _level, _loggerName) { + if (typeof console !== undefinedType) { + var consoleMethod = console[methodName] || console.log; + if (typeof consoleMethod === "function") { + return consoleMethod.bind(console); + } } - if (typeof console === undefinedType) { - return false; // No method possible, for now - fixed later by enableLoggingWhenConsoleArrives - } else if (methodName === 'trace' && isIE) { - return traceForIE; - } else if (console[methodName] !== undefined) { - return bindMethod(console, methodName); - } else if (console.log !== undefined) { - return bindMethod(console, 'log'); - } else { - return noop; - } + return noop; } // These private functions always need `this` to be set properly @@ -93,8 +53,8 @@ this.methodFactory(methodName, level, this.name); } - // Define log.log as an alias for log.debug - this.log = this.debug; + // Make `log.log` an alias to ensure compatibility with `console.*`. + this.log = this.info; // Return any important warnings. if (typeof console === undefinedType && level < this.levels.SILENT) { @@ -102,25 +62,6 @@ } } - // In old IE versions, the console isn't present until you first open it. - // We build realMethod() replacements here that regenerate logging methods - function enableLoggingWhenConsoleArrives(methodName) { - return function () { - if (typeof console !== undefinedType) { - replaceLoggingMethods.call(this); - this[methodName].apply(this, arguments); - } - }; - } - - // By default, we use closely bound real methods wherever possible, and - // otherwise we wait for a console to appear, and then try again. - function defaultMethodFactory(methodName, _level, _loggerName) { - /*jshint validthis:true */ - return realMethod(methodName) || - enableLoggingWhenConsoleArrives.apply(this, arguments); - } - function Logger(name, factory) { // Private instance variables. var self = this; diff --git a/dist/loglevel.min.js b/dist/loglevel.min.js index ed747a2..5d1b396 100644 --- a/dist/loglevel.min.js +++ b/dist/loglevel.min.js @@ -1,3 +1,3 @@ /*! loglevel - v1.9.2 - https://github.com/pimterry/loglevel - (c) 2024 Tim Perry - licensed MIT */ -!function(e,o){"use strict";"function"==typeof define&&define.amd?define(o):"object"==typeof module&&module.exports?module.exports=o():e.log=o()}(this,function(){"use strict";var l=function(){},f="undefined",i=typeof window!==f&&typeof window.navigator!==f&&/Trident\/|MSIE /.test(window.navigator.userAgent),s=["trace","debug","info","warn","error"],p={},d=null;function r(o,e){var n=o[e];if("function"==typeof n.bind)return n.bind(o);try{return Function.prototype.bind.call(n,o)}catch(e){return function(){return Function.prototype.apply.apply(n,[o,arguments])}}}function c(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function v(){for(var e=this.getLevel(),o=0;o