tealogs

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2019 License: MIT Imports: 31 Imported by: 3

Documentation

Index

Constants

View Source
const (
	AccessLogFieldHeader     = 1
	AccessLogFieldSentHeader = 2
	AccessLogFieldArg        = 3
	AccessLogFieldCookie     = 4
	AccessLogFieldExtend     = 5
	AccessLogFieldReferer    = 6
	AccessLogFieldUserAgent  = 7
)
View Source
const (
	QueryDurationYearly   = "yearly"
	QueryDurationMonthly  = "monthly"
	QueryDurationDaily    = "daily"
	QueryDurationHourly   = "hourly"
	QueryDurationMinutely = "minutely"
	QueryDurationSecondly = "secondly"
)
View Source
const (
	QueryActionCount   = "count"
	QueryActionSum     = "sum"
	QueryActionAvg     = "avg"
	QueryActionMin     = "min"
	QueryActionMax     = "max"
	QueryActionFind    = "find"
	QueryActionFindAll = "findAll"
)

Variables

View Source
var AccessLogFields = []maps.Map{
	{
		"code": AccessLogFieldHeader,
		"name": "请求Header列表",
	},
	{
		"code": AccessLogFieldSentHeader,
		"name": "响应Header列表",
	},
	{
		"code": AccessLogFieldArg,
		"name": "参数列表",
	},
	{
		"code": AccessLogFieldCookie,
		"name": "Cookie列表",
	},
	{
		"code": AccessLogFieldExtend,
		"name": "位置和浏览器分析",
	},
	{
		"code": AccessLogFieldReferer,
		"name": "请求来源",
	},
	{
		"code": AccessLogFieldUserAgent,
		"name": "终端信息",
	},
}

Functions

func AddAccessLogHook

func AddAccessLogHook(hook *AccessLogHook)

添加Hook

func CallAccessLogHooks

func CallAccessLogHooks(accessLog *AccessLog)

执行Filter

Types

type AccessLog

type AccessLog struct {
	Id primitive.ObjectID `var:"id" bson:"_id" json:"id"` // 数据库存储的ID

	ServerId   string `var:"serverId" bson:"serverId" json:"serverId"`       // 服务ID
	BackendId  string `var:"backendId" bson:"backendId" json:"backendId"`    // 后端服务ID
	LocationId string `var:"locationId" bson:"locationId" json:"locationId"` // 路径配置ID
	FastcgiId  string `var:"fastcgiId" bson:"fastcgiId" json:"fastcgiId"`    // Fastcgi配置ID
	RewriteId  string `var:"rewriteId" bson:"rewriteId" json:"rewriteId"`    // 重写规则ID

	TeaVersion      string  `var:"teaVersion" bson:"teaVersion" json:"teaVersion"`                // TeaWeb版本
	RemoteAddr      string  `var:"remoteAddr" bson:"remoteAddr" json:"remoteAddr"`                // 终端地址,通常是:ip:port
	RemotePort      int     `var:"remotePort" bson:"remotePort" json:"remotePort"`                // 终端端口
	RemoteUser      string  `var:"remoteUser" bson:"remoteUser" json:"remoteUser"`                // 终端用户,基于BasicAuth认证
	RequestURI      string  `var:"requestURI" bson:"requestURI" json:"requestURI"`                // 请求URI
	RequestPath     string  `var:"requestPath" bson:"requestPath" json:"requestPath"`             // 请求URI中的路径
	APIPath         string  `var:"apiPath" bson:"apiPath" json:"apiPath"`                         // API路径
	APIStatus       string  `var:"apiStatus" bson:"apiStatus" json:"apiStatus"`                   // API状态码
	RequestLength   int64   `var:"requestLength" bson:"requestLength" json:"requestLength"`       // 请求内容长度
	RequestTime     float64 `var:"requestTime" bson:"requestTime" json:"requestTime"`             // 从请求到所有响应数据发送到请求端所花时间,单位为带有小数点的秒,精确到纳秒,比如:0.000260081
	RequestMethod   string  `var:"requestMethod" bson:"requestMethod" json:"requestMethod"`       // 请求方法
	RequestFilename string  `var:"requestFilename" bson:"requestFilename" json:"requestFilename"` // 请求的文件名,包含完整的路径
	Scheme          string  `var:"scheme" bson:"scheme" json:"scheme"`                            // 请求协议,http或者https
	Proto           string  `var:"proto" bson:"proto" json:"proto"`                               // 请求协议,比如HTTP/1.0, HTTP/1.1

	BytesSent     int64               `var:"bytesSent" bson:"bytesSent" json:"bytesSent"`             // 响应的字节数,目前同 bodyBytesSent
	BodyBytesSent int64               `var:"bodyBytesSent" bson:"bodyBytesSent" json:"bodyBytesSent"` // 响应的字节数
	Status        int                 `var:"status" bson:"status" json:"status"`                      // 响应的状态码
	StatusMessage string              `var:"statusMessage" bson:"statusMessage" json:"statusMessage"` // 响应的信息
	SentHeader    map[string][]string `var:"sentHeader" bson:"sentHeader" json:"sentHeader"`          // 响应的头信息

	TimeISO8601    string              `var:"timeISO8601" bson:"timeISO8601" json:"timeISO8601"`          // ISO 8601格式的本地时间,比如 2018-07-16T23:52:24.839+08:00
	TimeLocal      string              `var:"timeLocal" bson:"timeLocal" json:"timeLocal"`                // 本地时间,比如 17/Jul/2018:09:52:24 +0800
	Msec           float64             `var:"msec" bson:"msec" json:"msec"`                               // 带有毫秒的时间,比如 1531756823.054
	Timestamp      int64               `var:"timestamp" bson:"timestamp" json:"timestamp"`                // unix时间戳,单位为秒
	Host           string              `var:"host" bson:"host" json:"host"`                               // 主机名
	Referer        string              `var:"referer" bson:"referer" json:"referer"`                      // 请求来源URL
	UserAgent      string              `var:"userAgent" bson:"userAgent" json:"userAgent"`                // 客户端信息
	Request        string              `var:"request" bson:"request" json:"request"`                      // 请求的简要说明,格式类似于 GET /hello/world HTTP/1.1
	ContentType    string              `var:"contentType" bson:"contentType" json:"contentType"`          // 请求头部的Content-Type
	Cookie         map[string]string   `bson:"cookie" json:"cookie"`                                      // Cookie cookie.name, cookie.sid
	Arg            map[string][]string `bson:"arg" json:"arg"`                                            // arg_name, arg_id
	Args           string              `var:"args" bson:"args" json:"args"`                               // name=liu&age=20
	QueryString    string              `var:"queryString" bson:"queryString" json:"queryString"`          // 同 Args
	Header         map[string][]string `bson:"header" json:"header"`                                      // 请求的头部信息,支持header_*和http_*,header_content_type, header_expires, http_content_type, http_user_agent
	ServerName     string              `var:"serverName" bson:"serverName" json:"serverName"`             // 接收请求的服务器名
	ServerPort     int                 `var:"serverPort" bson:"serverPort" json:"serverPort"`             // 服务器端口
	ServerProtocol string              `var:"serverProtocol" bson:"serverProtocol" json:"serverProtocol"` // 服务器协议,类似于HTTP/1.0”

	// 代理相关
	BackendAddress string `var:"backendAddress" bson:"backendAddress" json:"backendAddress"` // 代理的后端的地址
	FastcgiAddress string `var:"fastcgiAddress" bson:"fastcgiAddress" json:"fastcgiAddress"` // Fastcgi后端地址

	// 调试用
	RequestData        []byte `var:"" bson:"requestData" json:"requestData"`               // 请求数据
	ResponseHeaderData []byte `var:"" bson:"responseHeaderData" json:"responseHeaderData"` // 响应Header数据
	ResponseBodyData   []byte `var:"" bson:"responseBodyData" json:"responseBodyData"`     // 响应Body数据

	// 错误信息
	Errors    []string `var:"errors" bson:"errors" json:"errors"`          // 错误信息
	HasErrors bool     `var:"hasErrors" bson:"hasErrors" json:"hasErrors"` // 是否包含有错误信息

	// 扩展
	Extend *AccessLogExtend `bson:"extend" json:"extend"`
	Attrs  map[string]string
	// contains filtered or unexported fields
}

func NewAccessLog added in v0.1.2

func NewAccessLog() *AccessLog

获取新对象

func (*AccessLog) CleanFields added in v0.1.2

func (this *AccessLog) CleanFields()

清除不必要的的字段

func (*AccessLog) Format

func (this *AccessLog) Format(format string) string

func (*AccessLog) GetHeader

func (this *AccessLog) GetHeader(name string) string

获取Header内容

func (*AccessLog) Parse

func (this *AccessLog) Parse()

分析mime,扩展名、代理设置等

func (*AccessLog) SentContentType

func (this *AccessLog) SentContentType() string

func (*AccessLog) SetShouldStat

func (this *AccessLog) SetShouldStat(b bool)

设置是否支持统计

func (*AccessLog) SetShouldWrite added in v0.1.2

func (this *AccessLog) SetShouldWrite(b bool)

设置是否写入

func (*AccessLog) SetWritingFields added in v0.1.2

func (this *AccessLog) SetWritingFields(fields []int)

设置写入的字段

func (*AccessLog) ShouldStat

func (this *AccessLog) ShouldStat() bool

是否支持统计

func (*AccessLog) ShouldWrite added in v0.1.2

func (this *AccessLog) ShouldWrite() bool

是否支持写入

func (*AccessLog) Time

func (this *AccessLog) Time() time.Time

获取访问日志的请求时间

type AccessLogClient

type AccessLogClient struct {
	OS      AccessLogClientOS      `bson:"os" json:"os"`
	Device  AccessLogClientDevice  `bson:"device" json:"device"`
	Browser AccessLogClientBrowser `bson:"browser" json:"browser"`
}

type AccessLogClientBrowser

type AccessLogClientBrowser struct {
	Family string `bson:"family" json:"family"`
	Major  string `bson:"major" json:"major"`
	Minor  string `bson:"minor" json:"minor"`
	Patch  string `bson:"patch" json:"patch"`
}

type AccessLogClientDevice

type AccessLogClientDevice struct {
	Family string `bson:"family" json:"family"`
	Brand  string `bson:"brand" json:"brand"`
	Model  string `bson:"model" json:"model"`
}

type AccessLogClientOS

type AccessLogClientOS struct {
	Family     string `bson:"family" json:"family"`
	Major      string `bson:"major" json:"major"`
	Minor      string `bson:"minor" json:"minor"`
	Patch      string `bson:"patch" json:"patch"`
	PatchMinor string `bson:"patchMinor" json:"patchMinor"`
}

type AccessLogExtend added in v0.1.2

type AccessLogExtend struct {
	File   AccessLogFile   `bson:"file" json:"file"`
	Client AccessLogClient `bson:"client" json:"client"`
	Geo    AccessLogGeo    `bson:"geo" json:"geo"`
}

type AccessLogField added in v0.1.2

type AccessLogField = int

type AccessLogFile

type AccessLogFile struct {
	MimeType  string `bson:"mimeType" json:"mimeType"`   // 类似于 image/jpeg
	Extension string `bson:"extension" json:"extension"` // 扩展名,不带点(.)
	Charset   string `bson:"charset" json:"charset"`     // 字符集,统一大写
}

type AccessLogFileWriter

type AccessLogFileWriter struct {
	// contains filtered or unexported fields
}

func (*AccessLogFileWriter) Close

func (writer *AccessLogFileWriter) Close()

func (*AccessLogFileWriter) Init

func (writer *AccessLogFileWriter) Init()

func (*AccessLogFileWriter) Write

func (writer *AccessLogFileWriter) Write(log *AccessLog) error

type AccessLogGeo

type AccessLogGeo struct {
	Region   string               `bson:"region" json:"region"`
	State    string               `bson:"state" json:"state"`
	City     string               `bson:"city" json:"city"`
	Location AccessLogGeoLocation `bson:"location" json:"location"`
}

type AccessLogGeoLocation

type AccessLogGeoLocation struct {
	Latitude       float64 `bson:"latitude" json:"latitude"`
	Longitude      float64 `bson:"longitude" json:"longitude"`
	TimeZone       string  `bson:"timeZone" json:"timeZone"`
	AccuracyRadius uint16  `bson:"accuracyRadius" json:"accuracyRadius"`
	MetroCode      uint    `bson:"metroCode" json:"metroCode"`
}

type AccessLogHook

type AccessLogHook struct {
	Process func(accessLog *AccessLog) (goNext bool)
}

请求Hook定义

type AccessLogItem

type AccessLogItem struct {
	// contains filtered or unexported fields
}

type AccessLogStdoutWriter

type AccessLogStdoutWriter struct {
	// contains filtered or unexported fields
}

func (*AccessLogStdoutWriter) Close

func (writer *AccessLogStdoutWriter) Close()

func (*AccessLogStdoutWriter) Init

func (writer *AccessLogStdoutWriter) Init()

func (*AccessLogStdoutWriter) Write

func (writer *AccessLogStdoutWriter) Write(log *AccessLog) error

type AccessLogWriter

type AccessLogWriter interface {
	Init()
	Write(log *AccessLog) error
	Close()
}

func NewAccessLogWriter

func NewAccessLogWriter(config *teaconfigs.AccessLogConfig) (AccessLogWriter, error)

type AccessLogger

type AccessLogger struct {
	// contains filtered or unexported fields
}

访问日志记录器

func NewAccessLogger

func NewAccessLogger() *AccessLogger

func SharedLogger

func SharedLogger() *AccessLogger

func (*AccessLogger) Close

func (this *AccessLogger) Close()

关闭

func (*AccessLogger) Push

func (this *AccessLogger) Push(log *AccessLog)

type Query

type Query struct {
	// contains filtered or unexported fields
}

func NewQuery

func NewQuery() *Query

func (*Query) Action

func (this *Query) Action(action QueryAction) *Query

func (*Query) Asc

func (this *Query) Asc(field string) *Query

func (*Query) Attr

func (this *Query) Attr(field string, value interface{}) *Query

func (*Query) Debug

func (this *Query) Debug() *Query

func (*Query) Desc

func (this *Query) Desc(field string) *Query

func (*Query) Duration

func (this *Query) Duration(duration QueryDuration) *Query

func (*Query) Execute

func (this *Query) Execute() (interface{}, error)

开始执行

func (*Query) Find

func (this *Query) Find() (*AccessLog, error)

查找单个数据

func (*Query) FindAll

func (this *Query) FindAll() ([]*AccessLog, error)

查找多个数据

func (*Query) For

func (this *Query) For(field string) *Query

func (*Query) From

func (this *Query) From(time time.Time) *Query

func (*Query) Group

func (this *Query) Group(group []string) *Query

func (*Query) Gt

func (this *Query) Gt(field string, value interface{}) *Query

func (*Query) Gte

func (this *Query) Gte(field string, value interface{}) *Query

func (*Query) Id

func (this *Query) Id(idString string) *Query

设置日志ID

func (*Query) Limit

func (this *Query) Limit(size int64) *Query

func (*Query) Lt

func (this *Query) Lt(field string, value interface{}) *Query

func (*Query) Lte

func (this *Query) Lte(field string, value interface{}) *Query

func (*Query) Not

func (this *Query) Not(field string, value interface{}) *Query

func (*Query) Offset

func (this *Query) Offset(offset int64) *Query

func (*Query) Op

func (this *Query) Op(op string, field string, value interface{})

func (*Query) Result added in v0.1.2

func (this *Query) Result(field ...string) *Query

func (*Query) To

func (this *Query) To(time time.Time) *Query

type QueryAction

type QueryAction = string

type QueryDuration

type QueryDuration = string

Jump to

Keyboard shortcuts

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