UNPKG

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