@0xchain/logger 1.1.0-beta.17 → 1.1.0-beta.19
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/LICENSE +21 -0
- package/dist/index.js +15 -13
- package/package.json +10 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present 0xchain
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.js
CHANGED
|
@@ -1,31 +1,33 @@
|
|
|
1
|
-
import
|
|
2
|
-
const
|
|
3
|
-
|
|
1
|
+
import pino from "pino";
|
|
2
|
+
const logLevel = process.env.NODE_ENV === "production" ? "info" : "trace";
|
|
3
|
+
const frontendOrigin = process.env.NEXT_PUBLIC_BASE_URL || "";
|
|
4
|
+
const logUrl = `${frontendOrigin}/api/logger`;
|
|
5
|
+
const logger = pino({
|
|
6
|
+
level: logLevel,
|
|
4
7
|
// 设置输出的日志级别,只输出指定级别及以上的日志
|
|
5
|
-
timestamp:
|
|
8
|
+
timestamp: pino.stdTimeFunctions.isoTime,
|
|
6
9
|
// 设置时间戳格式
|
|
7
10
|
browser: {
|
|
8
11
|
// 参见 https://github.com/pinojs/pino/issues/1795
|
|
9
|
-
write: () =>
|
|
10
|
-
},
|
|
12
|
+
write: () => void 0,
|
|
11
13
|
// 禁止在浏览器控制台输出日志
|
|
12
|
-
asObject:
|
|
14
|
+
asObject: true,
|
|
13
15
|
// 配置将浏览器和中间件的日志发送到服务器
|
|
14
16
|
transmit: {
|
|
15
|
-
send: (
|
|
16
|
-
const
|
|
17
|
-
fetch(
|
|
17
|
+
send: (level, logEvent) => {
|
|
18
|
+
const messages = logEvent.messages;
|
|
19
|
+
void fetch(logUrl, {
|
|
18
20
|
method: "POST",
|
|
19
21
|
headers: {
|
|
20
22
|
"Content-Type": "application/json"
|
|
21
23
|
},
|
|
22
|
-
body: JSON.stringify({ level
|
|
23
|
-
keepalive:
|
|
24
|
+
body: JSON.stringify({ level, messages }),
|
|
25
|
+
keepalive: true
|
|
24
26
|
});
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
30
|
});
|
|
29
31
|
export {
|
|
30
|
-
|
|
32
|
+
logger
|
|
31
33
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xchain/logger",
|
|
3
|
-
"version": "1.1.0-beta.
|
|
3
|
+
"version": "1.1.0-beta.19",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -17,9 +17,17 @@
|
|
|
17
17
|
"dist",
|
|
18
18
|
"!**/*.tsbuildinfo"
|
|
19
19
|
],
|
|
20
|
-
"
|
|
20
|
+
"peerDependencies": {
|
|
21
21
|
"pino": "9.9.4"
|
|
22
22
|
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"pino": "9.9.4"
|
|
25
|
+
},
|
|
26
|
+
"nx": {
|
|
27
|
+
"tags": [
|
|
28
|
+
"type:util"
|
|
29
|
+
]
|
|
30
|
+
},
|
|
23
31
|
"publishConfig": {
|
|
24
32
|
"access": "public"
|
|
25
33
|
}
|