@jeffchi/logger 1.0.7 → 1.0.8

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 ADDED
@@ -0,0 +1,120 @@
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
+ [![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg?logo=jest)](https://github.com/facebook/jest)
10
+ ![test](https://github.com/vueComponent/ant-design-vue/workflows/test/badge.svg)
11
+ [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
12
+ [![actions-cool](https://img.shields.io/badge/using-actions--cool-blue?style=flat-square)](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
+
42
+ ```javascript
43
+ import { loggerWithTags } from '@jeffchi/logger';
44
+ import { LogLevel, LogMode } from '@jeffchi/logger/lib/interface';
45
+ const { debug,error,info,log,warn } = loggerWithTags(
46
+ 'api', // ['api','get'] 一个或多个tag
47
+ {
48
+ level: LogLevel.LOG, // 日志级别只有指定级别的日志才会输出至日志文件
49
+ date: 'MMM dd, yyyy HH:mm:ss.sss', // 日志输出的时间戳格式,true表示使用默认utc IOS日期时间格式,false表示不输出时间戳
50
+ env: LogMode.ALL, // 环境参数,开发版本或生产版本,如果指定开发环境,则生产环境不输出任何内容,也不会写入到日志文件
51
+ disableWarn: false, // 禁用Warn输出,用debug代替,仅影响前端控制台和后端终端,不影响实际内容打印.在跑测试时应该启用,避免影响测试结果
52
+ disableError: false, // 禁用Error输出,用debug代替,仅影响前端控制台和后端终端,不影响实际内容打印.在跑测试时应该启用,避免影响测试结果
53
+ ignoreThrow: false, // 默认Error输出后,会抛出异常,从而打断后端执行流程,可指定true取消该行为,在跑测试时应该启用,避免影响测试测试流程
54
+ outputFile: 'logs/<yyyy-MM-dd>.log', // 输出日志文件的位置,仅服务端使用时有效
55
+ }
56
+ );
57
+ ```
58
+
59
+ ## 参数
60
+
61
+ ```javascript
62
+ loggerWithTags( tags:LogTags, options:ILogOptions );
63
+ ```
64
+
65
+ ### tags
66
+
67
+ ```javascript
68
+ /** 日志标签 */
69
+ export type LogTags = string | string[];
70
+ ```
71
+
72
+ ### options
73
+ ```javascript
74
+
75
+ /** 日志配置选项 */
76
+ export interface ILogOptions {
77
+ /** 日志级别
78
+ * @default LogLevel.LOG
79
+ */
80
+ level?: LogLevel;
81
+ /**
82
+ * 是否支持输出时间戳及时间戳格式
83
+ *
84
+ * 字符串格式参见: https://github.com/date-fns/date-fns/blob/main/src/format/index.ts
85
+ * @default true 开启后默认IOS格式 'yyyy-MM-ddTHH:mm:ss.SSSZ'
86
+ */
87
+ date?: boolean | string;
88
+ /**
89
+ * 日志输出条件,默认全部输出
90
+ * @default 'all'
91
+ */
92
+ env?: LogMode;
93
+ /** 禁用warn输出,避免在测试场景下影响测试结果
94
+ * @default false
95
+ */
96
+ disableWarn?: boolean;
97
+ /** 禁用error输出,避免在测试场景下打断正常测试流程
98
+ * @default false
99
+ */
100
+ disableError?: boolean;
101
+ /** 调用error输出错误信息后,禁止继续抛出异常错误
102
+ * @description
103
+ * 调用error输出错误信息后,默认继续抛出异常错误,在测试环境下可以临地禁用,避免影响正常的测试流程
104
+ */
105
+ ignoreThrow?: boolean;
106
+ /**
107
+ * 基于当前工程根目录下的日志输出文件
108
+ *
109
+ * @description
110
+ * 浏览器环境:自动忽略该选项;
111
+ *
112
+ * node环境下默认 logs/xxx.log
113
+ */
114
+ outputFile?: string;
115
+ }
116
+
117
+ ```
118
+
119
+ ## Lincence
120
+ MIT
@@ -20,8 +20,9 @@ export declare enum LogLevel {
20
20
  ERROR = "ERROR",
21
21
  DEBUG = "DEBUG"
22
22
  }
23
+ /** 日志标签 */
23
24
  export type LogTags = string | string[];
24
- /** 日志输入配置选项 */
25
+ /** 日志配置选项 */
25
26
  export interface ILogOptions {
26
27
  /** 日志级别
27
28
  * @default LogLevel.LOG
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jeffchi/logger",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
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",