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

egg-mongoose-logger在阿里云服务器中无法打印日志 #1

Open
pwstrick opened this issue Jun 1, 2021 · 0 comments
Open

egg-mongoose-logger在阿里云服务器中无法打印日志 #1

pwstrick opened this issue Jun 1, 2021 · 0 comments

Comments

@pwstrick
Copy link

pwstrick commented Jun 1, 2021

遇到了一个比较奇怪的问题,无法在阿里云服务器中打印查询语句,但在本地是可以打印下面的日志。

2021-06-01 15:14:00,495 INFO 89719 [egg-mongoose-logger] db.getCollection('user_account').find({"realName":"test"}, {})

config中的debug参数使用了默认的true,format函数用的也是默认的。

const assert = require('assert');
const mongoose = require('mongoose');
module.exports = app => {
  app.coreLogger.info('[egg-mongoose-logger] init');
  const config = app.config.mongooseLogger;
  assert(typeof config.debug === 'boolean', '[egg-mongoose-logger] debug is required on config');
  if (config.debug === true) {
    mongoose.set('debug', (collectionName, methodName, query, doc, options) => {
      const meta = { collectionName, methodName, query, doc, options };
      const formatter = config.formatter || defaultFormatter;
      app.logger.info('[egg-mongoose-logger]', formatter(meta));
    });
  }
};
// default format
function defaultFormatter(meta) {
  const query = JSON.stringify(meta.query);
  const options = JSON.stringify(meta.options || {});
  return `db.getCollection('${meta.collectionName}').${meta.methodName}(${query}, ${options})`;
}

相关环境信息

  • 操作系统:ubuntu
  • Node 版本:12.18
  • Egg 版本:2.29.4
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

1 participant