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