Documentation ¶
Index ¶
- Constants
- func AddField(ctx context.Context, fields ...Field)
- func DeleteField(ctx context.Context, keys ...string)
- func ExtractLogID(req *http.Request) string
- func ForkContext(ctx context.Context) context.Context
- func GetRequestBody(req *http.Request) []byte
- func InitFieldsContainer(ctx context.Context) context.Context
- func RangeFields(ctx context.Context, f func(f Field))
- func RotateWriter(infoFile, errFile string) (infoWriter io.Writer, errWriter io.Writer, err error)
- func ValueLogID(ctx context.Context) string
- func ValueTraceID(ctx context.Context) string
- func WithLogID(ctx context.Context, val interface{}) context.Context
- func WithTraceID(ctx context.Context, val interface{}) context.Context
- type Field
- type Fields
- type Level
- type Logger
- type ObjectID
Constants ¶
const ( ModuleHTTP = "HTTP" ModuleRPC = "RPC" ModuleMySQL = "MySQL" ModuleRedis = "Redis" ModuleQueue = "Queue" ModuleCron = "Cron" )
const ( AppName = "app_name" Module = "module" ServiceName = "service_name" LogID = "log_id" TraceID = "trace_id" Header = "header" Method = "method" Request = "request" Response = "response" Code = "code" ClientIP = "client_ip" ClientPort = "client_port" ServerIP = "server_ip" ServerPort = "server_port" API = "api" URI = "uri" Cost = "cost" Timeout = "timeout" Trace = "trace" )
const (
ContextRPC contextKey
)
const (
LogHeader = "Log-Id"
)
Variables ¶
This section is empty.
Functions ¶
func DeleteField ¶ added in v1.0.9
func GetRequestBody ¶
GetRequestBody get http request body
func InitFieldsContainer ¶ added in v1.0.9
func RangeFields ¶ added in v1.0.9
func RotateWriter ¶
func ValueLogID ¶
ValueLogID extract log id from context
func ValueTraceID ¶
ValueTraceID extract trace id from context
Types ¶
type Field ¶
func ExtractFields ¶ added in v1.0.9
type Fields ¶
type Fields struct { AppName string `json:"app_name"` Module string `json:"module"` ServiceName string `json:"service_name"` LogID string `json:"log_id"` TraceID string `json:"trace_id"` Header http.Header `json:"header"` Method string `json:"method"` Request interface{} `json:"request"` Response interface{} `json:"response"` Code int `json:"code"` ClientIP string `json:"client_ip"` ClientPort int `json:"client_port"` ServerIP string `json:"server_ip"` ServerPort int `json:"server_port"` API string `json:"api"` URI string `json:"uri"` Cost int64 `json:"cost"` Timeout time.Duration `json:"timeout"` Trace string `json:"trace"` }
type Logger ¶
type Logger interface { Debug(ctx context.Context, msg string, fields ...Field) Info(ctx context.Context, msg string, fields ...Field) Warn(ctx context.Context, msg string, fields ...Field) Error(ctx context.Context, msg string, fields ...Field) Fatal(ctx context.Context, msg string, fields ...Field) GetLevel() Level Close() error }
type ObjectID ¶
type ObjectID [12]byte
LogId is a unique ID identifying a log record. It must be exactly 12 bytes long.
Reference:http://www.mongodb.org/display/DOCS/Object+IDs
func NewObjectIDWithTime ¶
NewObjectIDWithTime returns a dummy ObjectID with the timestamp part filled with the provided number of seconds from epoch UTC, and all other parts filled with zeroes. It's not safe to insert a document with an id generated by this method, it is useful only for queries to find documents with ids generated before or after the specified timestamp.
func (ObjectID) Counter ¶
Counter returns the incrementing value part of the id. It's a runtime error to call this method with an invalid id.
func (ObjectID) Machine ¶
Machine returns the 3-byte machine id part of the id. It's a runtime error to call this method with an invalid id.