## β‘ Features
- No [dependencies](https://npm.anvaka.com/#/view/2d/diary)
- Outstanding [performance](#-benchmark)
- Support for [`debug`'s filter](https://www.npmjs.com/package/debug#wildcards)
- Browser compatible through `localStorage`
## βοΈ Install
```sh
npm add diary
```
## π Usage
```ts
import { info, diary } from 'diary';
info('this important thing happened');
// ~> βΉ info this important thing happened
const scopedDiary = diary('my-module', (event) => {
if (event.level === 'error') {
Sentry.captureException(event.error);
}
});
scopedDiary.info('this other important thing happened');
// ~> βΉ info [my-module] this other important thing happened
```
Controlling runtime emission of logs, using the code below as an example:
```ts
// example.js
import { diary } from 'diary';
const scopeA1 = diary('scopeA:one');
const scopeA2 = diary('scopeA:two');
const scopeB1 = diary('scopeB:one');
const scopeB2 = diary('scopeB:two');
scopeA1.info('message'); // won't log β
scopeA2.info('message'); // will log β
scopeB1.info('message'); // will log β
scopeB2.info('message'); // will log β
```
#### _browser_
```ts
localStorage.setItem('DEBUG', 'scopeA:two,scopeB:*');
// then your scripts
```
> π‘ Tip - Set this via the DevTools, then hit refresh. Saves you having to re-bundle.
#### _node_
```sh
DEBUG=scopeA:two,scopeB:* node example.js
```
#### _workers_
As of version v0.3.0 to enable log events you must use the `enable` programmatic api, this is due to Module Workers no
longer offering global environment variables, and instead they are injected through an api.
Ambiant logs do however need to be statically enabled. (put a `enable()` in module scope).