zoukankan      html  css  js  c++  java
  • cube.js 自定义日志处理

    cube.js 的日志处理部分是可以扩展的,

    参考机制

    const winston = require('winston');
    const { loggly } = require('winston-loggly-bulk');
     
    winston.add(
      new loggly({
        token: 'LOGGLY-TOKEN',
        subdomain: 'your-subdomain',
        tags: ['winston-nodejs'],
        json: true,
      })
    );
     
    module.exports = {
      logger: (msg, params) => {
        console.log(`${msg}: ${json.stringify(params)}`);
        winston.log("info",`${msg}----${JSON.stringify(params)}`)
      },
    };

    集成graylog

     // Cube.js configuration options: https://cube.dev/docs/config
    const WinstonGraylog2 = require('winston-graylog2');
    const { createLogger, format, transports } = require('winston');
    const { combine, timestamp, label, printf } = format;
     
    const myFormat = printf(({ level, message, label, timestamp }) => {
      return `${timestamp} [${label}] ${level}: ${message}`;
    });
     
    const options = {
      name: 'Graylog',
      level: 'debug',
      silent: false,
      handleExceptions: false,
      graylog: {
        servers: [{host: '<host>', port:<port>}],
        hostname: '<servicehostname>',
        facility: 'oneservice',
        bufferSize: 140000
      },
      staticMeta: {env: 'staging'}
    }
    var logger = createLogger({
      format: combine(
        label({ label: 'right meow!' }),
        timestamp(),
        myFormat
      ),
      transports: [
        new WinstonGraylog2(options)  ],
    });
     
     
    module.exports = {
      logger:(msg, params)=>{
        console.log(`${JSON.stringify({msg,...params})}`)
        logger.log({
          level: 'info',
          message: `${JSON.stringify({msg,...params})}`
        });
      }
    };

    参考资料

    https://cube.dev/docs/configuration/extending-cubejs
    https://github.com/winstonjs/winston#formats

  • 相关阅读:
    GNU安装
    camera链接
    右键terminal
    Angular cli 常见问题
    Angular路由复用策略RouteReuseStrategy
    angular5 websocket 服务
    promise 极简版封装
    js a 标签 通过download 实现下载功能
    angular6 升级到 angular7+ 最新Ng-zorro
    最新IDEA永久激活
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/14706567.html
Copyright © 2011-2022 走看看