@lynker-desktop/electron-logs 0.0.2
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/README.md +40 -0
- package/common/index.d.ts +8 -0
- package/common/index.d.ts.map +1 -0
- package/esm/common/index.d.ts +8 -0
- package/esm/common/index.d.ts.map +1 -0
- package/esm/index.d.ts +2 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +5 -0
- package/esm/index.js.map +1 -0
- package/esm/main/index.d.ts +5 -0
- package/esm/main/index.d.ts.map +1 -0
- package/esm/main/index.js +110 -0
- package/esm/main/index.js.map +1 -0
- package/esm/package.json +1 -0
- package/esm/preload/index.js +40 -0
- package/esm/preload/index.js.map +1 -0
- package/esm/renderer/index.d.ts +13 -0
- package/esm/renderer/index.d.ts.map +1 -0
- package/esm/renderer/index.js +32 -0
- package/esm/renderer/index.js.map +1 -0
- package/index.d.ts +2 -0
- package/index.d.ts.map +1 -0
- package/index.js +5 -0
- package/index.js.map +1 -0
- package/main/index.d.ts +5 -0
- package/main/index.d.ts.map +1 -0
- package/main/index.js +112 -0
- package/main/index.js.map +1 -0
- package/package.json +78 -0
- package/preload/index.js +40 -0
- package/preload/index.js.map +1 -0
- package/renderer/index.d.ts +13 -0
- package/renderer/index.d.ts.map +1 -0
- package/renderer/index.js +33 -0
- package/renderer/index.js.map +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 hui.liu
|
|
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/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
Electron 应用的进程崩溃可能由多种原因引起,主要包括以下几个方面:
|
|
2
|
+
|
|
3
|
+
### 1. 内存问题
|
|
4
|
+
- **内存泄漏**:如果应用程序在运行过程中不断占用内存而不释放,最终可能导致内存耗尽,进而导致崩溃。
|
|
5
|
+
- **内存不足**:当系统可用内存不足时,操作系统可能会终止一些进程,包括 Electron 应用。
|
|
6
|
+
|
|
7
|
+
### 2. 未捕获的异常
|
|
8
|
+
- **JavaScript 异常**:未捕获的同步或异步 JavaScript 异常可能导致进程崩溃。例如,未处理的 Promise 拒绝或未捕获的错误。
|
|
9
|
+
- **渲染进程崩溃**:渲染进程中的脚本运行错误,未进行适当的错误处理,可能会导致崩溃。
|
|
10
|
+
|
|
11
|
+
### 3. 系统资源问题
|
|
12
|
+
- **CPU 资源不足**:高 CPU 使用率可能导致系统无法响应,进而导致进程崩溃。
|
|
13
|
+
- **磁盘空间不足**:如果应用需要写入文件但磁盘空间不足,也可能导致崩溃。
|
|
14
|
+
|
|
15
|
+
### 4. 外部库和插件问题
|
|
16
|
+
- **本地模块错误**:本地(Native)模块或插件中的错误,特别是 C++ 扩展模块,可能导致崩溃。
|
|
17
|
+
- **第三方库错误**:使用的第三方 JavaScript 库中存在错误,也可能导致应用崩溃。
|
|
18
|
+
|
|
19
|
+
### 5. 操作系统和硬件问题
|
|
20
|
+
- **操作系统更新**:操作系统更新或补丁可能导致与 Electron 不兼容的问题。
|
|
21
|
+
- **硬件故障**:如内存条故障、硬盘坏道等硬件问题也可能导致应用崩溃。
|
|
22
|
+
|
|
23
|
+
### 6. 代码逻辑问题
|
|
24
|
+
- **无限递归**:无限递归调用会导致堆栈溢出,进而崩溃。
|
|
25
|
+
- **死循环**:代码中的死循环可能导致应用无响应并最终崩溃。
|
|
26
|
+
|
|
27
|
+
### 7. 安全问题
|
|
28
|
+
- **恶意攻击**:恶意攻击可能通过各种方式导致应用崩溃,如缓冲区溢出、代码注入等。
|
|
29
|
+
- **安全漏洞**:应用中的安全漏洞被利用,导致崩溃。
|
|
30
|
+
|
|
31
|
+
### 8. 网络问题
|
|
32
|
+
- **网络请求失败**:频繁的网络请求失败或长时间等待网络响应,可能导致应用崩溃。
|
|
33
|
+
- **WebSocket 连接问题**:不正确的 WebSocket 处理可能导致崩溃。
|
|
34
|
+
|
|
35
|
+
### 9. 文件系统问题
|
|
36
|
+
- **文件权限**:缺少必要的文件读写权限可能导致应用崩溃。
|
|
37
|
+
- **文件损坏**:应用依赖的文件损坏或丢失,也可能导致崩溃。
|
|
38
|
+
|
|
39
|
+
### 10. Electron 内部问题
|
|
40
|
+
- **Electron 自身 Bug**:Electron 框架中的 Bug 或未预见的行为也可能导致崩溃。
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/common/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAC,MAAM,EAAC,MAAM,QAAQ,CAAA;AAClC,MAAM,MAAM,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAA;AAErD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,gBAAgB,CAAC,EAAE,GAAG,CAAC;KACxB;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAC,MAAM,EAAC,MAAM,QAAQ,CAAA;AAClC,MAAM,MAAM,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAA;AAErD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,gBAAgB,CAAC,EAAE,GAAG,CAAC;KACxB;CACF"}
|
package/esm/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,CAAC"}
|
package/esm/index.js
ADDED
package/esm/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["throw new Error(`electron 对主进程和渲染进程使用不同的代码: \n在electron主进程中, 你应该导入“@lynker-desktop/electron-logs/main” \n在electron渲染过程中, 你应该导入“@lynker-desktop/electron-logs/renderer”\n`);\n\nexport {};"],"names":[],"mappings":"AAAA,MAAM,IAAI,KAAK,CAAC,CAAA;;;AAGf,CAAA,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/main/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAO3B,eAAO,IAAI,aAAa,SAAQ,CAAC;AAEjC,eAAO,MAAM,UAAU,cAAc,MAAM,SAmG1C,CAAA;AACD,eAAe,MAAM,CAAA"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import log4js from 'log4js';
|
|
2
|
+
export { default } from 'log4js';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { app, ipcMain } from 'electron';
|
|
5
|
+
|
|
6
|
+
let LOG_PATH = path.join(app.getPath('logs'));
|
|
7
|
+
let isInitialized = false;
|
|
8
|
+
const initialize = (logsPath = LOG_PATH) => {
|
|
9
|
+
app.on('ready', () => {
|
|
10
|
+
});
|
|
11
|
+
try {
|
|
12
|
+
if (isInitialized) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
log4js.configure({
|
|
16
|
+
appenders: {
|
|
17
|
+
out: {
|
|
18
|
+
type: 'console'
|
|
19
|
+
},
|
|
20
|
+
alldateFileLog: {
|
|
21
|
+
type: 'dateFile',
|
|
22
|
+
filename: path.join(logsPath, 'log'),
|
|
23
|
+
pattern: 'yyyy-MM-dd.log', // 每天生成按这个格式拼接到filename后边
|
|
24
|
+
alwaysIncludePattern: true // 始终包含pattern
|
|
25
|
+
},
|
|
26
|
+
renderProccessLog: {
|
|
27
|
+
type: "dateFile",
|
|
28
|
+
filename: path.join(logsPath, 'renderer'),
|
|
29
|
+
pattern: "yyyy-MM-dd.log",
|
|
30
|
+
keepFileExt: true,
|
|
31
|
+
alwaysIncludePattern: true
|
|
32
|
+
},
|
|
33
|
+
mainProccessLog: {
|
|
34
|
+
type: 'dateFile',
|
|
35
|
+
filename: path.join(logsPath, 'main'),
|
|
36
|
+
pattern: 'yyyy-MM-dd.log', // 每天生成按这个格式拼接到filename后边
|
|
37
|
+
keepFileExt: true,
|
|
38
|
+
alwaysIncludePattern: true, // 始终包含pattern
|
|
39
|
+
// maxLogSize: 1024 * 1024 * 100, // 文件最大容纳值
|
|
40
|
+
// backups: 3
|
|
41
|
+
},
|
|
42
|
+
crashLog: {
|
|
43
|
+
type: 'dateFile',
|
|
44
|
+
filename: path.join(logsPath, 'crash'),
|
|
45
|
+
pattern: "yyyy-MM-dd.log",
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
// 不同等级的日志追加到不同的输出位置:appenders: ['out', 'allLog'] categories 作为getLogger方法的键名对应
|
|
49
|
+
categories: {
|
|
50
|
+
date: {
|
|
51
|
+
appenders: ['out', 'alldateFileLog'],
|
|
52
|
+
level: "debug"
|
|
53
|
+
},
|
|
54
|
+
main: {
|
|
55
|
+
appenders: ['out', 'mainProccessLog'],
|
|
56
|
+
level: "debug"
|
|
57
|
+
},
|
|
58
|
+
renderer: {
|
|
59
|
+
appenders: ['renderProccessLog'],
|
|
60
|
+
level: "debug"
|
|
61
|
+
},
|
|
62
|
+
crash: {
|
|
63
|
+
appenders: ['out', 'crashLog'],
|
|
64
|
+
level: "debug"
|
|
65
|
+
},
|
|
66
|
+
default: {
|
|
67
|
+
appenders: ['out', 'alldateFileLog'],
|
|
68
|
+
level: "debug"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
const main = log4js.getLogger('main');
|
|
73
|
+
const renderer = log4js.getLogger('renderer');
|
|
74
|
+
// @ts-ignore
|
|
75
|
+
global.console = console = main;
|
|
76
|
+
console.log(' ');
|
|
77
|
+
console.log('=================== electron-logs ===================');
|
|
78
|
+
console.log(' ');
|
|
79
|
+
console.log('init electron-logs: ', LOG_PATH);
|
|
80
|
+
console.log('');
|
|
81
|
+
console.log('=================== electron-logs ===================');
|
|
82
|
+
console.log(' ');
|
|
83
|
+
ipcMain.handle('__ELECTRON_LOGS_RENDERER__', (_, msg) => {
|
|
84
|
+
if (msg.type === 'log') {
|
|
85
|
+
try {
|
|
86
|
+
let level = `${msg?.level || 'log'}`?.replace(/^log$/gi, 'info');
|
|
87
|
+
const data = (msg?.data || []);
|
|
88
|
+
if (level in renderer) {
|
|
89
|
+
renderer.log(level, ...data);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
console.error(error);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (msg.type === 'getLogPath') {
|
|
97
|
+
return LOG_PATH;
|
|
98
|
+
}
|
|
99
|
+
return 'ok';
|
|
100
|
+
});
|
|
101
|
+
isInitialized = true;
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
console.error('assign console error: ', error);
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export { initialize, isInitialized };
|
|
110
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/main/index.ts"],"sourcesContent":["import log4js from 'log4js'\nimport path from 'path'\nimport { app, ipcMain } from 'electron'\nimport { Level } from '../common';\n\nlet LOG_PATH = path.join(app.getPath('logs'))\n\nexport let isInitialized = false;\n\nexport const initialize = (logsPath: string = LOG_PATH) => {\n app.on('ready', () => {\n\n })\n try {\n if (isInitialized) {\n return;\n }\n log4js.configure({\n appenders: {\n out: {\n type: 'console'\n },\n alldateFileLog: {\n type: 'dateFile',\n filename: path.join(logsPath, 'log'),\n pattern: 'yyyy-MM-dd.log', // 每天生成按这个格式拼接到filename后边\n alwaysIncludePattern: true // 始终包含pattern\n },\n renderProccessLog: {\n type: \"dateFile\",\n filename: path.join(logsPath, 'renderer'),\n pattern: \"yyyy-MM-dd.log\",\n keepFileExt: true,\n alwaysIncludePattern: true\n },\n mainProccessLog: {\n type: 'dateFile',\n filename: path.join(logsPath, 'main'),\n pattern: 'yyyy-MM-dd.log', // 每天生成按这个格式拼接到filename后边\n keepFileExt: true,\n alwaysIncludePattern: true, // 始终包含pattern\n // maxLogSize: 1024 * 1024 * 100, // 文件最大容纳值\n // backups: 3\n },\n crashLog: {\n type: 'dateFile',\n filename: path.join(logsPath, 'crash'),\n pattern: \"yyyy-MM-dd.log\",\n },\n },\n // 不同等级的日志追加到不同的输出位置:appenders: ['out', 'allLog'] categories 作为getLogger方法的键名对应\n categories: {\n date: {\n appenders: ['out', 'alldateFileLog'],\n level: \"debug\"\n },\n main: {\n appenders: ['out', 'mainProccessLog'],\n level: \"debug\"\n },\n renderer: {\n appenders: ['renderProccessLog'],\n level: \"debug\"\n },\n crash: {\n appenders: ['out', 'crashLog'],\n level: \"debug\"\n },\n default: {\n appenders: ['out', 'alldateFileLog'],\n level: \"debug\"\n }\n }\n });\n const main = log4js.getLogger('main');\n const renderer = log4js.getLogger('renderer');\n // @ts-ignore\n global.console = console = main;\n console.log(' ')\n console.log('=================== electron-logs ===================')\n console.log(' ')\n console.log('init electron-logs: ', LOG_PATH)\n console.log('')\n console.log('=================== electron-logs ===================')\n console.log(' ')\n\n ipcMain.handle('__ELECTRON_LOGS_RENDERER__', (_, msg: {type: 'log' | 'getLogPath', level: Level, data: Array<any>}) => {\n if (msg.type === 'log') {\n try {\n let level = `${msg?.level || 'log'}`?.replace(/^log$/gi, 'info')\n const data = (msg?.data || []);\n if (level in renderer) {\n renderer.log(level, ...data)\n }\n } catch (error) {\n console.error(error)\n }\n }\n if (msg.type === 'getLogPath') {\n return LOG_PATH;\n }\n return 'ok';\n })\n isInitialized = true;\n } catch (error) {\n console.error('assign console error: ', error)\n throw error\n }\n}\nexport default log4js\n"],"names":[],"mappings":";;;;;AAKA,IAAI,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAA;AAEtC,IAAI,aAAa,GAAG,MAAM;MAEpB,UAAU,GAAG,CAAC,QAAmB,GAAA,QAAQ,KAAI;AACtD,IAAA,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,MAAK;AAErB,KAAC,CAAC,CAAA;AACF,IAAA,IAAI;QACA,IAAI,aAAa,EAAE;YACf,OAAO;SACV;QACD,MAAM,CAAC,SAAS,CAAC;AACb,YAAA,SAAS,EAAE;AACP,gBAAA,GAAG,EAAE;AACD,oBAAA,IAAI,EAAE,SAAS;AAClB,iBAAA;AACD,gBAAA,cAAc,EAAE;AACZ,oBAAA,IAAI,EAAE,UAAU;oBAChB,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC;oBACpC,OAA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O,KAAK,EAAE;AACZ,oBAAA,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;iBACvB;aACF;AACD,YAAA,IAAI,GAAG,CAAC,IAAI,KAAK,YAAY,EAAE;AAC7B,gBAAA,OAAO,QAAQ,CAAC;aACjB;AACD,YAAA,OAAO,IAAI,CAAC;AAChB,SAAC,CAAC,CAAA;QACF,aAAa,GAAG,IAAI,CAAC;KACxB;IAAC,OAAO,KAAK,EAAE;AACZ,QAAA,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAA;AAC9C,QAAA,MAAM,KAAK,CAAA;KACd;AACL;;;;"}
|
package/esm/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type": "module"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ipcRenderer, contextBridge } from 'electron';
|
|
2
|
+
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
if (window.__ELECTRON_LOG__) {
|
|
5
|
+
// eslint-disable-next-line no-console
|
|
6
|
+
console.log('electron-logs Electron preload has already been run');
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
try {
|
|
10
|
+
const log = (level, ...logs) => {
|
|
11
|
+
ipcRenderer
|
|
12
|
+
.invoke('__ELECTRON_LOGS_RENDERER__', { type: 'log', level: level, data: logs })
|
|
13
|
+
// eslint-disable-next-line no-console
|
|
14
|
+
.catch((e) => console.error(new Error('electron-log isn\'t initialized in the main process. '
|
|
15
|
+
+ `Please call log.initialize() before. ${e.message}`)));
|
|
16
|
+
};
|
|
17
|
+
const getLogPath = async () => {
|
|
18
|
+
return await ipcRenderer.invoke('__ELECTRON_LOGS_RENDERER__', { type: 'getLogPath' });
|
|
19
|
+
};
|
|
20
|
+
const obj = {
|
|
21
|
+
log,
|
|
22
|
+
getLogPath
|
|
23
|
+
};
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
window.__ELECTRON_LOG__ = obj;
|
|
26
|
+
if (contextBridge) {
|
|
27
|
+
try {
|
|
28
|
+
// This will fail if contextIsolation is not enabled
|
|
29
|
+
contextBridge.exposeInMainWorld('__ELECTRON_LOG__', obj);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
// console.error(error)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
console.error(e);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/src/preload/index.ts"],"sourcesContent":["import { contextBridge, ipcRenderer } from 'electron';\nimport type { Level } from 'log4js';\n\n// @ts-ignore\nif (window.__ELECTRON_LOG__) {\n // eslint-disable-next-line no-console\n console.log('electron-logs Electron preload has already been run');\n} else {\n try {\n const log = (level: Level, ...logs: any[]) => {\n ipcRenderer\n .invoke('__ELECTRON_LOGS_RENDERER__', { type: 'log', level: level, data: logs })\n // eslint-disable-next-line no-console\n .catch((e) => console.error(new Error(\n 'electron-log isn\\'t initialized in the main process. '\n + `Please call log.initialize() before. ${e.message}`,\n )));\n }\n const getLogPath = async () => {\n return await ipcRenderer.invoke('__ELECTRON_LOGS_RENDERER__', { type: 'getLogPath' })\n }\n const obj = {\n log,\n getLogPath\n };\n // @ts-ignore\n window.__ELECTRON_LOG__ = obj;\n if (contextBridge) {\n try {\n // This will fail if contextIsolation is not enabled\n contextBridge.exposeInMainWorld('__ELECTRON_LOG__', obj);\n } catch (error) {\n // console.error(error)\n }\n }\n }\n catch (e) {\n console.error(e)\n }\n}\n"],"names":[],"mappings":";;AAGA;AACA,IAAI,MAAM,CAAC,gBAAgB,EAAE;;AAE3B,IAAA,OAAO,CAAC,GAAG,CAAC,qDAAqD,CAAC,CAAC;AACrE,CAAC;KAAM;AACL,IAAA,IAAI;QACF,MAAM,GAAG,GAAG,CAAC,KAAY,EAAE,GAAG,IAAW,KAAI;YAC3C,WAAW;AACR,iBAAA,MAAM,CAAC,4BAA4B,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;;AAE/E,iBAAA,KAAK,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CACnC,uDAAuD;AACrD,kBAAA,CAAA,qCAAA,EAAwC,CAAC,CAAC,OAAO,EAAE,CACtD,CAAC,CAAC,CAAC;AACR,SAAC,CAAA;AACD,QAAA,MAAM,UAAU,GAAG,YAAW;AAC5B,YAAA,OAAO,MAAM,WAAW,CAAC,MAAM,CAAC,4BAA4B,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAA;AACvF,SAAC,CAAA;AACD,QAAA,MAAM,GAAG,GAAG;YACV,GAAG;YACH,UAAU;SACX,CAAC;;AAEF,QAAA,MAAM,CAAC,gBAAgB,GAAG,GAAG,CAAC;QAC9B,IAAI,aAAa,EAAE;AACjB,YAAA,IAAI;;AAEF,gBAAA,aAAa,CAAC,iBAAiB,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAC;aAC1D;YAAC,OAAO,KAAK,EAAE;;aAEf;SACF;KACF;IACD,OAAO,CAAC,EAAE;AACR,QAAA,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;KACjB;AACH"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Level } from "../common";
|
|
2
|
+
/**
|
|
3
|
+
* 日志
|
|
4
|
+
* @param level
|
|
5
|
+
* @param logs
|
|
6
|
+
*/
|
|
7
|
+
export declare const log: (level: Level, ...logs: any[]) => void;
|
|
8
|
+
/**
|
|
9
|
+
* 获取日志目录
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export declare const getLogPath: () => Promise<string>;
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/renderer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AAEjC;;;;GAIG;AACH,eAAO,MAAM,GAAG,UAAW,KAAK,WAAW,GAAG,EAAE,SAS/C,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,UAAU,QAAa,OAAO,CAAC,MAAM,CAOjD,CAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 日志
|
|
3
|
+
* @param level
|
|
4
|
+
* @param logs
|
|
5
|
+
*/
|
|
6
|
+
const log = (level, ...logs) => {
|
|
7
|
+
try {
|
|
8
|
+
if (typeof console[level] === 'function') {
|
|
9
|
+
console[level](...logs);
|
|
10
|
+
}
|
|
11
|
+
window.__ELECTRON_LOG__?.log?.(level, ...logs);
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
console.error('__ELECTRON_LOG__', error);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* 获取日志目录
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
const getLogPath = async () => {
|
|
22
|
+
try {
|
|
23
|
+
return await window.__ELECTRON_LOG__?.getLogPath?.();
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
console.error('__ELECTRON_LOG__', error);
|
|
27
|
+
return '';
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { getLogPath, log };
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/renderer/index.ts"],"sourcesContent":["import { Level } from \"../common\"\n\n/**\n * 日志\n * @param level\n * @param logs\n */\nexport const log = (level: Level, ...logs: any[]) => {\n try {\n if (typeof console[level] === 'function') {\n console[level](...logs)\n }\n window.__ELECTRON_LOG__?.log?.(level, ...logs)\n } catch (error) {\n console.error('__ELECTRON_LOG__', error)\n }\n}\n\n/**\n * 获取日志目录\n * @returns\n */\nexport const getLogPath = async (): Promise<string> => {\n try {\n return await window.__ELECTRON_LOG__?.getLogPath?.()\n } catch (error) {\n console.error('__ELECTRON_LOG__', error)\n return '';\n }\n}\n"],"names":[],"mappings":"AAEA;;;;AAIG;AACU,MAAA,GAAG,GAAG,CAAC,KAAY,EAAE,GAAG,IAAW,KAAI;AAClD,IAAA,IAAI;QACF,IAAI,OAAO,OAAO,CAAC,KAAK,CAAC,KAAK,UAAU,EAAE;AACxC,YAAA,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,CAAA;SACxB;QACD,MAAM,CAAC,gBAAgB,EAAE,GAAG,GAAG,KAAK,EAAE,GAAG,IAAI,CAAC,CAAA;KAC/C;IAAC,OAAO,KAAK,EAAE;AACd,QAAA,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAA;KACzC;AACH,EAAC;AAED;;;AAGG;AACU,MAAA,UAAU,GAAG,YAA4B;AACpD,IAAA,IAAI;QACF,OAAO,MAAM,MAAM,CAAC,gBAAgB,EAAE,UAAU,IAAI,CAAA;KACrD;IAAC,OAAO,KAAK,EAAE;AACd,QAAA,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAA;AACxC,QAAA,OAAO,EAAE,CAAC;KACX;AACH;;;;"}
|
package/index.d.ts
ADDED
package/index.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,CAAC"}
|
package/index.js
ADDED
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["src/src/index.ts"],"sourcesContent":["throw new Error(`electron 对主进程和渲染进程使用不同的代码: \n在electron主进程中, 你应该导入“@lynker-desktop/electron-logs/main” \n在electron渲染过程中, 你应该导入“@lynker-desktop/electron-logs/renderer”\n`);\n\nexport {};"],"names":[],"mappings":"AAAA,MAAM,IAAI,KAAK,CAAC,CAAA;;;AAGf,CAAA,CAAC;;"}
|
package/main/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/main/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAO3B,eAAO,IAAI,aAAa,SAAQ,CAAC;AAEjC,eAAO,MAAM,UAAU,cAAc,MAAM,SAmG1C,CAAA;AACD,eAAe,MAAM,CAAA"}
|
package/main/index.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
|
|
3
|
+
const log4js = require('log4js');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const electron = require('electron');
|
|
6
|
+
|
|
7
|
+
let LOG_PATH = path.join(electron.app.getPath('logs'));
|
|
8
|
+
exports.isInitialized = false;
|
|
9
|
+
const initialize = (logsPath = LOG_PATH) => {
|
|
10
|
+
electron.app.on('ready', () => {
|
|
11
|
+
});
|
|
12
|
+
try {
|
|
13
|
+
if (exports.isInitialized) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
log4js.configure({
|
|
17
|
+
appenders: {
|
|
18
|
+
out: {
|
|
19
|
+
type: 'console'
|
|
20
|
+
},
|
|
21
|
+
alldateFileLog: {
|
|
22
|
+
type: 'dateFile',
|
|
23
|
+
filename: path.join(logsPath, 'log'),
|
|
24
|
+
pattern: 'yyyy-MM-dd.log', // 每天生成按这个格式拼接到filename后边
|
|
25
|
+
alwaysIncludePattern: true // 始终包含pattern
|
|
26
|
+
},
|
|
27
|
+
renderProccessLog: {
|
|
28
|
+
type: "dateFile",
|
|
29
|
+
filename: path.join(logsPath, 'renderer'),
|
|
30
|
+
pattern: "yyyy-MM-dd.log",
|
|
31
|
+
keepFileExt: true,
|
|
32
|
+
alwaysIncludePattern: true
|
|
33
|
+
},
|
|
34
|
+
mainProccessLog: {
|
|
35
|
+
type: 'dateFile',
|
|
36
|
+
filename: path.join(logsPath, 'main'),
|
|
37
|
+
pattern: 'yyyy-MM-dd.log', // 每天生成按这个格式拼接到filename后边
|
|
38
|
+
keepFileExt: true,
|
|
39
|
+
alwaysIncludePattern: true, // 始终包含pattern
|
|
40
|
+
// maxLogSize: 1024 * 1024 * 100, // 文件最大容纳值
|
|
41
|
+
// backups: 3
|
|
42
|
+
},
|
|
43
|
+
crashLog: {
|
|
44
|
+
type: 'dateFile',
|
|
45
|
+
filename: path.join(logsPath, 'crash'),
|
|
46
|
+
pattern: "yyyy-MM-dd.log",
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
// 不同等级的日志追加到不同的输出位置:appenders: ['out', 'allLog'] categories 作为getLogger方法的键名对应
|
|
50
|
+
categories: {
|
|
51
|
+
date: {
|
|
52
|
+
appenders: ['out', 'alldateFileLog'],
|
|
53
|
+
level: "debug"
|
|
54
|
+
},
|
|
55
|
+
main: {
|
|
56
|
+
appenders: ['out', 'mainProccessLog'],
|
|
57
|
+
level: "debug"
|
|
58
|
+
},
|
|
59
|
+
renderer: {
|
|
60
|
+
appenders: ['renderProccessLog'],
|
|
61
|
+
level: "debug"
|
|
62
|
+
},
|
|
63
|
+
crash: {
|
|
64
|
+
appenders: ['out', 'crashLog'],
|
|
65
|
+
level: "debug"
|
|
66
|
+
},
|
|
67
|
+
default: {
|
|
68
|
+
appenders: ['out', 'alldateFileLog'],
|
|
69
|
+
level: "debug"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
const main = log4js.getLogger('main');
|
|
74
|
+
const renderer = log4js.getLogger('renderer');
|
|
75
|
+
// @ts-ignore
|
|
76
|
+
global.console = console = main;
|
|
77
|
+
console.log(' ');
|
|
78
|
+
console.log('=================== electron-logs ===================');
|
|
79
|
+
console.log(' ');
|
|
80
|
+
console.log('init electron-logs: ', LOG_PATH);
|
|
81
|
+
console.log('');
|
|
82
|
+
console.log('=================== electron-logs ===================');
|
|
83
|
+
console.log(' ');
|
|
84
|
+
electron.ipcMain.handle('__ELECTRON_LOGS_RENDERER__', (_, msg) => {
|
|
85
|
+
if (msg.type === 'log') {
|
|
86
|
+
try {
|
|
87
|
+
let level = `${msg?.level || 'log'}`?.replace(/^log$/gi, 'info');
|
|
88
|
+
const data = (msg?.data || []);
|
|
89
|
+
if (level in renderer) {
|
|
90
|
+
renderer.log(level, ...data);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
console.error(error);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (msg.type === 'getLogPath') {
|
|
98
|
+
return LOG_PATH;
|
|
99
|
+
}
|
|
100
|
+
return 'ok';
|
|
101
|
+
});
|
|
102
|
+
exports.isInitialized = true;
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
console.error('assign console error: ', error);
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
exports.default = log4js;
|
|
111
|
+
exports.initialize = initialize;
|
|
112
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/src/main/index.ts"],"sourcesContent":["import log4js from 'log4js'\nimport path from 'path'\nimport { app, ipcMain } from 'electron'\nimport { Level } from '../common';\n\nlet LOG_PATH = path.join(app.getPath('logs'))\n\nexport let isInitialized = false;\n\nexport const initialize = (logsPath: string = LOG_PATH) => {\n app.on('ready', () => {\n\n })\n try {\n if (isInitialized) {\n return;\n }\n log4js.configure({\n appenders: {\n out: {\n type: 'console'\n },\n alldateFileLog: {\n type: 'dateFile',\n filename: path.join(logsPath, 'log'),\n pattern: 'yyyy-MM-dd.log', // 每天生成按这个格式拼接到filename后边\n alwaysIncludePattern: true // 始终包含pattern\n },\n renderProccessLog: {\n type: \"dateFile\",\n filename: path.join(logsPath, 'renderer'),\n pattern: \"yyyy-MM-dd.log\",\n keepFileExt: true,\n alwaysIncludePattern: true\n },\n mainProccessLog: {\n type: 'dateFile',\n filename: path.join(logsPath, 'main'),\n pattern: 'yyyy-MM-dd.log', // 每天生成按这个格式拼接到filename后边\n keepFileExt: true,\n alwaysIncludePattern: true, // 始终包含pattern\n // maxLogSize: 1024 * 1024 * 100, // 文件最大容纳值\n // backups: 3\n },\n crashLog: {\n type: 'dateFile',\n filename: path.join(logsPath, 'crash'),\n pattern: \"yyyy-MM-dd.log\",\n },\n },\n // 不同等级的日志追加到不同的输出位置:appenders: ['out', 'allLog'] categories 作为getLogger方法的键名对应\n categories: {\n date: {\n appenders: ['out', 'alldateFileLog'],\n level: \"debug\"\n },\n main: {\n appenders: ['out', 'mainProccessLog'],\n level: \"debug\"\n },\n renderer: {\n appenders: ['renderProccessLog'],\n level: \"debug\"\n },\n crash: {\n appenders: ['out', 'crashLog'],\n level: \"debug\"\n },\n default: {\n appenders: ['out', 'alldateFileLog'],\n level: \"debug\"\n }\n }\n });\n const main = log4js.getLogger('main');\n const renderer = log4js.getLogger('renderer');\n // @ts-ignore\n global.console = console = main;\n console.log(' ')\n console.log('=================== electron-logs ===================')\n console.log(' ')\n console.log('init electron-logs: ', LOG_PATH)\n console.log('')\n console.log('=================== electron-logs ===================')\n console.log(' ')\n\n ipcMain.handle('__ELECTRON_LOGS_RENDERER__', (_, msg: {type: 'log' | 'getLogPath', level: Level, data: Array<any>}) => {\n if (msg.type === 'log') {\n try {\n let level = `${msg?.level || 'log'}`?.replace(/^log$/gi, 'info')\n const data = (msg?.data || []);\n if (level in renderer) {\n renderer.log(level, ...data)\n }\n } catch (error) {\n console.error(error)\n }\n }\n if (msg.type === 'getLogPath') {\n return LOG_PATH;\n }\n return 'ok';\n })\n isInitialized = true;\n } catch (error) {\n console.error('assign console error: ', error)\n throw error\n }\n}\nexport default log4js\n"],"names":["app","isInitialized","ipcMain"],"mappings":";;;;;;AAKA,IAAI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CAAC,CAAA;AACpE,QAAA,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAEhBC,gBAAO,CAAC,MAAM,CAAC,4BAA4B,EAAE,CAAC,CAAC,EAAE,GAAiE,KAAI;AAClH,YAAA,IAAI,GAAG,CAAC,IAAI,KAAK,KAAK,EAAE;AACtB,gBAAA,IAAI;AACA,oBAAA,IAAI,KAAK,GAAG,CAAA,EAAG,GAAG,EAAE,KAAK,IAAI,KAAK,CAAE,CAAA,EAAE,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;oBAChE,MAAM,IAAI,IAAI,GAAG,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC;AAC/B,oBAAA,IAAI,KAAK,IAAI,QAAQ,EAAE;wBACnB,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,CAAA;qBAC/B;iBACJ;gBAAC,OAAO,KAAK,EAAE;AACZ,oBAAA,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;iBACvB;aACF;AACD,YAAA,IAAI,GAAG,CAAC,IAAI,KAAK,YAAY,EAAE;AAC7B,gBAAA,OAAO,QAAQ,CAAC;aACjB;AACD,YAAA,OAAO,IAAI,CAAC;AAChB,SAAC,CAAC,CAAA;QACFD,qBAAa,GAAG,IAAI,CAAC;KACxB;IAAC,OAAO,KAAK,EAAE;AACZ,QAAA,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAA;AAC9C,QAAA,MAAM,KAAK,CAAA;KACd;AACL;;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lynker-desktop/electron-logs",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "electron-logs",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"electron",
|
|
7
|
+
"browser",
|
|
8
|
+
"tab"
|
|
9
|
+
],
|
|
10
|
+
"types": "./index.d.ts",
|
|
11
|
+
"main": "./index.js",
|
|
12
|
+
"module": "./esm/main/index.js",
|
|
13
|
+
"browser": "./esm/renderer/index.js",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"node": {
|
|
17
|
+
"require": "./index.js",
|
|
18
|
+
"import": "./esm/main/index.js"
|
|
19
|
+
},
|
|
20
|
+
"default": "./esm/renderer/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./main": {
|
|
23
|
+
"require": "./main/index.js",
|
|
24
|
+
"import": "./esm/main/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./renderer": {
|
|
27
|
+
"require": "./renderer/index.js",
|
|
28
|
+
"import": "./esm/renderer/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./preload": {
|
|
31
|
+
"require": "./preload/index.js",
|
|
32
|
+
"import": "./esm/preload/index.js"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"author": "",
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": ""
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"npm:publish": "pnpm publish --access public",
|
|
43
|
+
"prepublishOnly": "npm run build",
|
|
44
|
+
"build": "rollup -c --bundleConfigAsCjs ",
|
|
45
|
+
"docs": "documentation build *.js -f html -o docs",
|
|
46
|
+
"dev": "concurrently \"npm run dev:renderer\" \"node ./scripts/dev.js\"",
|
|
47
|
+
"dev:renderer": "cd example/renderer && npm run dev",
|
|
48
|
+
"dev:main": "npm run build && electron --inspect=8888 example/main.js"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"log4js": "^6.9.1"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@babel/core": "^7.24.9",
|
|
55
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
56
|
+
"@rollup/plugin-commonjs": "^26.0.1",
|
|
57
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
58
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
59
|
+
"@rollup/plugin-replace": "^5.0.7",
|
|
60
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
61
|
+
"@types/lodash": "^4.17.7",
|
|
62
|
+
"classnames": "^2.2.6",
|
|
63
|
+
"concurrently": "^8.2.2",
|
|
64
|
+
"electron": "24.8.8",
|
|
65
|
+
"file-url": "^2.0.2",
|
|
66
|
+
"fs-extra": "^11.2.0",
|
|
67
|
+
"lodash.merge": "^4.6.2",
|
|
68
|
+
"react": "^16.8.6",
|
|
69
|
+
"react-dom": "^16.8.6",
|
|
70
|
+
"rimraf": "^6.0.1",
|
|
71
|
+
"rollup": "^4.18.1",
|
|
72
|
+
"rollup-obfuscator": "^4.1.1",
|
|
73
|
+
"rollup-plugin-multi-input": "^1.4.2",
|
|
74
|
+
"rollup-plugin-node-builtins": "^2.1.2",
|
|
75
|
+
"tslib": "^2.6.3",
|
|
76
|
+
"typescript": "^5.5.3"
|
|
77
|
+
}
|
|
78
|
+
}
|
package/preload/index.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const electron = require('electron');
|
|
2
|
+
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
if (window.__ELECTRON_LOG__) {
|
|
5
|
+
// eslint-disable-next-line no-console
|
|
6
|
+
console.log('electron-logs Electron preload has already been run');
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
try {
|
|
10
|
+
const log = (level, ...logs) => {
|
|
11
|
+
electron.ipcRenderer
|
|
12
|
+
.invoke('__ELECTRON_LOGS_RENDERER__', { type: 'log', level: level, data: logs })
|
|
13
|
+
// eslint-disable-next-line no-console
|
|
14
|
+
.catch((e) => console.error(new Error('electron-log isn\'t initialized in the main process. '
|
|
15
|
+
+ `Please call log.initialize() before. ${e.message}`)));
|
|
16
|
+
};
|
|
17
|
+
const getLogPath = async () => {
|
|
18
|
+
return await electron.ipcRenderer.invoke('__ELECTRON_LOGS_RENDERER__', { type: 'getLogPath' });
|
|
19
|
+
};
|
|
20
|
+
const obj = {
|
|
21
|
+
log,
|
|
22
|
+
getLogPath
|
|
23
|
+
};
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
window.__ELECTRON_LOG__ = obj;
|
|
26
|
+
if (electron.contextBridge) {
|
|
27
|
+
try {
|
|
28
|
+
// This will fail if contextIsolation is not enabled
|
|
29
|
+
electron.contextBridge.exposeInMainWorld('__ELECTRON_LOG__', obj);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
// console.error(error)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
console.error(e);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/src/preload/index.ts"],"sourcesContent":["import { contextBridge, ipcRenderer } from 'electron';\nimport type { Level } from 'log4js';\n\n// @ts-ignore\nif (window.__ELECTRON_LOG__) {\n // eslint-disable-next-line no-console\n console.log('electron-logs Electron preload has already been run');\n} else {\n try {\n const log = (level: Level, ...logs: any[]) => {\n ipcRenderer\n .invoke('__ELECTRON_LOGS_RENDERER__', { type: 'log', level: level, data: logs })\n // eslint-disable-next-line no-console\n .catch((e) => console.error(new Error(\n 'electron-log isn\\'t initialized in the main process. '\n + `Please call log.initialize() before. ${e.message}`,\n )));\n }\n const getLogPath = async () => {\n return await ipcRenderer.invoke('__ELECTRON_LOGS_RENDERER__', { type: 'getLogPath' })\n }\n const obj = {\n log,\n getLogPath\n };\n // @ts-ignore\n window.__ELECTRON_LOG__ = obj;\n if (contextBridge) {\n try {\n // This will fail if contextIsolation is not enabled\n contextBridge.exposeInMainWorld('__ELECTRON_LOG__', obj);\n } catch (error) {\n // console.error(error)\n }\n }\n }\n catch (e) {\n console.error(e)\n }\n}\n"],"names":["ipcRenderer","contextBridge"],"mappings":";;AAGA;AACA,IAAI,MAAM,CAAC,gBAAgB,EAAE;;AAE3B,IAAA,OAAO,CAAC,GAAG,CAAC,qDAAqD,CAAC,CAAC;AACrE,CAAC;KAAM;AACL,IAAA,IAAI;QACF,MAAM,GAAG,GAAG,CAAC,KAAY,EAAE,GAAG,IAAW,KAAI;YAC3CA,oBAAW;AACR,iBAAA,MAAM,CAAC,4BAA4B,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;;AAE/E,iBAAA,KAAK,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CACnC,uDAAuD;AACrD,kBAAA,CAAA,qCAAA,EAAwC,CAAC,CAAC,OAAO,EAAE,CACtD,CAAC,CAAC,CAAC;AACR,SAAC,CAAA;AACD,QAAA,MAAM,UAAU,GAAG,YAAW;AAC5B,YAAA,OAAO,MAAMA,oBAAW,CAAC,MAAM,CAAC,4BAA4B,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAA;AACvF,SAAC,CAAA;AACD,QAAA,MAAM,GAAG,GAAG;YACV,GAAG;YACH,UAAU;SACX,CAAC;;AAEF,QAAA,MAAM,CAAC,gBAAgB,GAAG,GAAG,CAAC;QAC9B,IAAIC,sBAAa,EAAE;AACjB,YAAA,IAAI;;AAEF,gBAAAA,sBAAa,CAAC,iBAAiB,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAC;aAC1D;YAAC,OAAO,KAAK,EAAE;;aAEf;SACF;KACF;IACD,OAAO,CAAC,EAAE;AACR,QAAA,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;KACjB;AACH;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Level } from "../common";
|
|
2
|
+
/**
|
|
3
|
+
* 日志
|
|
4
|
+
* @param level
|
|
5
|
+
* @param logs
|
|
6
|
+
*/
|
|
7
|
+
export declare const log: (level: Level, ...logs: any[]) => void;
|
|
8
|
+
/**
|
|
9
|
+
* 获取日志目录
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export declare const getLogPath: () => Promise<string>;
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/renderer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AAEjC;;;;GAIG;AACH,eAAO,MAAM,GAAG,UAAW,KAAK,WAAW,GAAG,EAAE,SAS/C,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,UAAU,QAAa,OAAO,CAAC,MAAM,CAOjD,CAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 日志
|
|
3
|
+
* @param level
|
|
4
|
+
* @param logs
|
|
5
|
+
*/
|
|
6
|
+
const log = (level, ...logs) => {
|
|
7
|
+
try {
|
|
8
|
+
if (typeof console[level] === 'function') {
|
|
9
|
+
console[level](...logs);
|
|
10
|
+
}
|
|
11
|
+
window.__ELECTRON_LOG__?.log?.(level, ...logs);
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
console.error('__ELECTRON_LOG__', error);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* 获取日志目录
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
const getLogPath = async () => {
|
|
22
|
+
try {
|
|
23
|
+
return await window.__ELECTRON_LOG__?.getLogPath?.();
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
console.error('__ELECTRON_LOG__', error);
|
|
27
|
+
return '';
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
exports.getLogPath = getLogPath;
|
|
32
|
+
exports.log = log;
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/src/renderer/index.ts"],"sourcesContent":["import { Level } from \"../common\"\n\n/**\n * 日志\n * @param level\n * @param logs\n */\nexport const log = (level: Level, ...logs: any[]) => {\n try {\n if (typeof console[level] === 'function') {\n console[level](...logs)\n }\n window.__ELECTRON_LOG__?.log?.(level, ...logs)\n } catch (error) {\n console.error('__ELECTRON_LOG__', error)\n }\n}\n\n/**\n * 获取日志目录\n * @returns\n */\nexport const getLogPath = async (): Promise<string> => {\n try {\n return await window.__ELECTRON_LOG__?.getLogPath?.()\n } catch (error) {\n console.error('__ELECTRON_LOG__', error)\n return '';\n }\n}\n"],"names":[],"mappings":"AAEA;;;;AAIG;AACU,MAAA,GAAG,GAAG,CAAC,KAAY,EAAE,GAAG,IAAW,KAAI;AAClD,IAAA,IAAI;QACF,IAAI,OAAO,OAAO,CAAC,KAAK,CAAC,KAAK,UAAU,EAAE;AACxC,YAAA,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,CAAA;SACxB;QACD,MAAM,CAAC,gBAAgB,EAAE,GAAG,GAAG,KAAK,EAAE,GAAG,IAAI,CAAC,CAAA;KAC/C;IAAC,OAAO,KAAK,EAAE;AACd,QAAA,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAA;KACzC;AACH,EAAC;AAED;;;AAGG;AACU,MAAA,UAAU,GAAG,YAA4B;AACpD,IAAA,IAAI;QACF,OAAO,MAAM,MAAM,CAAC,gBAAgB,EAAE,UAAU,IAAI,CAAA;KACrD;IAAC,OAAO,KAAK,EAAE;AACd,QAAA,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAA;AACxC,QAAA,OAAO,EAAE,CAAC;KACX;AACH;;;;;"}
|