gpt4 book ai didi

electron - 从打包的asar应用程序 Electron 访问extraFiles Electron 生成器

转载 作者:行者123 更新时间:2023-12-03 12:32:04 31 4
gpt4 key购买 nike

我有一个 Electron 应用程序,该应用程序可以完美运行到开发环境中,并且日志引擎可以写入文件(使用winston.js)。
该项目的结构是这样的:
enter image description here
当我运行 Electron 构建器来打包我的应用程序时,我有以下结构:
enter image description here

  • 我的app.asar文件进入Resources目录
  • 我的日志文件已放入数据/日志

  • 在开发环境中,我使用以下winston config访问日志文件:
    new winston.transports.File({filename: 'data/logs/error.log', level: 'error'})
    但是这个特定的路径配置只能在开发模式下运行。而且,我找不到在产品环境中定位日志文件的好方法。
    我需要在产品环境中使用哪种路径将文件定向到Resources目录(或Contents目录已安装应用程序的根目录)之外?
    使用 Electron 应用程序管理日志的最佳方法是什么?

    最佳答案

    electron-builder docs中所述,要在打包的应用程序中获取资源和extraFiles路径,可以使用 process.resourcesPath

    const getResourcesPath = () => {
    return process.resourcesPath;
    };

    const getExtraFilesPath = () => {
    return path.join(process.resourcesPath, '..'); // go up one directory
    };
    对于日志,Electron为此提供了一个路径,您可以使用 app.getPath 进行检查
    app.getPath('logs');
    默认情况下,在macOS上为 ~/Library/Logs/YourAppName,在Linux和Windows上为 userData目录
    您可以根据需要使用 app.setAppLogsPath 更改此默认路径。
    大多数Electron应用程序将日志存储在默认位置

    关于electron - 从打包的asar应用程序 Electron 访问extraFiles Electron 生成器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66444014/

    31 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com