Documentation ¶
Overview ¶
Package rkquery can be used for creating Event instance for logging.
Index ¶
- Constants
- Variables
- type Encoding
- type Event
- type EventFactory
- type EventHelper
- type EventOption
- func WithAppName(appName string) EventOption
- func WithAppVersion(appVersion string) EventOption
- func WithEncoding(ec Encoding) EventOption
- func WithEntryName(entryName string) EventOption
- func WithEntryType(entryType string) EventOption
- func WithOperation(operation string) EventOption
- func WithPayloads(fields ...zap.Field) EventOption
- func WithQuietMode(quietMode bool) EventOption
- func WithZapLogger(logger *zap.Logger) EventOption
Constants ¶
const ( // NotStarted will be assigned to Event before SetStartTime() was called. NotStarted eventStatus = 0 // InProgress will be assigned to Event after SetStartTime() was called. InProgress eventStatus = 1 // Ended will be assigned to Event after SetEndTime() was called. Ended eventStatus = 2 )
Variables ¶
var ( // StdLoggerConfigBytes defines zap logger config whose output path is stdout. StdLoggerConfigBytes = []byte(`{ "level": "info", "encoding": "console", "outputPaths": ["stdout"], "errorOutputPaths": ["stderr"], "initialFields": {}, "encoderConfig": { "messageKey": "msg", "levelKey": "", "nameKey": "", "timeKey": "", "callerKey": "", "stacktraceKey": "", "callstackKey": "", "errorKey": "", "timeEncoder": "iso8601", "fileKey": "", "levelEncoder": "capital", "durationEncoder": "second", "callerEncoder": "full", "nameEncoder": "full" }, "maxsize": 1, "maxage": 7, "maxbackups": 3, "localtime": true, "compress": true }`) // StdoutLogger defines zap logger which use StdLoggerConfigBytes as config. StdoutLogger, _, _ = rk_logger.NewZapLoggerWithBytes(StdLoggerConfigBytes, rk_logger.JSON) )
Functions ¶
This section is empty.
Types ¶
type Encoding ¶ added in v1.2.0
type Encoding int
Encoding supported format of Console and JSON currently.
func ToEncoding ¶ added in v1.2.0
ToEncoding returns Encoding type from string value.
type Event ¶
type Event interface { // SetStartTime sets start timer of current event. This can be overridden by user. // We keep this function open in order to mock event during unit test. SetStartTime(time.Time) // GetStartTime returns start time of current event data. GetStartTime() time.Time // SetEndTime sets end timer of current event. This can be overridden by user. // We keep this function open in order to mock event during unit test. SetEndTime(time.Time) // GetEndTime returns end time of current event data. GetEndTime() time.Time // AddPayloads function add payload as zap.Field. // Payload could be anything with RPC requests or user event such as http request param. AddPayloads(...zap.Field) // ListPayloads will lists payloads. ListPayloads() []zap.Field // GetEventId returns event id of current event. GetEventId() string // SetEventId sets event id of current event. // A new event id would be created while event data was created from EventFactory. // User could override event id with this function. SetEventId(string) // GetTraceId returns trace id of current event. GetTraceId() string // SetTraceId set trace id of current event. SetTraceId(string) // GetRequestId returns request id of current event. GetRequestId() string // SetRequestId set request id of current event. SetRequestId(string) // AddErr function adds an error into event which could be printed with error.Error() function. AddErr(error) // GetErrCount returns error count. // We will use value of error.Error() as the key. GetErrCount(error) int64 // GetOperation returns operation of current event. GetOperation() string // SetOperation sets operation of current event. SetOperation(string) // GetRemoteAddr returns remote address of current event. GetRemoteAddr() string // SetRemoteAddr sets remote address of current event, mainly used in RPC calls. // Default value of <localhost> would be assigned while creating event via EventFactory. SetRemoteAddr(string) // GetResCode returns response code of current event. // Mainly used in RPC calls. GetResCode() string // SetResCode sets response code of current event. SetResCode(string) // GetEventStatus returns event status of current event. // Available event status as bellow: // 1: NotStarted // 2: InProgress // 3: Ended GetEventStatus() eventStatus // StartTimer starts timer of current sub event. StartTimer(string) // EndTimer ends timer of current sub event. EndTimer(string) // UpdateTimerMs updates timer of current sub event with time elapsed in milli seconds. UpdateTimerMs(string, int64) // UpdateTimerMsWithSample updates timer of current sub event with time elapsed in milli seconds and sample. UpdateTimerMsWithSample(string, int64, int64) // GetTimeElapsedMs returns timer elapsed in milli seconds. GetTimeElapsedMs(string) int64 // GetValueFromPair returns value with key in pairs. GetValueFromPair(string) string // AddPair adds value with key in pairs. AddPair(string, string) // GetCounter returns counter of current event. GetCounter(string) int64 // SetCounter sets counter of current event. SetCounter(string, int64) // IncCounter increases counter of current event. IncCounter(string, int64) // Finish sets event status and flush to logger. Finish() // Sync flushes logger in buffer Sync() }
Event is used to record any event related stuff like RPC
type EventFactory ¶
type EventFactory struct {
// contains filtered or unexported fields
}
EventFactory is not thread safe!!!
func NewEventFactory ¶
func NewEventFactory(option ...EventOption) *EventFactory
NewEventFactory creates a new event factory with option.
func (*EventFactory) CreateEvent ¶
func (factory *EventFactory) CreateEvent(options ...EventOption) Event
CreateEvent creates a new event with options.
func (*EventFactory) CreateEventNoop ¶ added in v1.0.3
func (factory *EventFactory) CreateEventNoop() Event
CreateEventNoop creates a new noop event.
func (*EventFactory) CreateEventThreadSafe ¶ added in v1.0.3
func (factory *EventFactory) CreateEventThreadSafe(options ...EventOption) Event
CreateEventThreadSafe create a new thread safe event.
type EventHelper ¶
type EventHelper struct {
Factory *EventFactory
}
EventHelper is a helper function for easy use of EventData.
func NewEventHelper ¶ added in v1.0.3
func NewEventHelper(factory *EventFactory) *EventHelper
NewEventHelper creates a new event helper.
func (*EventHelper) FinishWithCond ¶
func (helper *EventHelper) FinishWithCond(event Event, success bool)
FinishWithCond finish current event with condition.
func (*EventHelper) FinishWithError ¶
func (helper *EventHelper) FinishWithError(event Event, err error)
FinishWithError finish current event with error.
func (*EventHelper) Start ¶
func (helper *EventHelper) Start(operation string, opts ...EventOption) Event
Start function creates and start a new event with options.
type EventOption ¶ added in v1.0.3
type EventOption func(Event)
EventOption will be pass into EventFactory while creating Event to override fields in Event.
func WithAppName ¶ added in v1.0.2
func WithAppName(appName string) EventOption
WithAppName override app name in Event.
func WithAppVersion ¶ added in v1.2.0
func WithAppVersion(appVersion string) EventOption
WithAppVersion overrides app version in event.
func WithEncoding ¶ added in v1.2.0
func WithEncoding(ec Encoding) EventOption
WithEncoding override encoding in Event.
func WithEntryName ¶ added in v1.2.0
func WithEntryName(entryName string) EventOption
WithEntryName override entry name in Event.
func WithEntryType ¶ added in v1.2.0
func WithEntryType(entryType string) EventOption
WithEntryType override entry type in Event.
func WithOperation ¶ added in v1.0.2
func WithOperation(operation string) EventOption
WithOperation overrides operation in Event.
func WithPayloads ¶ added in v1.2.0
func WithPayloads(fields ...zap.Field) EventOption
WithPayloads overrides payloads with form of zap.Field in Event.
func WithQuietMode ¶ added in v1.0.2
func WithQuietMode(quietMode bool) EventOption
WithQuietMode turn on quiet mode which won't flush data to logger.
func WithZapLogger ¶ added in v1.2.0
func WithZapLogger(logger *zap.Logger) EventOption
WithZapLogger override logger in Event.