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,
logger.log({
level: 'info',
message: `${JSON.stringify({msg,
});
}
};
参考资料
https://cube.dev/docs/configuration/extending-cubejs
https://github.com/winstonjs/winston#formats