3 Star 5 Fork 3

三三物联网/ssiot-core

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
log.go 1.21 KB
一键复制 编辑 原始数据 按行查看 历史
三三物联网 提交于 2023-04-01 18:08 . 结构调整
// Package log provides debug logging
package log
import (
"encoding/json"
"fmt"
"time"
)
var (
// DefaultSize Default buffer size if any
DefaultSize = 256
// DefaultFormat Default formatter
DefaultFormat = TextFormat
)
// Log is debug log interface for reading and writing logs
type Log interface {
// Read reads log entries from the logger
Read(...ReadOption) ([]Record, error)
// Write writes records to log
Write(Record) error
// Stream log records
Stream() (Stream, error)
}
// Record is log record entry
type Record struct {
// Timestamp of logged event
Timestamp time.Time `json:"timestamp"`
// Metadata to enrich log record
Metadata map[string]string `json:"metadata"`
// Value contains log entry
Message interface{} `json:"message"`
}
// Stream returns a log stream
type Stream interface {
Chan() <-chan Record
Stop() error
}
// FormatFunc is a function which formats the output
type FormatFunc func(Record) string
// TextFormat returns text format
func TextFormat(r Record) string {
t := r.Timestamp.Format("2006-01-02 15:04:05")
return fmt.Sprintf("%s %v ", t, r.Message)
}
// JSONFormat is a json Format func
func JSONFormat(r Record) string {
b, _ := json.Marshal(r)
return string(b) + " "
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sansaniot/ssiot-core.git
git@gitee.com:sansaniot/ssiot-core.git
sansaniot
ssiot-core
ssiot-core
v1.8.22

搜索帮助