#log #aliyun #api-bindings #aliyuncs

aliyun-log-sdk

阿里云日志API实现

1个不稳定版本

0.0.1 2021年1月18日

#21 in #aliyun

MIT/Apache

18KB
400

aliyun-log-sdk

Rust版本

警告:此实现是实验性的,API 稳定。请谨慎使用。

示例用法

use aliyun_log_sdk::{Content, Log, LogProducer};

fn main() {
    // create a async runtime
    let rt = tokio::runtime::Runtime::new().unwrap();
    // create a new LogProducer instance
    let producer = LogProducer::new(
        env!("ACCESS_KEY"),
        env!("ACCESS_SECRET"),
        "cn-shenzhen.log.aliyuncs.com",
        "playground",
        "sdk-test",
    )
        .unwrap();

    // Create a vector of Log
    let mut records: Vec<Log> = Vec::new();
    // Create a new Log with default timestamp (now)
    let mut log: Log = Log::default();
    // Push K-V pairs to Log
    log.contents.push(Content::new("level", "INFO"));
    log.contents.push(Content::new("message", "startup"));
    // Add this log
    records.push(log);

    // Create LogGroup
    let log_group: LogGroup = LogGroup::new(records);
    // Send LogGroup to Aliyun
    let result = rt.block_on(producer.put_logs_lb(&log_group)).unwrap();
    let text = rt.block_on(result.text()).unwrap();
    println!("{}", text);
}

依赖项

~8–23MB
~313K SLoC