@rife/logger 0.0.6-beta.13 → 0.0.6-beta.15

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.
@@ -75,7 +75,7 @@ var __webpack_exports__ = {};
75
75
  'thread-stream-worker': external_path_default().join(__dirname, './worker/thread-stream.cjs'),
76
76
  ...globalThis.__bundlerPathsOverrides
77
77
  };
78
- 'production' === process.env.NODE_ENV || targets.push({
78
+ 'production' === process.env.NODE_ENV || void 0 !== process.env.VITEST || targets.push({
79
79
  level: 'debug',
80
80
  target: 'pino-pretty',
81
81
  options: {
@@ -31,7 +31,7 @@ function getPinoConfig() {
31
31
  'thread-stream-worker': path.join(pino_dirname, './worker/thread-stream.cjs'),
32
32
  ...globalThis.__bundlerPathsOverrides
33
33
  };
34
- 'production' === process.env.NODE_ENV || targets.push({
34
+ 'production' === process.env.NODE_ENV || void 0 !== process.env.VITEST || targets.push({
35
35
  level: 'debug',
36
36
  target: 'pino-pretty',
37
37
  options: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rife/logger",
3
- "version": "0.0.6-beta.13",
3
+ "version": "0.0.6-beta.15",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "types": "./src/index.ts",
@@ -44,8 +44,8 @@
44
44
  },
45
45
  "devDependencies": {
46
46
  "thread-stream": "^4.0.0",
47
- "@rife/cli": "0.0.6-beta.22",
48
- "@rife/plugin-rstack": "0.0.1-beta.20"
47
+ "@rife/cli": "0.0.6-beta.23",
48
+ "@rife/plugin-rstack": "0.0.1-beta.23"
49
49
  },
50
50
  "scripts": {
51
51
  "dev": "rife dev",
package/src/pino/index.ts CHANGED
@@ -2,15 +2,15 @@ import path from 'path';
2
2
 
3
3
  import pino from 'pino';
4
4
 
5
- import { genTraceId, getTraceId, runInTrace } from '../trace';
6
5
  export { pino };
6
+ // 避免报错 "This is likely not portable. A type annotation is necessary."
7
+ export type { Logger } from 'pino';
8
+
9
+ import { genTraceId, getTraceId, runInTrace } from '../trace';
7
10
 
8
11
  declare var __isNodeSingleFileBundle: any;
9
12
  declare var __isVite: any;
10
13
 
11
- /** @ts-ignore 当前是cloudflare worker */
12
- const isCFWorker = typeof WebSocketPair !== 'undefined';
13
-
14
14
  // https://github.com/pinojs/pino/blob/master/docs/api.md
15
15
  function getPinoConfig() {
16
16
  const targets: any = [];
@@ -40,7 +40,10 @@ function getPinoConfig() {
40
40
  };
41
41
  }
42
42
 
43
- if (process.env.NODE_ENV === 'production') {
43
+ if (
44
+ process.env.NODE_ENV === 'production' ||
45
+ typeof process.env.VITEST !== 'undefined' // VITEST
46
+ ) {
44
47
  } else {
45
48
  targets.push({
46
49
  level: 'debug',
package/tsconfig.json CHANGED
@@ -1,9 +1,7 @@
1
1
  {
2
2
  "extends": "@rife/config/tsconfig.json", // 继承 packages 目录下通用配置
3
3
  "compilerOptions": {
4
- "outDir": "dist",
5
4
  "declaration": true,
6
- "baseUrl": ".",
7
5
  "paths": {
8
6
  "@/*": ["./src/*"]
9
7
  }
@@ -1,116 +0,0 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.n = (module)=>{
5
- var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
- __webpack_require__.d(getter, {
7
- a: getter
8
- });
9
- return getter;
10
- };
11
- })();
12
- (()=>{
13
- __webpack_require__.d = (exports1, definition)=>{
14
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
- enumerable: true,
16
- get: definition[key]
17
- });
18
- };
19
- })();
20
- (()=>{
21
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
- })();
23
- (()=>{
24
- __webpack_require__.r = (exports1)=>{
25
- if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
- value: 'Module'
27
- });
28
- Object.defineProperty(exports1, '__esModule', {
29
- value: true
30
- });
31
- };
32
- })();
33
- var __webpack_exports__ = {};
34
- __webpack_require__.r(__webpack_exports__);
35
- __webpack_require__.d(__webpack_exports__, {
36
- createLogger: ()=>createLogger
37
- });
38
- const external_pino_namespaceObject = require("pino");
39
- var external_pino_default = /*#__PURE__*/ __webpack_require__.n(external_pino_namespaceObject);
40
- const external_path_namespaceObject = require("path");
41
- var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
42
- const external_trace_cjs_namespaceObject = require("../trace.cjs");
43
- function getPinoConfig() {
44
- const targets = [];
45
- if ('production' === process.env.NODE_ENV) ;
46
- else {
47
- const rotate = `./rotate${external_path_default().extname(__filename)}`;
48
- targets.push({
49
- level: 'debug',
50
- target: rotate,
51
- options: {
52
- path: './logs/'
53
- }
54
- });
55
- targets.push({
56
- level: 'debug',
57
- target: 'pino-pretty',
58
- options: {
59
- ignore: 'pid',
60
- messageKey: 'message'
61
- }
62
- });
63
- }
64
- const config = {
65
- transport: {
66
- targets
67
- },
68
- mixin (data) {
69
- const traceId = data?.traceId;
70
- delete data.traceId;
71
- delete data.level;
72
- delete data.time;
73
- delete data.pid;
74
- delete data.name;
75
- delete data.hostname;
76
- if (!traceId) return {
77
- traceId: (0, external_trace_cjs_namespaceObject.getTraceId)()
78
- };
79
- return {
80
- traceId
81
- };
82
- },
83
- browser: {
84
- write: (o)=>{
85
- const { name, time, level, ...rest } = o;
86
- if (name) rest.message = rest.message ? `[${name}] ${rest.message}` : `[${name}]`;
87
- if (!rest.traceId) rest.traceId = (0, external_trace_cjs_namespaceObject.getTraceId)();
88
- if (level >= 50) console.error(rest);
89
- else if (level >= 40) console.warn(rest);
90
- else console.log(rest);
91
- }
92
- }
93
- };
94
- return config;
95
- }
96
- function createLogger() {
97
- const logger = external_pino_default()({
98
- base: {
99
- pid: process.pid
100
- },
101
- messageKey: 'message',
102
- errorKey: 'error',
103
- timestamp: external_pino_default().stdTimeFunctions.epochTime,
104
- ...getPinoConfig()
105
- });
106
- return {
107
- logger
108
- };
109
- }
110
- exports.createLogger = __webpack_exports__.createLogger;
111
- for(var __rspack_i in __webpack_exports__)if (-1 === [
112
- "createLogger"
113
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
114
- Object.defineProperty(exports, '__esModule', {
115
- value: true
116
- });
@@ -1,74 +0,0 @@
1
- import "node:module";
2
- import pino from "pino";
3
- import path from "path";
4
- import { getTraceId } from "../trace.mjs";
5
- import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
6
- var worker_filename = __rspack_fileURLToPath(import.meta.url);
7
- function getPinoConfig() {
8
- const targets = [];
9
- if ('production' === process.env.NODE_ENV) ;
10
- else {
11
- const rotate = `./rotate${path.extname(worker_filename)}`;
12
- targets.push({
13
- level: 'debug',
14
- target: rotate,
15
- options: {
16
- path: './logs/'
17
- }
18
- });
19
- targets.push({
20
- level: 'debug',
21
- target: 'pino-pretty',
22
- options: {
23
- ignore: 'pid',
24
- messageKey: 'message'
25
- }
26
- });
27
- }
28
- const config = {
29
- transport: {
30
- targets
31
- },
32
- mixin (data) {
33
- const traceId = data?.traceId;
34
- delete data.traceId;
35
- delete data.level;
36
- delete data.time;
37
- delete data.pid;
38
- delete data.name;
39
- delete data.hostname;
40
- if (!traceId) return {
41
- traceId: getTraceId()
42
- };
43
- return {
44
- traceId
45
- };
46
- },
47
- browser: {
48
- write: (o)=>{
49
- const { name, time, level, ...rest } = o;
50
- if (name) rest.message = rest.message ? `[${name}] ${rest.message}` : `[${name}]`;
51
- if (!rest.traceId) rest.traceId = getTraceId();
52
- if (level >= 50) console.error(rest);
53
- else if (level >= 40) console.warn(rest);
54
- else console.log(rest);
55
- }
56
- }
57
- };
58
- return config;
59
- }
60
- function createLogger() {
61
- const logger = pino({
62
- base: {
63
- pid: process.pid
64
- },
65
- messageKey: 'message',
66
- errorKey: 'error',
67
- timestamp: pino.stdTimeFunctions.epochTime,
68
- ...getPinoConfig()
69
- });
70
- return {
71
- logger
72
- };
73
- }
74
- export { createLogger };
@@ -1,82 +0,0 @@
1
- import pino from 'pino';
2
- import path from 'path';
3
-
4
- import { getTraceId } from '../trace';
5
-
6
- // https://github.com/pinojs/pino/blob/master/docs/api.md
7
- function getPinoConfig() {
8
- const targets: any = [];
9
-
10
- if (process.env.NODE_ENV === 'production') {
11
- } else {
12
- const rotate = `./rotate${path.extname(__filename)}`;
13
- targets.push({
14
- level: 'debug',
15
- target: rotate,
16
- options: { path: './logs/' },
17
- });
18
- targets.push({
19
- level: 'debug',
20
- target: 'pino-pretty', // must be installed separately,
21
- options: {
22
- // https://github.com/pinojs/pino-pretty?tab=readme-ov-file#options
23
- ignore: 'pid',
24
- messageKey: 'message',
25
- },
26
- });
27
- }
28
-
29
- const config: pino.LoggerOptions = {
30
- transport: { targets },
31
- mixin(data: any) {
32
- // {"level":30,"time":1726065716643,"pid":21968,"hostname":"Win-LH"}
33
- // 基础字段不能重复
34
- const traceId = data?.traceId;
35
- delete data.traceId;
36
- delete data.level;
37
- delete data.time;
38
- delete data.pid;
39
- delete data.name;
40
- delete data.hostname;
41
- if (!traceId) {
42
- return { traceId: getTraceId() };
43
- }
44
- return { traceId };
45
- },
46
- browser: {
47
- write: (o: any) => {
48
- // https://github.com/pinojs/pino/blob/main/docs/api.md#level-1
49
- const { name, time, level, ...rest } = o;
50
- if (name) {
51
- rest.message = rest.message ? `[${name}] ${rest.message}` : `[${name}]`;
52
- }
53
- if (!rest.traceId) {
54
- rest.traceId = getTraceId();
55
- }
56
- if (level >= 50) {
57
- console.error(rest);
58
- } else if (level >= 40) {
59
- console.warn(rest);
60
- } else {
61
- console.log(rest);
62
- }
63
- },
64
- },
65
- };
66
-
67
- return config;
68
- }
69
-
70
- export function createLogger() {
71
- const logger = pino({
72
- // https://github.com/pinojs/pino/blob/main/docs/api.md#opt-serializers
73
- base: { pid: process.pid },
74
- messageKey: 'message',
75
- errorKey: 'error',
76
- timestamp: pino.stdTimeFunctions.epochTime,
77
- // timestamp: process.env.NODE_ENV === 'production' ? pino.stdTimeFunctions.epochTime : pino.stdTimeFunctions.isoTime,
78
- ...getPinoConfig(),
79
- });
80
-
81
- return { logger };
82
- }