Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: appenderModule.configure is not a function #1411

Open
Wrightlt opened this issue Jan 5, 2024 · 5 comments
Open

TypeError: appenderModule.configure is not a function #1411

Wrightlt opened this issue Jan 5, 2024 · 5 comments

Comments

@Wrightlt
Copy link

Wrightlt commented Jan 5, 2024

Node.js: v16.16.0 Nuxt: 2.15.8 log4js: 6.9.1

Hi.

I am triying to use log4js in Nuxt,it is work, but it's throwing an error: TypeError: appenderModule.configure is not a function.

this is my log4js.js:

// const log4js = require("log4js");
// import log4js from 'log4js';
import * as log4js from "log4js";

const config = {
    appenders: {
        info: {
            info: { type: "file", filename: "logs/info.log" },
        },
    },
    categories: {
        default: { appenders: ['debug', 'info', 'error'], level: 'info' },
    },
};
log4js.configure(config);

export default log4js;

I tried three different approaches:
Approach 1: const log4js = require("log4js");
Approach 2: import log4js from 'log4js';
Approach 3: import * as log4js from "log4js";
But all of them resulted in the above-mentioned error.

usage:

<template>
    <div>ttt6666888</div>
</template>

<script>
import log4js from './log4js';


export default {
    name: "IndexPage",
    asyncData() {

      const logger = log4js.getLogger('info');
      logger.info('info~~~');

        return {
          test: 111
        }
    }
}
</script>

error is:

TypeError: appenderModule.configure is not a function
    at eval (index.js:117:29)
    at Object.onlyOnMaster (clusteringBrowser.js:13:50)
    at createAppender (index.js:112:21)
    at getAppender (index.js:68:20)
    at eval (index.js:147:7)
    at Array.forEach (<anonymous>)
    at setup (index.js:139:33)
    at eval (configuration.js:51:35)
    at Array.forEach (<anonymous>)
    at Object.configure (configuration.js:51:13)

But when I directly use log4js in a component, it works and doesn't throw an error.
my component:

<template>
    <div>test11</div>
</template>

<script>
const log4js = require("log4js")

export default {
    name: "IndexPage",
    asyncData() {
        log4js.configure({
            appenders: {
                out: { type: "stdout" },
                app: { type: "file", filename: "logs/app.log" }
            },
            categories: {
                default: { appenders: ["out", "app"], level: "debug" }
            }
        })
        const logger = log4js.getLogger("cheese")

        logger.info("Cheese is Comté.")
        logger.error("Cheese is too ripe!")
    }
}
</script>
Do you have any solutions for this error?
@SokolovskyAlex
Copy link

hi! i have the same issue with log4js in Nuxt 3. Can anybody help with this?

@worker24h
Copy link

hi! i have the same issue with log4js in vue3 and electron.

import log4js from "log4js";

export default {
  install: (app, options) => {
    const logConfig = {
      appenders: {
        dateFileLog: {
          category: "log_date",
          type: "dateFile",
          filename: "./logs/log",
          alwaysIncludePattern: true,
          keepFileExt: true,
          pattern: "yyyy-MM-dd.log",
        },
        allFileLog: {
          type: "file",
          filename: "./logs/log.log",
          keepFileExt: true,
          maxLogSize: 1024 * 1024 * 100,
          backups: 3,
        },
      },
      categories: {
        default: { appenders: ["dateFileLog"], level: "info" },
        allFile: { appenders: ["allFileLog"], level: "debug" },
      },
    };
    log4js.configure(logConfig);
    app.config.globalProperties.$logger = log4js.getLogger();
  },
};

Error Message:

Uncaught TypeError: require$$1.inspect is not a function
    at createAppender (index-_dcK43Xt.js:7446:46)
    at getAppender (index-_dcK43Xt.js:7408:21)
    at index-_dcK43Xt.js:7477:7
    at Array.forEach (<anonymous>)
    at setup (index-_dcK43Xt.js:7475:33)
    at index-_dcK43Xt.js:6458:37
    at Array.forEach (<anonymous>)
    at Object.configure$9 [as configure] (index-_dcK43Xt.js:6458:15)
    at Object.configure (index-_dcK43Xt.js:8306:17)
    at Object.install (index-_dcK43Xt.js:8405:14)

@worker24h
Copy link

worker24h commented Mar 1, 2024

    const config = {
      appenders: {
        outfile: { type: 'file', filename: 'cheese.log' },
      },
      categories: {
        default: { appenders: ['outfile'], level: 'trace' },
      },
    }

The above configuration will cause an error, however the following configuration will not

    const config = {
      appenders: {
        console: { type: 'console' },
      },
      categories: {
        default: { appenders: ['console'], level: 'trace' },
      },
    }

@worker24h
Copy link

worker24h commented Mar 1, 2024

image

I debug code by vscode, I found cause.
image

@worker24h
Copy link

worker24h commented Mar 4, 2024

Downgrade version, <= v6.8.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants