@aglyn/shared-util-logger 1.0.0-beta.143 → 1.0.0-beta.144
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 +19 -19
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
# @aglyn/shared-util-logger
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A small leveled logger: named instances, a log level per instance, and a
|
|
4
|
+
replaceable handler. The larger Aglyn packages log through it, and it works on
|
|
5
|
+
its own. Its shape follows `@firebase/logger`; it depends on nothing.
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
> Beta. Published from the Aglyn monorepo under the `beta` dist-tag; APIs can change between beta releases.
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
## Install
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
npm install @aglyn/shared-util-logger@beta
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
visible to Firebase end developers should go through this module.
|
|
13
|
+
## Usage
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
Firebase components should import the `Logger` class and instantiate a new instance by passing a
|
|
17
|
-
component name (
|
|
18
|
-
e.g. `@aglyn/<project-name>`) to the constructor.
|
|
19
|
-
|
|
20
|
-
_e.g._
|
|
15
|
+
Create one `Logger` per component, named for it:
|
|
21
16
|
|
|
22
17
|
```typescript
|
|
23
|
-
import { Logger } from '@aglyn/shared-util-logger'
|
|
18
|
+
import { Logger, LogLevel } from '@aglyn/shared-util-logger'
|
|
24
19
|
|
|
25
|
-
const logger = new Logger(
|
|
20
|
+
const logger = new Logger('@acme/checkout')
|
|
21
|
+
logger.setLogLevel(LogLevel.WARN)
|
|
22
|
+
logger.warn('inventory is stale', { sku })
|
|
26
23
|
```
|
|
27
24
|
|
|
25
|
+
`logLevel` decides which calls reach the handler. `logHandler` replaces the
|
|
26
|
+
default handler, which writes to the console, and `userLogHandler` adds one
|
|
27
|
+
that runs beside it, for forwarding logs somewhere else.
|
|
28
|
+
|
|
28
29
|
Each `Logger` instance supports 5 log functions each to be used in a specific instance:
|
|
29
30
|
|
|
30
|
-
- `debug`: Internal
|
|
31
|
-
to diagnose an issue.
|
|
31
|
+
- `debug`: Internal detail, for diagnosing an issue.
|
|
32
32
|
- `log`: Use to inform your user about things they may need to know.
|
|
33
33
|
- `info`: Use if you have to inform the user about something that they need to take a concrete
|
|
34
34
|
action on. Once they take that action, the log should go away.
|
|
@@ -43,6 +43,6 @@ Each log will be formatted in the following manner:
|
|
|
43
43
|
`"[${new Date()}] ${COMPONENT_NAME}: ${...args}"`
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
-
##
|
|
46
|
+
## License
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
Apache-2.0. Source: https://github.com/aglyn/aglyn/tree/main/libs/shared/util/logger
|