## β‘ 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_
Create an [Environment Variable](https://developers.cloudflare.com/workers/platform/environments) with `DEBUG`.
> β οΈ Specifically referencing the Cloudflare Workers
#### _programmatic_
```ts
import { diary, enable } from 'diary';
enable('scopeA:two,scopeB:*');
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 β
enable('scopeA:*');
scopeA1.info('message'); // will log β
scopeA2.info('message'); // will log β
scopeB1.info('message'); // won't log β
scopeB2.info('message'); // won't log β
```
## π API
### diary(name: string, onEmit?: Reporter)
Returns: [log functions](#log-functions)
> A default diary is exported, accessible through simply importing any [log function](#log-functions).
>
>