@zhin.js/process-monitor 0.0.42 → 0.0.44

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.
Files changed (2) hide show
  1. package/package.json +4 -4
  2. package/src/index.ts +9 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhin.js/process-monitor",
3
- "version": "0.0.42",
3
+ "version": "0.0.44",
4
4
  "description": "进程监控与重启通知插件",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -39,14 +39,14 @@
39
39
  "directory": "plugins/features/process-monitor"
40
40
  },
41
41
  "dependencies": {
42
- "zhin.js": "1.0.80"
42
+ "zhin.js": "1.0.82"
43
43
  },
44
44
  "devDependencies": {
45
- "@types/node": "^25.7.0",
45
+ "@types/node": "^25.8.0",
46
46
  "typescript": "^6.0.3"
47
47
  },
48
48
  "peerDependencies": {
49
- "zhin.js": "1.0.80"
49
+ "zhin.js": "1.0.82"
50
50
  },
51
51
  "scripts": {
52
52
  "build": "tsc",
package/src/index.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * 进程监控与重启通知插件
5
5
  */
6
- import { usePlugin } from 'zhin.js';
6
+ import { formatCompact, usePlugin } from 'zhin.js';
7
7
  import os from 'os';
8
8
  import fs from 'fs';
9
9
  import path from 'path';
@@ -39,7 +39,7 @@ const config: Config = {
39
39
  };
40
40
 
41
41
  if (!config.enabled) {
42
- logger.info('进程监控已禁用');
42
+ logger.info(formatCompact( { op: 'load', enabled: false }));
43
43
  }
44
44
 
45
45
  // ─── 状态管理 ────────────────────────────────────────────────────────────────
@@ -69,7 +69,7 @@ function loadProcessState() {
69
69
  processState = JSON.parse(data);
70
70
  }
71
71
  } catch (error) {
72
- logger.warn('加载进程状态失败:', error);
72
+ logger.warn(formatCompact( { op: 'load_state', ok: false, error: String(error) }));
73
73
  }
74
74
  }
75
75
 
@@ -78,7 +78,7 @@ function saveProcessState() {
78
78
  fs.mkdirSync(path.dirname(STATE_FILE), { recursive: true });
79
79
  fs.writeFileSync(STATE_FILE, JSON.stringify(processState, null, 2));
80
80
  } catch (error) {
81
- logger.warn('保存进程状态失败:', error);
81
+ logger.warn(formatCompact( { op: 'save_state', ok: false, error: String(error) }));
82
82
  }
83
83
  }
84
84
 
@@ -96,17 +96,17 @@ async function detectStartupReason() {
96
96
  if (timeSinceLastStart < 5 * 60 * 1000) {
97
97
  reason = 'crash';
98
98
  processState.crashCount++;
99
- logger.warn(`检测到异常重启(距上次启动 ${Math.floor(timeSinceLastStart / 1000)}s)`);
99
+ logger.warn(formatCompact( { op: 'restart', abnormal: true, since_last_s: Math.floor(timeSinceLastStart / 1000) }));
100
100
  } else {
101
101
  reason = 'restart';
102
102
  processState.restartCount++;
103
- logger.info('检测到正常重启');
103
+ logger.info(formatCompact( { op: 'restart', abnormal: false }));
104
104
  }
105
105
 
106
106
  uptime = timeSinceLastStart;
107
107
  processState.totalUptime += uptime;
108
108
  } else {
109
- logger.info('首次启动');
109
+ logger.info(formatCompact({ first: true }));
110
110
  }
111
111
 
112
112
  processState.lastPid = currentPid;
@@ -205,12 +205,12 @@ if (config.enabled) {
205
205
  detectStartupReason();
206
206
 
207
207
  process.on('SIGTERM', () => {
208
- logger.info('收到 SIGTERM 信号');
208
+ logger.info(formatCompact( { op: 'shutdown', signal: 'SIGTERM' }));
209
209
  saveProcessState();
210
210
  });
211
211
 
212
212
  process.on('SIGINT', () => {
213
- logger.info('收到 SIGINT 信号');
213
+ logger.info(formatCompact( { op: 'shutdown', signal: 'SIGINT' }));
214
214
  saveProcessState();
215
215
  });
216
216
  }