-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Description
node version: 20.19.3
log4js version: 6.9.1
测试代码:
log.js
'use strict';
const log4js = require('log4js');
const path = require('path');
log4js.configure({
appenders: {
console: {
type: 'console',
},
info: {
type: 'dateFile',
filename: path.join(__dirname + '/logs/', 'test-info.log'), // 'log/fengshows-info.log',
pattern: 'yyyy-MM-dd',
layout: {
type: 'pattern',
pattern: '[%d{ISO8601}][%5p %z %c] %m',
},
compress: false,
},
maxInfo: {
type: 'logLevelFilter',
appender: 'info',
level: 'debug',
maxLevel: 'info',
},
},
categories: {
default: {
appenders: [
'console',
'maxInfo',
],
level: 'all',
},
},
});
const loggerCreator = function loggerCreator(name) {
return log4js.getLogger(name);
};
module.exports = loggerCreator;
moderation_sdk/index.js
const core = require('@huaweicloud/huaweicloud-sdk-core');
const moderation = require("@huaweicloud/huaweicloud-sdk-moderation");
module.exports = class ModerationClient {
constructor(opts) {
const credentials = new core.BasicCredentials()
.withAk(opts.ak)
.withSk(opts.sk)
.withProjectId(opts.project_id);
this.client = moderation.v3.ModerationClient.newBuilder()
.withCredential(credentials)
.withEndpoint(`https://moderation.${opts.region}.myhuaweicloud.com`)
.build();
}
async verifyText(text, eventType, categories) {
const request = new moderation.v3.RunTextModerationRequest();
const body = new moderation.v3.TextDetectionReq();
const databody = new moderation.v3.TextDetectionDataReq();
databody.withText(text);
body.withData(databody);
body.withEventType(eventType);
body.withCategories(categories);
request.withBody(body);
const result = await this.client.runTextModeration(request);
if(result.httpStatusCode != 200) throw new Error(`request error: ${result.httpStatusCode}`);
return result.result;
}
}
package.json
"dependencies": {
"@huaweicloud/huaweicloud-sdk-core": "^3.1.168",
"@huaweicloud/huaweicloud-sdk-moderation": "^3.1.168",
"log4js": "^6.9.1",
"uuid": "^13.0.0"
}
index.js
const logger = require('./log')('app');
const ModerationClient = require('./moderation_sdk');
async function main() {
logger.info('hello');
}
main();
此时输出的日志不会写入到 ./logs/test-info.log 文件当中。
const ModerationClient = require('./moderation_sdk');
const logger = require('./log')('app');
index.js 调换引用包的调换顺序之后,输出正常,日志正常写入到文件中。
Metadata
Metadata
Assignees
Labels
No labels