Open
Description
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?
Metadata
Metadata
Assignees
Labels
No labels