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 |
|
25 | For 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 |
|
29 | First thing's first, install the module:
|
30 |
|
31 | ```console
|
32 | npm install loglevelnext --save
|
33 | ```
|
34 |
|
35 | ## Usage
|
36 |
|
37 | Users can choose to use `loglevelnext` in Node.js or in the client (browser).
|
38 |
|
39 | ```js
|
40 | const log = require('loglevelnext');
|
41 |
|
42 | log.info('bananas!');
|
43 | ```
|
44 |
|
45 | ## Log Levels
|
46 |
|
47 | By default `loglevelnext` ships supporting the following log level name-value
|
48 | pairs:
|
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 |
|
63 | When 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 |
|
67 | Please 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 |
|
71 | These methods correspond to the available log levels and accept parameters identical to their `console` counterparts. e.g.
|
72 |
|
73 | ```js
|
74 | console.info('...');
|
75 | console.info('...');
|
76 | // ... etc
|
77 | ```
|
78 |
|
79 | #### `create(options)`
|
80 |
|
81 | Returns 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 |
|
89 | Type: `Array [ Class ]`
|
90 |
|
91 | Returns an `Array` containing the factory classes available within `loglevelnext`
|
92 | to outside modules. Particularly useful when creating plugins. eg.
|
93 |
|
94 | ```js
|
95 | const log = require('loglevelnext');
|
96 | const { MethodFactory } = log.factories;
|
97 | class MyFactory extends MethodFactory { ... }
|
98 | ```
|
99 |
|
100 | #### `loggers`
|
101 |
|
102 | Type: `Array [ LogLevel ]`
|
103 |
|
104 | Returns an `Array` containing references to the currently instantiated loggers.
|
105 |
|
106 | ## Factories aka Plugins
|
107 |
|
108 | If you're used to using plugins with `loglevel`, fear not. The same capabilities
|
109 | are available in `loglevelnext`, but in a much more straightforward and structured
|
110 | way. `loglevelnext` supports by way of "Factories." A `Factory` is nothing more
|
111 | than a class which defines several base methods that operate on the `console`
|
112 | and provide functionality to a `LogLevel` instance. All factories must inherit from the
|
113 | [`MethodFactory`][methodfactory] class, and may override any defined class functions.
|
114 |
|
115 | For an example factory, please have a look at the [`PrefixFactory`][prefixfactory]
|
116 | which provides similar functionality as the [loglevel-prefix](loglevelpre) plugin,
|
117 | and is the factory which is used when a user passes the `prefix` option to a
|
118 | `LogLevel` instance.
|
119 |
|
120 | ## Browser Support
|
121 |
|
122 | As 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 |
|
128 | Base 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)
|