UNPKG

4.67 kBMarkdownView Raw
1[tests]: https://img.shields.io/circleci/project/github/shellscape/loglevelnext.svg
2[tests-url]: https://circleci.com/gh/shellscape/loglevelnext
3[cover]: https://codecov.io/gh/shellscape/loglevelnext/branch/master/graph/badge.svg
4[cover-url]: https://codecov.io/gh/shellscape/loglevelnext
5[size]: https://packagephobia.now.sh/badge?p=loglevelnext
6[size-url]: https://packagephobia.now.sh/result?p=loglevelnext
7[loglevel]: https://githhub.com/pimterry/loglevel
8[loglevelpre]: https://github.com/kutuluk/loglevel-plugin-prefix
9[methodfactory]: lib/factory/MethodFactory.js
10[prefixfactory]: lib/factory/PrefixFactory.js
11
12<div align="center">
13 <img width="150" height="150" src="http://shellscape.org/assets/images/external/loglevelnext-icon.svg">
14</div>
15<br/>
16
17[![tests][tests]][tests-url]
18[![cover][cover]][cover-url]
19[![size][size]][size-url]
20
21# loglevelnext
22
23`loglevelnext` is a modern logging library for Node.js and modern browsers, written with modern patterns and practices which provides log level mapping of the `console` object.
24
25For browser use, or use in client-side applications, `loglevelnext` should be bundled by your preferred bundler or compiler, such as [Rollup](https://rollupjs.org).
26
27## Getting Started
28
29First thing's first, install the module:
30
31```console
32npm install loglevelnext --save
33```
34
35## Usage
36
37Users can choose to use `loglevelnext` in Node.js or in the client (browser).
38
39```js
40const log = require('loglevelnext');
41
42log.info('bananas!');
43```
44
45## Log Levels
46
47By default `loglevelnext` ships supporting the following log level name-value
48pairs:
49
50```js
51{
52 TRACE: 0,
53 DEBUG: 1,
54 INFO: 2,
55 WARN: 3,
56 ERROR: 4,
57 SILENT: 5
58}
59```
60
61## Default Logger
62
63When requiring `loglevelnext` in Node.js the default export will be an instance of [`LogLevel`](docs/LogLevel.md) wrapped with some extra sugar.
64
65### Methods
66
67Please see [`LogLevel`](docs/LogLevel.md) for documentation of all methods and properties of every log instance, including the default instance.
68
69#### `trace`, `debug`, `info`, `warn`, `error`
70
71These methods correspond to the available log levels and accept parameters identical to their `console` counterparts. e.g.
72
73```js
74console.info('...');
75console.info('...');
76// ... etc
77```
78
79#### `create(options)`
80
81Returns a new `LogLevel` instance. The `options` parameter should be an `Object` matching the options for the [`LogLevel`](docs/LogLevel.md) constructor.
82
83_Note: `LogLevel` instances created are cached. Calling `create` with a previously used `name` will return the cached `LogLevel` instance. To create a different instance with the same `name`, assign a unique `id` property to the `options` parameter._
84
85### Properties
86
87#### `factories`
88
89Type: `Array [ Class ]`
90
91Returns an `Array` containing the factory classes available within `loglevelnext`
92to outside modules. Particularly useful when creating plugins. eg.
93
94```js
95const log = require('loglevelnext');
96const { MethodFactory } = log.factories;
97class MyFactory extends MethodFactory { ... }
98```
99
100#### `loggers`
101
102Type: `Array [ LogLevel ]`
103
104Returns an `Array` containing references to the currently instantiated loggers.
105
106## Factories aka Plugins
107
108If you're used to using plugins with `loglevel`, fear not. The same capabilities
109are available in `loglevelnext`, but in a much more straightforward and structured
110way. `loglevelnext` supports by way of "Factories." A `Factory` is nothing more
111than a class which defines several base methods that operate on the `console`
112and provide functionality to a `LogLevel` instance. All factories must inherit from the
113[`MethodFactory`][methodfactory] class, and may override any defined class functions.
114
115For an example factory, please have a look at the [`PrefixFactory`][prefixfactory]
116which provides similar functionality as the [loglevel-prefix](loglevelpre) plugin,
117and is the factory which is used when a user passes the `prefix` option to a
118`LogLevel` instance.
119
120## Browser Support
121
122As mentioned, `loglevelnext` is a logging library for Node.js and _modern_ browsers, which means the latest versions of the major browsers. When bundling or compiling `loglevelnext` for use in a browser, you should ensure that appropriate polyfills are used. e.g. Internet Explorer typically requires polyfilling both `Symbol` and `Object.assign`.
123
124## Attribution
125
126_This project originated as a fork of the much-loved [loglevel](loglevel) module, but has diverged and has been rewritten, and now shares similarities only in functional intent._
127
128Base Log SVG by [Freepik](http://www.freepik.com/) from [www.flaticon.com](http://www.flaticon.com).
129
130## Meta
131
132[CONTRIBUTING](./.github/CONTRIBUTING)
133
134[LICENSE (Mozilla Public License)](./LICENSE)