@jeffchi/logger 1.0.7 → 1.1.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 +138 -0
- package/lib/interface.d.ts +2 -1
- package/package.json +1 -2
package/README.md
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
<h1 align="center">
|
|
2
|
+
<a href="https://github.com/poechiang/jeffchi-logger#readme" target="_blank">jeffchi-logger</a>
|
|
3
|
+
</h1>
|
|
4
|
+
|
|
5
|
+
<div align="center">
|
|
6
|
+
|
|
7
|
+
A log print output javascript tool library that can be used at the front and back ends
|
|
8
|
+
|
|
9
|
+
[](https://github.com/facebook/jest)
|
|
10
|
+

|
|
11
|
+
[](https://github.com/prettier/prettier)
|
|
12
|
+
[](https://github.com/actions-cool)
|
|
13
|
+
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
## 支持环境
|
|
17
|
+
|
|
18
|
+
- 现代浏览器。
|
|
19
|
+
- 支持服务端使用, 在服务端使用时默认写入 %root%/logs/yyyy-mm-dd.log 日志文件。
|
|
20
|
+
|
|
21
|
+
| [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/edge/edge_48x48.png" alt="IE / Edge" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>IE / Edge | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png" alt="Firefox" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Firefox | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png" alt="Chrome" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Chrome | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari/safari_48x48.png" alt="Safari" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Safari | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/opera/opera_48x48.png" alt="Opera" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Opera |
|
|
22
|
+
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
23
|
+
| Edge | last 2 versions | last 2 versions | last 2 versions | last 2 versions |
|
|
24
|
+
|
|
25
|
+
## 安装
|
|
26
|
+
|
|
27
|
+
### 使用 npm 或 yarn 安装
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
$ npm install @jeffchi/logger --save
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
$ yarn add @jeffchi/logger
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
如果你的网络环境不佳,推荐使用 [cnpm](https://github.com/cnpm/cnpm)。
|
|
38
|
+
|
|
39
|
+
## 用法
|
|
40
|
+
|
|
41
|
+
```javascript
|
|
42
|
+
import { loggerWithTags } from '@jeffchi/logger';
|
|
43
|
+
import { LogLevel, LogMode } from '@jeffchi/logger/lib/interface';
|
|
44
|
+
const { debug, error, info, log, warn } = loggerWithTags(
|
|
45
|
+
'api', // ['api','get'] 一个或多个tag
|
|
46
|
+
{
|
|
47
|
+
level: LogLevel.LOG, // 日志级别只有指定级别的日志才会输出至日志文件
|
|
48
|
+
date: 'MMM dd, yyyy HH:mm:ss.sss', // 日志输出的时间戳格式,true表示使用默认utc IOS日期时间格式,false表示不输出时间戳
|
|
49
|
+
env: LogMode.ALL, // 环境参数,开发版本或生产版本,如果指定开发环境,则生产环境不输出任何内容,也不会写入到日志文件
|
|
50
|
+
disableWarn: false, // 禁用Warn输出,用debug代替,仅影响前端控制台和后端终端,不影响实际内容打印.在跑测试时应该启用,避免影响测试结果
|
|
51
|
+
disableError: false, // 禁用Error输出,用debug代替,仅影响前端控制台和后端终端,不影响实际内容打印.在跑测试时应该启用,避免影响测试结果
|
|
52
|
+
ignoreThrow: false, // 默认Error输出后,会抛出异常,从而打断后端执行流程,可指定true取消该行为,在跑测试时应该启用,避免影响测试测试流程
|
|
53
|
+
outputFile: 'logs/<yyyy-MM-dd>.log', // 输出日志文件的位置,仅服务端使用时有效
|
|
54
|
+
},
|
|
55
|
+
);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## 参数
|
|
59
|
+
|
|
60
|
+
```javascript
|
|
61
|
+
loggerWithTags( tags:LogTags, options:ILogOptions );
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### tags
|
|
65
|
+
|
|
66
|
+
```javascript
|
|
67
|
+
/** 日志标签 */
|
|
68
|
+
export type LogTags = string | string[];
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### options
|
|
72
|
+
|
|
73
|
+
```javascript
|
|
74
|
+
/** 日志配置选项 */
|
|
75
|
+
export interface ILogOptions {
|
|
76
|
+
/** 日志级别
|
|
77
|
+
* @default LogLevel.LOG
|
|
78
|
+
*/
|
|
79
|
+
level?: LogLevel;
|
|
80
|
+
/**
|
|
81
|
+
* 是否支持输出时间戳及时间戳格式
|
|
82
|
+
*
|
|
83
|
+
* 字符串格式参见: https://github.com/date-fns/date-fns/blob/main/src/format/index.ts
|
|
84
|
+
* @default true 开启后默认IOS格式 'yyyy-MM-ddTHH:mm:ss.SSSZ'
|
|
85
|
+
*/
|
|
86
|
+
date?: boolean | string;
|
|
87
|
+
/**
|
|
88
|
+
* 日志输出条件,默认全部输出
|
|
89
|
+
* @default 'all'
|
|
90
|
+
*/
|
|
91
|
+
env?: LogMode;
|
|
92
|
+
/** 禁用warn输出,避免在测试场景下影响测试结果
|
|
93
|
+
* @default false
|
|
94
|
+
*/
|
|
95
|
+
disableWarn?: boolean;
|
|
96
|
+
/** 禁用error输出,避免在测试场景下打断正常测试流程
|
|
97
|
+
* @default false
|
|
98
|
+
*/
|
|
99
|
+
disableError?: boolean;
|
|
100
|
+
/** 调用error输出错误信息后,禁止继续抛出异常错误
|
|
101
|
+
* @description
|
|
102
|
+
* 调用error输出错误信息后,默认继续抛出异常错误,在测试环境下可以临地禁用,避免影响正常的测试流程
|
|
103
|
+
*/
|
|
104
|
+
ignoreThrow?: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* 基于当前工程根目录下的日志输出文件
|
|
107
|
+
*
|
|
108
|
+
* @description
|
|
109
|
+
* 浏览器环境:自动忽略该选项;
|
|
110
|
+
*
|
|
111
|
+
* node环境下默认 logs/xxx.log
|
|
112
|
+
*/
|
|
113
|
+
outputFile?: string;
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## 测试
|
|
118
|
+
|
|
119
|
+
`src/__test__` 目录下的 `*.spec.ts` 和 `*.test.ts` 是测试文件.
|
|
120
|
+
|
|
121
|
+
- `*.spec.ts` 特定于指定版本的测试文件,需要切换到指定版本分支才能保证测试通过
|
|
122
|
+
- `*.test.ts` 当前版本的测试文件
|
|
123
|
+
|
|
124
|
+
> 测试基于 `ts-jest`,终端窗口通过指定参数,来运行特定的测试文件
|
|
125
|
+
>
|
|
126
|
+
> ```bash
|
|
127
|
+
> npm run test 1.0.3 # 1.0.3的测试文件
|
|
128
|
+
> npm run test main # 当前测试文件
|
|
129
|
+
> npm run test # 所有测试文件
|
|
130
|
+
> ```
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
MIT
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
```
|
package/lib/interface.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jeffchi/logger",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"description": "A log print output javascript tool library that can be used at the front and back ends",
|
|
@@ -49,7 +49,6 @@
|
|
|
49
49
|
"@types/lodash": "^4.14.191",
|
|
50
50
|
"@types/node": "^18.11.18",
|
|
51
51
|
"jest": "^29.3.1",
|
|
52
|
-
"lodash": "^4.17.21",
|
|
53
52
|
"prettier": "^2.8.2",
|
|
54
53
|
"ts-jest": "^29.0.5",
|
|
55
54
|
"tslint": "^6.1.3",
|