UNPKG

@midwayjs/web

Version:

Midway Web Framework for Egg.js

71 lines 2.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const path = require("path"); const mkdirp = require("mkdirp"); const os = require("os"); const fs = require("fs"); const loggerModule = require("@midwayjs/logger"); const core_1 = require("@midwayjs/core"); exports.default = appInfo => { const exports = {}; exports.rundir = path.join(appInfo.appDir, 'run'); // 修改默认的日志名 exports.midwayLogger = (0, core_1.extend)(true, {}, loggerModule.loggers.getDefaultMidwayLoggerConfig(appInfo)['midwayLogger'], { clients: { appLogger: { fileLogName: 'midway-web.log', aliasName: 'logger', }, agentLogger: { fileLogName: 'midway-agent.log', }, }, }); exports.egg = { dumpConfig: true, contextLoggerFormat: info => { var _a, _b, _c; const ctx = info.ctx; // format: '[$userId/$ip/$traceId/$use_ms $method $url]' const userId = ctx.userId || '-'; const traceId = (_c = (_a = ctx.traceId) !== null && _a !== void 0 ? _a : (_b = ctx.tracer) === null || _b === void 0 ? void 0 : _b.traceId) !== null && _c !== void 0 ? _c : '-'; const use = Date.now() - ctx.startTime; const label = userId + '/' + ctx.ip + '/' + traceId + '/' + use + 'ms ' + ctx.method + ' ' + ctx.url; return `${info.timestamp} ${info.LEVEL} ${info.pid} [${label}] ${info.message}`; }, queryParseMode: 'extended', }; exports.pluginOverwrite = false; exports.security = { csrf: { ignoreJSON: false, }, }; // alinode runtime 写入的日志策略是: 如果 NODE_LOG_DIR 有设置,写入 NODE_LOG_DIR 设置的目录;否则为 /tmp let alinodeLogdir = fs.existsSync('/tmp') ? '/tmp' : os.tmpdir(); // try to use NODE_LOG_DIR first if (process.env.NODE_LOG_DIR) { alinodeLogdir = process.env.NODE_LOG_DIR; } mkdirp.sync(alinodeLogdir); exports.alinode = { logdir: alinodeLogdir, error_log: [ path.join(appInfo.root, `logs/${appInfo.pkg.name}/common-error.log`), path.join(appInfo.root, 'logs/stderr.log'), ], packages: [path.join(appInfo.appDir, 'package.json')], }; return exports; }; //# sourceMappingURL=config.default.js.map