1.3.1 • Published 6 years ago

ali-loghub-sdk v1.3.1

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

ali-loghub-sdk

npm package

因日常工作原因,目前只支持部分功能,剩余功能之后会逐渐开放,有什么特殊需求的欢迎在Issues中提出!

aliyun 日志服务sdk库

开始使用

  • 安装
$ npm install ali-loghub-sdk --save

若出现无法下载等网络问题,请使用淘宝镜像下载

$ cnpm install ali-loghub-sdk --save
  • 初始化
const Loghub = require('ali-loghub-sdk');

const loghub = new Loghub({
  accessKeyId: "accessKeyId",
  secretAccessKey: "secretAccessKey",
  endpoint: "cn-hangzhou.log.aliyuncs.com",
  projectName: "projectName"
});
  • 获取 logstore
loghub.getLogStores((err, info) => {
   if(err) {
     console.log(err);
   } else {
     console.log(info);
   }
 });
  • 消费日志
/**
 * logStoreName: logstore 名称
 * shard: 从listShards接口获取的值,指定shard
 * count: 返回的 loggroup 数目,范围为 0~1000
 * cursor: 游标,用以表示从什么位置开始读取数据,相当于起点
 */
loghub.pullLogs({
  logStoreName: 'logStoreName',
  shard: '107',
  count: '100',
  cursor: 'cursor'
}, (err, info) => {
  if(err) {
    console.log('err: ', err);
  } else {
    console.log('info: ', info);
  }
});
  • 获取游标 cursor
/**
 * logStoreName: logstore 名称
 * shard: 从listShards接口获取的值,指定shard
 * from: 时间戳,秒,查询的时间点
 */
loghub.getCursor({
  logStoreName: 'logstorename',
  shard: '114',
  from: '1513952882'
}, (err, info) => {
  if(err) {
    console.log('err: ', err);
  } else {
    console.log('info: ', info);
  }
});
  • 获取logstore下所有可用的shard
/**
 * logstorename: logstore 名称
 */
loghub.listShards(logstorename, (err, info) => {
  if(err) {
    console.log('err: ', err);
  } else {
    console.log('info: ', info);
  }
});
  • 按需查找日志
loghub.getLogs({
  logstorename: 'logstorename',
  from: 1513751400,
  to: 1513751500
}, (err, info) => {
  if(err) {
    console.log('err: ', err);
  } else {
    console.log('info: ', info);
  }
});

查询参数列表

名称类型是否必选描述
logstorenamestring查询的logstore名称
topicstring查询日志主题
fromint查询开始时间点(精度为秒,从 1970-1-1 00:00:00 UTC 计算起的秒数)
toint查询结束时间点(精度为秒,从 1970-1-1 00:00:00 UTC 计算起的秒数)
querystring查询表达式查询表达式
lineint请求返回的最大日志条数。取值范围为 0~100,默认值为 100
offsetint请求返回日志的起始点。取值范围为 0 或正整数,默认值为 0
reversebool是否按日志时间戳逆序返回日志。true 表示逆序,false 表示顺序,默认值为 false
1.3.1

6 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago