@likec4/log 1.21.1 → 1.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,36 @@
1
1
  # `@likec4/log`
2
2
 
3
- Shared instance of [consola](https://github.com/unjs/consola)
3
+ Shared interface for logging.
4
+
5
+ ## Usage
6
+
7
+ ```ts
8
+ import { createLogger, loggable, rootLogger } from '@likec4/log'
9
+
10
+ const logger = createLogger('module')
11
+ // OR
12
+ const logger = rootLogger.getChild('module')
13
+ ```
14
+
15
+ ## Prefer template strings
16
+
17
+ ```ts
18
+ const name = 'world'
19
+ logger.info`Hello, ${name}!`
20
+ ```
21
+
22
+ ## Logging errors
23
+
24
+ When logging errors, you can use `loggable`:
25
+
26
+ ```ts
27
+ import { loggable } from '@likec4/log'
28
+
29
+ try {
30
+ throw new Error('Something went wrong')
31
+ } catch (error) {
32
+ logger.error(loggable(error))
33
+ // OR pass as second argument
34
+ logger.error('An error occurred', { error })
35
+ }
36
+ ```