standard

package module
v1.7.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2021 License: MIT Imports: 0 Imported by: 6

README

服务化架构标准化

日志标准化

日志格式规范详见 日志格式规范说明

Documentation

Index

Constants

View Source
const DiscoverDefaultRegistry = "127.0.0.1:6379::15" // 默认注册中心配置
View Source
const DiscoverEnvApp = "DISCOVER_APP" // 应用名,注册为服务
View Source
const DiscoverEnvCalls = "DISCOVER_CALLS" // 被调用的应用定义,{"app1": "5000:token", "app2": "1000"},也可以使用 DISCOVER_CALLS_app1=timeout:token,token会通过 Access-Token 头进行传递
View Source
const DiscoverEnvRegistry = "DISCOVER_REGISTRY" // 注册中心地址,"127.0.0.1:6379:15"、"127.0.0.1:6379:15:password"
View Source
const DiscoverEnvWeight = "DISCOVER_WEIGHT" // 应用权重,默认值:100
View Source
const DiscoverHeaderClientAppName = "X-Client-App-Name" // 客户端App名字
View Source
const DiscoverHeaderClientAppVersion = "X-Client-App-Version" // 客户端App版本号
View Source
const DiscoverHeaderClientIp = "X-Real-IP" // 真实的用户IP
View Source
const DiscoverHeaderDeviceId = "X-Device-ID" // 设备唯一编号
View Source
const DiscoverHeaderForwardedFor = "X-Forwarded-For" // 客户端IP列表
View Source
const DiscoverHeaderFromApp = "X-From-App" // 来源App
View Source
const DiscoverHeaderFromNode = "X-From-Node" // 来源节点
View Source
const DiscoverHeaderHost = "X-Host" // 真实用户请求的Host
View Source
const DiscoverHeaderRequestId = "X-Request-ID" // 请求唯一编号
View Source
const DiscoverHeaderScheme = "X-Scheme" // 真实用户请求的 http or https
View Source
const DiscoverHeaderSessionId = "X-Session-ID" // 会话唯一编号
View Source
const DiscoverHeaderUserAgent = "X-User-Agent" // 真实用户的UserAgent
View Source
const DiscoverHeaderUserId = "X-User-ID" // 用户编号
View Source
const LogDefaultSensitive = "phone,password,secret,token,accessToken" // 默认脱敏字段
View Source
const LogEnvFile = "LOG_FILE" // 日志文件,默认输出到 stdout
View Source
const LogEnvLevel = "LOG_LEVEL" // 日志级别,debug、info、warning、error,默认值:info
View Source
const LogEnvRegexSensitive = "LOG_REGEXSENSITIVE" // 日志脱敏正则,无特殊情况不建议使用
View Source
const LogEnvSensitive = "LOG_SENSITIVE" // 日志脱敏字段,默认值:standard.LogDefaultSensitive
View Source
const LogTypeDb = "db" // 数据库操作
View Source
const LogTypeDbError = "dbError" // 数据库错误
View Source
const LogTypeDebug = "debug"
View Source
const LogTypeError = "error"
View Source
const LogTypeInfo = "info"
View Source
const LogTypeMonitor = "monitor" // 监控
View Source
const LogTypeRequest = "request" // 服务请求
View Source
const LogTypeServer = "server" // 服务信息
View Source
const LogTypeServerError = "serverError" // 服务错误
View Source
const LogTypeStatistic = "statistic" // 统计
View Source
const LogTypeTask = "task" // 任务
View Source
const LogTypeUndefined = "undefined" // 无法识别的
View Source
const LogTypeWarning = "warning"

Variables

Functions

This section is empty.

Types

type BaseLog added in v0.0.8

type BaseLog struct {
	LogName    string // 日志名称
	LogType    string // 日志类型
	LogTime    string // 日志时间,格式为 RFC3339Nano "2006-01-02T15:04:05.999999999Z07:00"
	TraceId    string // 跟踪ID,同一过程中的日志具有相同的traceId
	ImageName  string // docker镜像名字
	ImageTag   string // docker镜像Tag
	ServerName string // 服务主机(宿主机器)名称
	ServerIp   string // 服务主机(宿主机器)Ip地址
	Extra      map[string]interface{}
}

type DBErrorLog added in v0.0.8

type DBErrorLog struct {
	ErrorLog
	DBLog
}

type DBLog added in v0.0.8

type DBLog struct {
	BaseLog
	DbType    string  // 数据库类型,例如:mysql、oracle、redis...
	Dsn       string  // 连接信息
	Query     string  // 请求内容
	QueryArgs string  // 请求参数,会变化的部分应该记录在此
	UsedTime  float32 // 处理请求花费的时间,格式为float32,单位毫秒
}

type DebugLog added in v0.0.8

type DebugLog struct {
	BaseLog
	Debug      string   // 调试信息
	CallStacks []string // 调用堆栈
}

type ErrorLog added in v0.0.8

type ErrorLog struct {
	BaseLog
	Error      string   // 错误信息
	CallStacks []string // 调用堆栈
}

type InfoLog added in v0.0.8

type InfoLog struct {
	BaseLog
	Info string // 信息
}

type MonitorLog added in v0.0.9

type MonitorLog struct {
	BaseLog
	Name       string  // 监控项目
	Target     string  // 监控目标
	TargetInfo string  // 目标信息,例如:DNS、URL
	Expect     string  // 预期结果
	Result     string  // 实际结果
	Succeed    bool    // 是否成功
	UsedTime   float32 // 处理请求花费的时间,格式为float32,单位毫秒
	Memo       string  // 备注
}

type RequestLog added in v0.0.8

type RequestLog struct {
	BaseLog
	ServerId           string // 服务编号(用于跟踪哪一个服务)
	App                string // 应用名
	Node               string // 处理请求的节点,ip:port
	ClientIp           string // 真实的用户IP,通过 X-Real-IP 续传
	FromApp            string // 调用方应用
	FromNode           string // 调用方节点,格式 ip:port
	UserId             string // 客户唯一编号,通过 X-Client-ID 续传
	DeviceId           string
	ClientAppName      string
	ClientAppVersion   string
	SessionId          string                 // 会话唯一编号,通过 X-Session-ID 续传
	RequestId          string                 // 请求唯一编号,通过 X-Request-ID 续传
	Host               string                 // 真实用户请求的Host,通过 X-Host 续传
	Scheme             string                 // http scheme, http or https
	Proto              string                 // http proto, 1.1 or 2.0
	AuthLevel          int                    // 验证级别,用来校验用户是否有权限访问
	Priority           int                    // 优先级,用来在服务故障时进行自动降级处理
	Method             string                 // 请求的方法
	Path               string                 // 请求的路径,不包括GET参数部分,如果有PATH参数应该记录定义的PATH
	RequestHeaders     map[string]string      // 请求头,排除掉指定不需要信息后的所有头部内容,敏感数据应脱敏
	RequestData        map[string]interface{} // 请求的数据内容,JSON对象,集合类型仅记录少量内容,敏感数据应脱敏,非对象内容过大应做截取
	UsedTime           float32                // 处理请求花费的时间,格式为float32,单位毫秒
	ResponseCode       int                    // 应答代码,200 1000+ 正常应答,201~399,1~199  600~999 特殊应答,<1 异常应答
	ResponseHeaders    map[string]string      // 应答头,排除掉指定不需要信息后的所有头部内容,敏感数据应脱敏
	ResponseDataLength uint                   // 应答的数据长度
	ResponseData       string                 // 指定要记录的数据内容,JSON对象,集合类型仅记录少量内容,敏感数据应脱敏,非对象内容不进行记录
}

type ServerErrorLog added in v0.0.9

type ServerErrorLog struct {
	ErrorLog
	App       string // 运行什么应用
	Weight    int    // 服务的权重
	Node      string // 运行在哪个节点(ip:port)
	Proto     string // 工作协议,例如:http1.1、http2.0、h2c
	StartTime string // 日志时间,格式为 RFC3339Nano "2006-01-02T15:04:05.999999999Z07:00"
}

type ServerLog added in v0.0.9

type ServerLog struct {
	InfoLog
	App       string // 运行什么应用
	Weight    int    // 服务的权重
	Node      string // 运行在哪个节点(ip:port)
	Proto     string // 工作协议,例如:http1.1、http2.0、h2c
	StartTime string // 日志时间,格式为 RFC3339Nano "2006-01-02T15:04:05.999999999Z07:00"
}

type StatisticLog added in v0.0.8

type StatisticLog struct {
	BaseLog
	ServerId  string  // 服务编号(用于跟踪哪一个服务)
	App       string  // 运行什么应用
	Name      string  // 统计项目
	StartTime string  // 日志时间,格式为 RFC3339Nano "2006-01-02T15:04:05.999999999Z07:00"
	EndTime   string  // 日志时间,格式为 RFC3339Nano "2006-01-02T15:04:05.999999999Z07:00"
	Times     uint    // 总次数
	Failed    uint    // 失败次数
	Avg       float64 // 平均
	Min       float64 // 最小值
	Max       float64 // 最大值
}

type TaskLog added in v0.0.9

type TaskLog struct {
	BaseLog
	Name      string                 // 任务名称
	Args      map[string]interface{} // 任务参数
	Succeed   bool                   // 是否成功
	Node      string                 // 运行在哪个节点(ip:port)
	StartTime string                 // 日志时间,格式为 RFC3339Nano "2006-01-02T15:04:05.999999999Z07:00"
	UsedTime  float32                // 处理任务花费的时间,格式为float32,单位毫秒
	Memo      string                 // 备注
}

type WarningLog added in v0.0.8

type WarningLog struct {
	BaseLog
	Warning    string   // 警告信息
	CallStacks []string // 调用堆栈
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL