在 Vue 3 中使用 log4js

Using log4js with Vue 3

提问人:betta7391 提问时间:9/28/2022 更新时间:9/28/2022 访问量:402

问:

我想将 log4js 添加到我的 Vue 项目中。

我用这段代码创建了一个文件logger.ts

import log4js from "log4js";

log4js.configure({
  appenders: { 
    app: { 
      type: "file", 
      filename: "./logs/app.log",
      compress: true,
      //pattern: '-yyyy-MM-dd',
      layout: {
        type: "pattern",
        pattern: "%d %p [%X{user}] %m%n",
      },
      daysToKeep: 14,
    } 
  },
  categories: { 
    default: { 
      appenders: ["app"], 
      level: "debug"
    } 
  },
});

export const logger = log4js.getLogger();

当我启动我的应用程序时,我的文件上有这个错误:node_modules/graceful-fs/polyfills.js

Uncaught ReferenceError: process is not defined
    at node_modules/graceful-fs/polyfills.js (polyfills.js:3:15)
    at __require2 (chunk-ASBRWZGP.js?v=44740571:15:50)
    at node_modules/graceful-fs/graceful-fs.js (graceful-fs.js:2:17)
    at __require2 (chunk-ASBRWZGP.js?v=44740571:15:50)
    at node_modules/fs-extra/lib/fs/index.js (index.js:5:12)
    at __require2 (chunk-ASBRWZGP.js?v=44740571:15:50)
    at node_modules/fs-extra/lib/index.js (index.js:6:3)
    at __require2 (chunk-ASBRWZGP.js?v=44740571:15:50)
    at node_modules/streamroller/lib/RollingFileWriteStream.js (RollingFileWriteStream.js:2:12)
    at __require2 (chunk-ASBRWZGP.js?v=44740571:15:50)

我该如何解决?

打字稿 vue.js 日志记录 log4js-node

评论

0赞 captainskippah 9/28/2022
process是在 Node 环境中找到的变量。我假设您的 Vue 3 代码在 Node 之外的浏览器上运行。可能是不支持在浏览器上使用库。

答: 暂无答案