# log **Repository Path**: go-wares/log ## Basic Information - **Project Name**: log - **Description**: Compatible with open telemetry (without sdk) and open tracing. Logging support Elasticsearch、File、Kafka、Terminal and Trace support Jaeger、Zipkin - **Primary Language**: Go - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-03-27 - **Last Updated**: 2024-09-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: log, logging, opentracing, Go语言 ## README # Log 适配 OpenTracing 和 OpenTelemetry 的日志工具. ```go import "gitee.com/go-wares/log" func main() { // 等待完成. // 主协程退出前, 等待日志和调用链全部上报完成. defer log.Close() ... } ``` ## 1. 配置 本工具包首次加载时, 在项目的工作目录中查找 `config/log.yaml` 或 `config/log.yml` 或 `../config/log.yaml` 或 `../config/log.yml` 文件, 然后解析到 `go-wares/log.Config` 实例. ## 2. 日志 日志系统支持下列适配, 同时只能配置其中一项. - `term` - `sync` 在终端上打印日志. - `file` - `async` 日志写入到本地文件中. - `kafka` - `async` 发布日志到 `Kafka` 中间件. - `elasticsearch` - `async` 发布日志到 `Elasticsearch` 中间件. ### 2.1 简易用法 ```go log.Info("info message") log.Infof("info message with: %s", "formatter") // 兼容 OpenTracing / OpenTelemetry. ctx := log.NewContext() log.Infofc(ctx, "info message with: %s", "formatter and context") ``` ### 2.2 自定义字段 ```go log.Field{"key": "value"}.Info("info message with fields") ``` ### 2.3 调整格式化 ```go formatter := &MyFormatter{} log.Manager.GetLoggerAdapter().SetFormatter(formatter) ``` ## 3. 调用链 Trace reporter support follow adapters. - `jaeger` - publish span to jaeger - `zipkin` - publish span to zipkin ### 3.1 简易用法 ```go span := log.NewSpan("example") defer span.End() span.Info("info message") ```