spring-boot-starter-log-aliyun

基于阿里云日志服务,aliyun-log-producer 封装的 spring-boot starter 组件支持

License

License

Categories

Categories

Spring Boot Container Microservices
GroupId

GroupId

me.weteam
ArtifactId

ArtifactId

spring-boot-starter-log-aliyun
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

pom
Description

Description

spring-boot-starter-log-aliyun
基于阿里云日志服务,aliyun-log-producer 封装的 spring-boot starter 组件支持
Project URL

Project URL

https://github.com/gumutianqi/spring-boot-starter-log-aliyun
Source Code Management

Source Code Management

https://github.com/gumutianqi/spring-boot-starter-log-aliyun.git

Download spring-boot-starter-log-aliyun

How to add to project

<!-- https://jarcasting.com/artifacts/me.weteam/spring-boot-starter-log-aliyun/ -->
<dependency>
    <groupId>me.weteam</groupId>
    <artifactId>spring-boot-starter-log-aliyun</artifactId>
    <version>1.0.1</version>
    <type>pom</type>
</dependency>
// https://jarcasting.com/artifacts/me.weteam/spring-boot-starter-log-aliyun/
implementation 'me.weteam:spring-boot-starter-log-aliyun:1.0.1'
// https://jarcasting.com/artifacts/me.weteam/spring-boot-starter-log-aliyun/
implementation ("me.weteam:spring-boot-starter-log-aliyun:1.0.1")
'me.weteam:spring-boot-starter-log-aliyun:pom:1.0.1'
<dependency org="me.weteam" name="spring-boot-starter-log-aliyun" rev="1.0.1">
  <artifact name="spring-boot-starter-log-aliyun" type="pom" />
</dependency>
@Grapes(
@Grab(group='me.weteam', module='spring-boot-starter-log-aliyun', version='1.0.1')
)
libraryDependencies += "me.weteam" % "spring-boot-starter-log-aliyun" % "1.0.1"
[me.weteam/spring-boot-starter-log-aliyun "1.0.1"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

  • spring-boot-starter-logging-aliyun

spring-boot-starter-log-aliyun

基于阿里云日志服务,aliyun-log-producer 封装的 spring-boot starter 组件支持

使用说明

参考:https://yq.aliyun.com/articles/682761

参考:https://github.com/aliyun/aliyun-log-java-producer

已经发布到 Maven 中央仓库,直接引用以下依赖

<dependency>
    <groupId>me.weteam</groupId>
    <artifactId>spring-boot-starter-logging-aliyun</artifactId>
    <version>1.0.1</version>
</dependency>

版本更新记录

2019-05-22 -> 1.0.1

新增plugin模块,后续陆续集成基于面向对象的插件化数据采集模式;

新增插件:基于 ThreadLocal 的 Event 采集;使用该插件,可以采集一个线程栈过程中的 Event 事件数据; ThreadLocal-event 插件文档:

2019-05-20 -> 1.0.0

第一个版本,集成 aliyun-log-producer,完成 spring-boot-starer 适配; 实现自动配置,开箱即用;具体参考下文的配置文档和使用文档;

配置说明

## Aliyun Log Hub
aliyun:
  loghub:
    enabled: true
    ## 参考阿里云 SDK 文档进行配置 Producer https://yq.aliyun.com/articles/682761
    producer:
      retries: 3
    ## 可以同时配置多个 aliyun log project
    projects:
      - project-name: <AliyunLog Project Name>
        endpoint: cn-hangzhou.log.aliyuncs.com
        access-key-id: <AccessKeyId>
        access-key-secret: <AccessKeySecret>
      - project-name: <AliyunLog Project Name>
        endpoint: cn-hangzhou.log.aliyuncs.com
        access-key-id: <AccessKeyId>
        access-key-secret: <AccessKeySecret>

使用说明

建议参考下面的代码进行使用; 新建一个 Class,作为日志采集的 IOC 工具

import me.weteam.loghub.AliyunLogHub;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 日志采集
 */
@Component
public class LogBot {

    @Autowired
    private AliyunLogHub aliyunLogHub;

    // 通过阿里云 SDK 可知,可以同时向多个 Log Project 发送日志;
    // 我们的建议是:在同一个 Log Project 下面创建多个 Log Store;

    private static final String REQUESTS_LOG_PROJECT = "api-log";
    private static final String REQUESTS_LOG_PROJECT_STORE = "api-request";

    private static final String EVENT_LOG_PROJECT = "api-log";
    private static final String EVENT_LOG_PROJECT_STORE = "api-event";

    /**
     * 发送一个 HTTP Requests 请求日志
     *
     * @param logMap
     */
    public void sendRequest(Map<String, String> logMap) {
        aliyunLogHub.send(REQUESTS_LOG_PROJECT, REQUESTS_LOG_PROJECT_STORE, logMap);
    }

    /**
     * 发送一个 Event 事件 打点日志
     *
     * @param logMap
     */
    public void sendEvent(Map<String, String> logMap) {
        aliyunLogHub.send(EVENT_LOG_PROJECT, EVENT_LOG_PROJECT_STORE, logMap);
    }
    
    //.... 可扩展为封装其他类型的日志
}

使用建议:

在项目的其他地方直接通过 IOC 注入 LogBot 进行日志采集即可; 为了规范采集日志内容格式,建议将以上 LogBot Class 中的日志采集内容 logMap 对象封装为强类型的 Java 业务对象;


如果其他建议,欢迎提供 Issues 和 pullRequest

Versions

Version
1.0.1
1.0.0