source: trip-planner-front/node_modules/loglevel/README.md@ 6fe77af

Last change on this file since 6fe77af was e29cc2e, checked in by Ema <ema_spirova@…>, 3 years ago

primeNG components

  • Property mode set to 100644
File size: 22.4 KB
Line 
1
2# loglevel [![NPM version][npm-image]][npm-url] [![NPM downloads](https://img.shields.io/npm/dw/loglevel.svg)](https://www.npmjs.com/package/loglevel) [![Build status](https://travis-ci.org/pimterry/loglevel.png)](https://travis-ci.org/pimterry/loglevel) [![Coveralls percentage](https://img.shields.io/coveralls/pimterry/loglevel.svg)](https://coveralls.io/r/pimterry/loglevel?branch=master)
3
4[npm-image]: https://img.shields.io/npm/v/loglevel.svg?style=flat
5[npm-url]: https://npmjs.org/package/loglevel
6
7> _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)_
8
9Minimal lightweight simple logging for JavaScript. loglevel replaces console.log() and friends with level-based logging and filtering, with none of console's downsides.
10
11This is a barebones reliable everyday logging library. It does not do fancy things, it does not let you reconfigure appenders or add complex log filtering rules or boil tea (more's the pity), but it does have the all core functionality that you actually use:
12
13## Features
14
15### Simple
16
17* Log things at a given level (trace/debug/info/warn/error) to the console object (as seen in all modern browsers & node.js)
18* Filter logging by level (all the above or 'silent'), so you can disable all but error logging in production, and then run log.setLevel("trace") in your console to turn it all back on for a furious debugging session
19* Single file, no dependencies, weighs in at 1.1KB minified and gzipped
20
21### Effective
22
23* Log methods gracefully fall back to simpler console logging methods if more specific ones aren't available: so calls to log.debug() go to console.debug() if possible, or console.log() if not
24* Logging calls still succeed even if there's no console object at all, so your site doesn't break when people visit with old browsers that don't support the console object (here's looking at you IE) and similar
25* This then comes together giving a consistent reliable API that works in every JavaScript environment with a console available, and never breaks anything anywhere else
26
27### Convenient
28
29* Log output keeps line numbers: most JS logging frameworks call console.log methods through wrapper functions, clobbering your stacktrace and making the extra info many browsers provide useless. We'll have none of that thanks.
30* It works with all the standard JavaScript loading systems out of the box (CommonJS, AMD, or just as a global)
31* Logging is filtered to "warn" level by default, to keep your live site clean in normal usage (or you can trivially re-enable everything with an initial log.enableAll() call)
32* Magically handles situations where console logging is not initially available (IE8/9), and automatically enables logging as soon as it does become available (when developer console is opened)
33* TypeScript type definitions included, so no need for extra `@types` packages
34* Extensible, to add other log redirection, filtering, or formatting functionality, while keeping all the above (except you will clobber your stacktrace, see Plugins below)
35
36## Downloading loglevel
37
38If you're using NPM, you can just run `npm install loglevel`.
39
40Alternatively, loglevel is also available via [Bower](https://github.com/bower/bower) (`bower install loglevel`), as a [Webjar](http://www.webjars.org/), or an [Atmosphere package](https://atmospherejs.com/spacejamio/loglevel) (for Meteor)
41
42Alternatively if you just want to grab the file yourself, you can download either the current stable [production version][min] or the [development version][max] directly, or reference it remotely on unpkg at [`https://unpkg.com/loglevel/dist/loglevel.min.js`][cdn] (this will redirect to a latest version, use the resulting redirected URL if you want to pin that version).
43
44Finally, 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.
45
46[min]: https://raw.github.com/pimterry/loglevel/master/dist/loglevel.min.js
47[max]: https://raw.github.com/pimterry/loglevel/master/dist/loglevel.js
48[cdn]: https://unpkg.com/loglevel/dist/loglevel.min.js
49
50## Setting it up
51
52loglevel supports AMD (e.g. RequireJS), CommonJS (e.g. Node.js) and direct usage (e.g. loading globally with a &lt;script&gt; tag) loading methods. You should be able to do nearly anything, and then skip to the next section anyway and have it work. Just in case though, here's some specific examples that definitely do the right thing:
53
54### CommonsJS (e.g. Node)
55
56```javascript
57var log = require('loglevel');
58log.warn("unreasonably simple");
59```
60
61### AMD (e.g. RequireJS)
62
63```javascript
64define(['loglevel'], function(log) {
65 log.warn("dangerously convenient");
66});
67```
68
69### Directly in your web page:
70
71```html
72<script src="loglevel.min.js"></script>
73<script>
74log.warn("too easy");
75</script>
76```
77
78### As an ES6 module:
79
80loglevel is written as a UMD module, with a single object exported. Unfortunately ES6 module loaders & transpilers don't all handle this the same way. Some will treat the object as the default export, while others use it as the root exported object. In addition, loglevel includes `default` property on the root object, designed to help handle this differences. Nonetheless, there's two possible syntaxes that might work for you:
81
82For most tools, using the default import is the most convenient and flexible option:
83
84```javascript
85import log from 'loglevel';
86log.warn("module-tastic");
87```
88
89For some tools though, it might better to wildcard import the whole object:
90
91```javascript
92import * as log from 'loglevel';
93log.warn("module-tastic");
94```
95
96There's no major difference, unless you're using TypeScript & building a loglevel plugin (in that case, see https://github.com/pimterry/loglevel/issues/149). In general though, just use whichever suits your environment, and everything should work out fine.
97
98### With noConflict():
99
100If you're using another JavaScript library that exposes a 'log' global, you can run into conflicts with loglevel. Similarly to jQuery, you can solve this by putting loglevel into no-conflict mode immediately after it is loaded onto the page. This resets to 'log' global to its value before loglevel was loaded (typically `undefined`), and returns the loglevel object, which you can then bind to another name yourself.
101
102For example:
103
104```html
105<script src="loglevel.min.js"></script>
106<script>
107var logging = log.noConflict();
108
109logging.warn("still pretty easy");
110</script>
111```
112
113### TypeScript:
114
115loglevel includes its own type definitions, assuming you're using a modern module environment (e.g. Node.JS, webpack, etc), you should be able to use the ES6 syntax above, and everything will work immediately. If not, file a bug!
116
117If you really want to use LogLevel as a global however, but from TypeScript, you'll need to declare it as such first. To do that:
118
119* Create a `loglevel.d.ts` file
120* Ensure that file is included in your build (e.g. add it to `include` in your tsconfig, pass it on the command line, or use `///<reference path="./loglevel.d.ts" />`)
121* In that file, add:
122 ```typescript
123 import * as log from 'loglevel';
124 export as namespace log;
125 export = log;
126 ```
127
128## Documentation
129
130The loglevel API is extremely minimal. All methods are available on the root loglevel object, which it's suggested you name 'log' (this is the default if you import it in globally, and is what's set up in the above examples). The API consists of:
131
132* 5 actual logging methods, ordered and available as:
133 * `log.trace(msg)`
134 * `log.debug(msg)`
135 * `log.info(msg)`
136 * `log.warn(msg)`
137 * `log.error(msg)`
138
139 `log.log(msg)` is also available, as an alias for `log.debug(msg)`, to improve compatibility with `console`, and make migration easier.
140
141 Exact output formatting of these will depend on the console available in the current context of your application. For example, many environments will include a full stack trace with all trace() calls, and icons or similar to highlight other calls.
142
143 These methods should never fail in any environment, even if no console object is currently available, and should always fall back to an available log method even if the specific method called (e.g. warn) isn't available.
144
145 Be aware that all this means that these method won't necessarily always produce exactly the output you expect in every environment; loglevel only guarantees that these methods will never explode on you, and that it will call the most relevant method it can find, with your argument. For example, `log.trace(msg)` in Firefox before version 64 prints the stacktrace by itself, and doesn't include your message (see [#84](https://github.com/pimterry/loglevel/issues/84)).
146
147* A `log.setLevel(level, [persist])` method.
148
149 This disables all logging below the given level, so that after a log.setLevel("warn") call log.warn("something") or log.error("something") will output messages, but log.info("something") will not.
150
151 This can take either a log level name or 'silent' (which disables everything) in one of a few forms:
152 * As a log level from the internal levels list, e.g. log.levels.SILENT ← _for type safety_
153 * As a string, like 'error' (case-insensitive) ← _for a reasonable practical balance_
154 * As a numeric index from 0 (trace) to 5 (silent) ← _deliciously terse, and more easily programmable (...although, why?)_
155
156 Where possible the log level will be persisted. LocalStorage will be used if available, falling back to cookies if not. If neither is available in the current environment (i.e. in Node), or if you pass `false` as the optional 'persist' second argument, persistence will be skipped.
157
158 If log.setLevel() is called when a console object is not available (in IE 8 or 9 before the developer tools have been opened, for example) logging will remain silent until the console becomes available, and then begin logging at the requested level.
159
160* A `log.setDefaultLevel(level)` method.
161
162 This sets the current log level only if one has not been persisted and can’t be loaded. This is useful when initializing scripts; if a developer or user has previously called `setLevel()`, this won’t alter their settings. For example, your application might set the log level to `error` in a production environment, but when debugging an issue, you might call `setLevel("trace")` on the console to see all the logs. If that `error` setting was set using `setDefaultLevel()`, it will still stay as `trace` on subsequent page loads and refreshes instead of resetting to `error`.
163
164 The `level` argument takes is the same values that you might pass to `setLevel()`. Levels set using `setDefaultLevel()` never persist to subsequent page loads.
165
166* A `log.resetLevel()` method.
167
168 This resets the current log level to the default level (or `warn` if no explicit default was set) and clears the persisted level if one was previously persisted.
169
170* `log.enableAll()` and `log.disableAll()` methods.
171
172 These enable or disable all log messages, and are equivalent to log.setLevel("trace") and log.setLevel("silent") respectively.
173
174* A `log.getLevel()` method.
175
176 Returns the current logging level, as a number from 0 (trace) to 5 (silent)
177
178 It's very unlikely you'll need to use this for normal application logging; it's provided partly to help plugin development, and partly to let you optimize logging code as below, where debug data is only generated if the level is set such that it'll actually be logged. This probably doesn't affect you, unless you've run profiling on your code and you have hard numbers telling you that your log data generation is a real performance problem.
179
180 ```javascript
181 if (log.getLevel() <= log.levels.DEBUG) {
182 var logData = runExpensiveDataGeneration();
183 log.debug(logData);
184 }
185 ```
186
187 This notably isn't the right solution to avoid the cost of string concatenation in your logging. Firstly, it's very unlikely that string concatenation in your logging is really an important performance problem. Even if you do genuinely have hard metrics showing that it is though, the better solution that wrapping your log statements in this is to use multiple arguments, as below. The underlying console API will automatically concatenate these for you if logging is enabled, and if it isn't then all log methods are no-ops, and no concatenation will be done at all.
188
189 ```javascript
190 // Prints 'My concatenated log message'
191 log.debug("My ", "concatenated ", "log message");
192 ```
193
194* A `log.getLogger(loggerName)` method.
195
196 This gets you a new logger object that works exactly like the root `log` object, but can have its level and logging methods set independently. All loggers must have a name (which is a non-empty string, or a [Symbol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol)). Calling `getLogger()` multiple times with the same name will return an identical logger object.
197
198 In large applications, it can be incredibly useful to turn logging on and off for particular modules as you are working with them. Using the `getLogger()` method lets you create a separate logger for each part of your application with its own logging level.
199
200 Likewise, for small, independent modules, using a named logger instead of the default root logger allows developers using your module to selectively turn on deep, trace-level logging when trying to debug problems, while logging only errors or silencing logging altogether under normal circumstances.
201
202 Example usage *(using CommonJS modules, but you could do the same with any module system):*
203
204 ```javascript
205 // In module-one.js:
206 var log = require("loglevel").getLogger("module-one");
207 function doSomethingAmazing() {
208 log.debug("Amazing message from module one.");
209 }
210
211 // In module-two.js:
212 var log = require("loglevel").getLogger("module-two");
213 function doSomethingSpecial() {
214 log.debug("Special message from module two.");
215 }
216
217 // In your main application module:
218 var log = require("loglevel");
219 var moduleOne = require("module-one");
220 var moduleTwo = require("module-two");
221 log.getLogger("module-two").setLevel("TRACE");
222
223 moduleOne.doSomethingAmazing();
224 moduleTwo.doSomethingSpecial();
225 // logs "Special message from module two."
226 // (but nothing from module one.)
227 ```
228
229 Loggers returned by `getLogger()` support all the same properties and methods as the default root logger, excepting `noConflict()` and the `getLogger()` method itself.
230
231 Like the root logger, other loggers can have their logging level saved. If a logger’s level has not been saved, it will inherit the root logger’s level when it is first created. If the root logger’s level changes later, the new level will not affect other loggers that have already been created. Loggers with Symbol names (rather than string names) will be always considered as unique instances, and will never have their logging level saved or restored.
232
233 Likewise, loggers will inherit the root logger’s `methodFactory`. After creation, each logger can have its `methodFactory` independently set. See the *plugins* section below for more about `methodFactory`.
234
235* A `log.getLoggers()` method.
236
237 This will return you the dictionary of all loggers created with `getLogger`, keyed off of their names.
238
239## Plugins
240
241### Existing plugins:
242
243[loglevel-plugin-prefix](https://github.com/kutuluk/loglevel-plugin-prefix) - plugin for loglevel message prefixing.
244
245[loglevel-plugin-remote](https://github.com/kutuluk/loglevel-plugin-remote) - plugin for sending loglevel messages to a remote log server.
246
247ServerSend - https://github.com/artemyarulin/loglevel-serverSend - Forward your log messages to a remote server.
248
249DEBUG - https://github.com/vectrlabs/loglevel-debug - Control logging from a DEBUG environmental variable (similar to the classic [Debug](https://github.com/visionmedia/debug) module)
250
251### Writing plugins:
252
253Loglevel provides a simple reliable minimal base for console logging that works everywhere. This means it doesn't include lots of fancy functionality that might be useful in some cases, such as log formatting and redirection (e.g. also sending log messages to a server over AJAX)
254
255Including that would increase the size and complexity of the library, but more importantly would remove stacktrace information. Currently log methods are either disabled, or enabled with directly bound versions of the console.log methods (where possible). This means your browser shows the log message as coming from your code at the call to `log.info("message!")` not from within loglevel, since it really calls the bound console method directly, without indirection. The indirection required to dynamically format, further filter, or redirect log messages would stop this.
256
257There's clearly enough enthusiasm for this even at that cost though that loglevel now includes a plugin API. To use it, redefine `log.methodFactory(methodName, logLevel, loggerName)` with a function of your own. This will be called for each enabled method each time the level is set (including initially), and should return a function to be used for the given log method `methodName`, at the given *configured* (not actual) level `logLevel`, for a logger with the given name `loggerName`. If you'd like to retain all the reliability and features of loglevel, it's recommended that this wraps the initially provided value of `log.methodFactory`.
258
259For example, a plugin to prefix all log messages with "Newsflash: " would look like:
260
261```javascript
262var originalFactory = log.methodFactory;
263log.methodFactory = function (methodName, logLevel, loggerName) {
264 var rawMethod = originalFactory(methodName, logLevel, loggerName);
265
266 return function (message) {
267 rawMethod("Newsflash: " + message);
268 };
269};
270log.setLevel(log.getLevel()); // Be sure to call setLevel method in order to apply plugin
271```
272
273*(The above supports only a single string `log.warn("...")` argument for clarity, but it's easy to extend to a [fuller variadic version](http://jsbin.com/xehoye/edit?html,console).)*
274
275If you develop and release a plugin, please get in contact! I'd be happy to reference it here for future users. Some consistency is helpful; naming your plugin 'loglevel-PLUGINNAME' (e.g. loglevel-newsflash) is preferred, as is giving it the 'loglevel-plugin' keyword in your package.json
276
277## Developing & Contributing
278In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality.
279
280Builds can be run with npm: run `npm run dist` to build a distributable version of the project (in /dist), or `npm test` to just run the tests and linting. During development you can run `npm run watch` and it will monitor source files, and rerun the tests and linting as appropriate when they're changed.
281
282_Also, please don't manually edit files in the "dist" subdirectory as they are generated via Grunt. You'll find source code in the "lib" subdirectory!_
283
284#### Release process
285
286To do a release of loglevel:
287
288* Update the version number in package.json and bower.json
289* Run `npm run dist` to build a distributable version in dist/
290* Update the release history in this file (below)
291* Commit the built code, tagging it with the version number and a brief message about the release
292* Push to Github
293* Run `npm publish .` to publish to NPM
294
295## Release History
296v0.1.0 - First working release with apparent compatibility with everything tested
297
298v0.2.0 - Updated release with various tweaks and polish and real proper documentation attached
299
300v0.3.0 - Some bugfixes (#12, #14), cookie-based log level persistence, doc tweaks, support for Bower and JamJS
301
302v0.3.1 - Fixed incorrect text in release build banner, various other minor tweaks
303
304v0.4.0 - Use LocalStorage for level persistence if available, compatibility improvements for IE, improved error messages, multi-environment tests
305
306v0.5.0 - Fix for Modernizr+IE8 issues, improved setLevel error handling, support for auto-activation of desired logging when console eventually turns up in IE8
307
308v0.6.0 - Handle logging in Safari private browsing mode (#33), fix TRACE level persistence bug (#35), plus various minor tweaks
309
310v1.0.0 - Official stable release! Fixed a bug with localStorage in Android webviews, improved CommonJS detection, and added noConflict().
311
312v1.1.0 - Added support for including loglevel with preprocessing and .apply() (#50), and fixed QUnit dep version which made tests potentially unstable.
313
314v1.2.0 - New plugin API! Plus various bits of refactoring and tidy up, nicely simplifying things and trimming the size down.
315
316v1.3.0 - Make persistence optional in setLevel, plus lots of documentation updates and other small tweaks
317
318v1.3.1 - With the new optional persistence, stop unnecessarily persisting the initially set default level (warn)
319
320v1.4.0 - Add getLevel(), setDefaultLevel() and getLogger() functionality for more fine-grained log level control
321
322v1.4.1 - Reorder UMD (#92) to improve bundling tool compatibility
323
324v1.5.0 - Fix log.debug (#111) after V8 changes deprecating console.debug, check for `window` upfront (#104), and add `.log` alias for `.debug` (#64)
325
326v1.5.1 - Fix bug (#112) in level-persistence cookie fallback, which failed if it wasn't the first cookie present
327
328v1.6.0 - Add a name property to loggers and add log.getLoggers() (#114), and recommend unpkg as CDN instead of CDNJS.
329
330v1.6.1 - Various small documentation & test updates
331
332v1.6.2 - Include TypeScript type definitions in the package itself
333
334v1.6.3 - Avoid TypeScript type conflicts with other global `log` types (e.g. `core-js`)
335
336v1.6.4 - Ensure package.json's 'main' is a fully qualified path, to fix webpack issues
337
338v1.6.5 - Ensure the provided message is included when calling trace() in IE11
339
340v1.6.6 - Fix bugs in v1.6.5, which caused issues in node.js & IE < 9
341
342v1.6.7 - Fix a bug in environments with `window` defined but no `window.navigator`
343
344v1.6.8 - Update TypeScript type definitions to include `log.log()`.
345
346v1.7.0 - Add support for Symbol-named loggers, and a `.default` property to help with ES6 module usage.
347
348v1.7.1 - Update TypeScript types to support Symbol-named loggers.
349
350v1.8.0 - Add resetLevel() method to clear persisted levels & reset to defaults
351
352## `loglevel` for enterprise
353
354Available as part of the Tidelift Subscription.
355
356The maintainers of `loglevel` and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-loglevel?utm_source=npm-loglevel&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
357
358## License
359Copyright (c) 2013 Tim Perry
360Licensed under the MIT license.
Note: See TracBrowser for help on using the repository browser.