@weapp-core/logger 3.0.2 → 3.0.3
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 +44 -0
- package/dist/index.d.ts +9 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# @weapp-core/logger
|
|
2
|
+
|
|
3
|
+
## 简介
|
|
4
|
+
|
|
5
|
+
`@weapp-core/logger` 是基于 consola 的日志封装,提供全局级别控制与按 tag 的细粒度过滤,适合在 weapp-vite 相关工具链中统一输出风格。
|
|
6
|
+
|
|
7
|
+
## 特性
|
|
8
|
+
|
|
9
|
+
- 全局日志级别控制
|
|
10
|
+
- 按 tag 覆盖日志级别
|
|
11
|
+
- API 兼容 consola 的常用用法
|
|
12
|
+
|
|
13
|
+
## 安装
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add @weapp-core/logger
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## 使用
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import logger, { configureLogger } from '@weapp-core/logger'
|
|
23
|
+
|
|
24
|
+
configureLogger({
|
|
25
|
+
level: 'info',
|
|
26
|
+
tags: {
|
|
27
|
+
build: 'warn',
|
|
28
|
+
},
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
logger.info('Hello')
|
|
32
|
+
logger.withTag('build').warn('Build warning')
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## 配置
|
|
36
|
+
|
|
37
|
+
`configureLogger` 选项:
|
|
38
|
+
|
|
39
|
+
- `level`:全局日志级别(`info` / `warn` / `error` / `silent`)
|
|
40
|
+
- `tags`:按 tag 覆盖级别
|
|
41
|
+
|
|
42
|
+
## 相关链接
|
|
43
|
+
|
|
44
|
+
- 仓库:https://github.com/weapp-vite/weapp-vite
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { ConsolaInstance } from 'consola';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @description 日志类型
|
|
5
|
+
*/
|
|
3
6
|
type LogType = 'error' | 'warn' | 'info';
|
|
7
|
+
/**
|
|
8
|
+
* @description 日志级别
|
|
9
|
+
*/
|
|
4
10
|
type LogLevel = LogType | 'silent';
|
|
5
11
|
interface LoggerConfig {
|
|
6
12
|
/**
|
|
@@ -16,6 +22,9 @@ interface LoggerConfig {
|
|
|
16
22
|
*/
|
|
17
23
|
tags?: Record<string, LogLevel | undefined>;
|
|
18
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* @description 设置全局 logger 配置
|
|
27
|
+
*/
|
|
19
28
|
declare function configureLogger(config?: LoggerConfig): void;
|
|
20
29
|
declare const logger: ConsolaInstance;
|
|
21
30
|
|