1 | # @bearer/logger
|
2 |
|
3 | ## Usage
|
4 |
|
5 | We recommend to create a logger file within you project
|
6 |
|
7 | ```ts
|
8 | // my-logger.ts
|
9 | import debug from '@bearer/logger'
|
10 |
|
11 | export default () => debug('my-package-name')
|
12 | ```
|
13 |
|
14 | then in your app
|
15 |
|
16 | ```ts
|
17 | import debug from 'path/to/my-logger'
|
18 |
|
19 | const logger = debug()
|
20 | logger('message to debug')
|
21 | logger({ object: 'something' })
|
22 |
|
23 | // sub logger
|
24 |
|
25 | const subLogger = logger.extend('sub-feature')
|
26 | subLogger('blablabl')
|
27 | ```
|
28 |
|
29 | You'll need to set `DEBUG=*` to see all logs or `DEBUG=bearer:my-package-name` to see logs produced by your application.
|
30 |
|
31 | ### Browser support
|
32 |
|
33 | We assume you are writing a bearer integration.
|
34 |
|
35 | _views/src/my-component.tsx_
|
36 |
|
37 | ```tsx
|
38 | import debug from '@bearer/logger'
|
39 |
|
40 | const logger = debug('a-scope-you-provide')
|
41 |
|
42 | class MyComponent {
|
43 | componentDidLoad() {
|
44 | logger('Loaded')
|
45 | }
|
46 | }
|
47 | ```
|
48 |
|
49 | if you want to see logs you must enable it by setting the `localStorage.debug` value from your console
|
50 |
|
51 | **Show all logs**
|
52 |
|
53 | ```js
|
54 | localStorage.debug = '*'
|
55 | ```
|
56 |
|
57 | **Show bearer logs only**
|
58 |
|
59 | ```js
|
60 | localStorage.debug = 'bearer:*'
|
61 | ```
|
62 |
|
63 | **Show your integration logs only**
|
64 |
|
65 | ```js
|
66 | localStorage.debug = 'bearer:a-scope-you-provide:*'
|
67 | ```
|