TencentWSRD / connect-cas2

NodeJS implement of CAS(Central Authentication Service) client.
MIT License
107 stars 44 forks source link

怎样配置 log 输出 #1

Closed jiang-wei closed 7 years ago

jiang-wei commented 7 years ago

不配置 log 时,应该就是使用默认的 console 可是代码里用了 logger.access ,所对应的 console 缺没有 access 方法,会造成输出失败。 在使用时还要自己定义一个 console.access = console.log 先 请考虑修改

xiaoyuze88 commented 7 years ago

@allanfish 看下,这个应该要考虑兼容性

jiang-wei commented 7 years ago

另外代码里判断 logger 不是 function 时就用 console替换掉了 winston 的 logger 都是 objcet,该怎么使用呢?

jiang-wei commented 7 years ago

@allanfish 有头绪吗?

luckyufei commented 7 years ago

@jiang-wei 已经解决了 默认有支持.

如果使用winston. 建议在配置cas的时候传进来:

 logger: (req, type) => {
    switch (type) { // cas日志不用那么详细, 有问题后再打开
      case 'log':
      case 'debug':
      case 'info':
        return winston.info(...);
      case 'warn':
      case 'error':
       return winston.error(...);
      default:
        return winston.log(...);
    }
  },
jiang-wei commented 7 years ago

解决了

        logger: (req, type) => {
            switch(type) {
                case 'log':
                case 'debug':
                    return casLogger.debug.bind(casLogger);
                case 'access':
                case 'info':
                    return casLogger.info.bind(casLogger);
                case 'warn':
                case 'error':
                    return casLogger.error.bind(casLogger);
                default:
                    return casLogger.log.bind(casLogger);
            }
        },
    ....