Documentation ¶
Index ¶
- Constants
- Variables
- func AddHook(hook logrus.Hook)
- func Ctx(ctx context.Context) *logrus.Entry
- func CtxFields(ctx context.Context, fields logrus.Fields) context.Context
- func CtxPut(ctx context.Context, entry *logrus.Entry) context.Context
- func Debug(args ...interface{})
- func Debugf(format string, args ...interface{})
- func Debugln(args ...interface{})
- func Error(args ...interface{})
- func Errorf(format string, args ...interface{})
- func Errorln(args ...interface{})
- func Fatal(args ...interface{})
- func Fatalf(format string, args ...interface{})
- func Fatalln(args ...interface{})
- func GetLevel() logrus.Level
- func Info(args ...interface{})
- func Infof(format string, args ...interface{})
- func Infoln(args ...interface{})
- func IsLevelEnabled(level logrus.Level) bool
- func Panic(args ...interface{})
- func Panicf(format string, args ...interface{})
- func Panicln(args ...interface{})
- func Print(args ...interface{})
- func Printf(format string, args ...interface{})
- func PrintfHTTPReq(ctx context.Context, req HTTPRequest)
- func Println(args ...interface{})
- func Req(req *http.Request) *logrus.Entry
- func ReqWrap(req *http.Request, entry *logrus.Entry) *http.Request
- func SetFormatter(formatter logrus.Formatter)
- func SetLevel(level logrus.Level)
- func SetOutput(out io.Writer)
- func SetReportCaller(include bool)
- func Trace(args ...interface{})
- func Tracef(format string, args ...interface{})
- func Traceln(args ...interface{})
- func Warn(args ...interface{})
- func Warnf(format string, args ...interface{})
- func Warning(args ...interface{})
- func Warningf(format string, args ...interface{})
- func Warningln(args ...interface{})
- func Warnln(args ...interface{})
- func WithContext(ctx context.Context) *logrus.Entry
- func WithErr(err error) *logrus.Entry
- func WithField(key string, value interface{}) *logrus.Entry
- func WithFields(fields logrus.Fields) *logrus.Entry
- func WithTime(t time.Time) *logrus.Entry
- type CallerHook
- type ColorScheme
- type CtxKey
- type HTTPRequest
- type Log
- type Logger
- type RequestIDHook
- type TextFormatter
- type UserIDHook
Constants ¶
const HTTPRequestKey = "http:request"
HTTPRequestKey key used in fields to log http request data
Variables ¶
var NoHTTPOpt = cgerrors.ErrInvalidArgument("logging - no http request found")
NoHTTPOpt means no request ke was found
Functions ¶
func Debug ¶
func Debug(args ...interface{})
Debug logs a message at level Debug on the standard xlog.
func Debugf ¶
func Debugf(format string, args ...interface{})
Debugf logs a message at level Debug on the standard xlog.
func Debugln ¶
func Debugln(args ...interface{})
Debugln logs a message at level Debug on the standard xlog.
func Error ¶
func Error(args ...interface{})
Error logs a message at level Error on the standard xlog.
func Errorf ¶
func Errorf(format string, args ...interface{})
Errorf logs a message at level Error on the standard xlog.
func Errorln ¶
func Errorln(args ...interface{})
Errorln logs a message at level Error on the standard xlog.
func Fatal ¶
func Fatal(args ...interface{})
Fatal logs a message at level Fatal on the standard xlog then the process will exit with status set to 1.
func Fatalf ¶
func Fatalf(format string, args ...interface{})
Fatalf logs a message at level Fatal on the standard xlog then the process will exit with status set to 1.
func Fatalln ¶
func Fatalln(args ...interface{})
Fatalln logs a message at level Fatal on the standard xlog then the process will exit with status set to 1.
func Infof ¶
func Infof(format string, args ...interface{})
Infof logs a message at level Info on the standard xlog.
func Infoln ¶
func Infoln(args ...interface{})
Infoln logs a message at level Info on the standard xlog.
func IsLevelEnabled ¶
IsLevelEnabled checks if the log level of the standard xlog is greater than the level param
func Panic ¶
func Panic(args ...interface{})
Panic logs a message at level Panic on the standard xlog.
func Panicf ¶
func Panicf(format string, args ...interface{})
Panicf logs a message at level Panic on the standard xlog.
func Panicln ¶
func Panicln(args ...interface{})
Panicln logs a message at level Panic on the standard xlog.
func Print ¶
func Print(args ...interface{})
Print logs a message at level Info on the standard xlog.
func Printf ¶
func Printf(format string, args ...interface{})
Printf logs a message at level Info on the standard xlog.
func PrintfHTTPReq ¶
func PrintfHTTPReq(ctx context.Context, req HTTPRequest)
PrintfHTTPReq will log request on specific level
func Println ¶
func Println(args ...interface{})
Println logs a message at level Info on the standard xlog.
func SetFormatter ¶
SetFormatter sets the standard xlog formatter.
func SetReportCaller ¶
func SetReportCaller(include bool)
SetReportCaller sets whether the standard xlog will include the calling method as a field.
func Trace ¶
func Trace(args ...interface{})
Trace logs a message at level Trace on the standard xlog.
func Tracef ¶
func Tracef(format string, args ...interface{})
Tracef logs a message at level Trace on the standard xlog.
func Traceln ¶
func Traceln(args ...interface{})
Traceln logs a message at level Trace on the standard xlog.
func Warnf ¶
func Warnf(format string, args ...interface{})
Warnf logs a message at level Warn on the standard xlog.
func Warning ¶
func Warning(args ...interface{})
Warning logs a message at level Warn on the standard xlog.
func Warningf ¶
func Warningf(format string, args ...interface{})
Warningf logs a message at level Warn on the standard xlog.
func Warningln ¶
func Warningln(args ...interface{})
Warningln logs a message at level Warn on the standard xlog.
func Warnln ¶
func Warnln(args ...interface{})
Warnln logs a message at level Warn on the standard xlog.
func WithContext ¶
WithContext returns a new log entry with given context.
func WithErr ¶
WithErr creates an entry from the standard xlog and adds an error to it, using the value defined in ErrorKey as key.
func WithField ¶
WithField creates an entry from the standard xlog and adds a field to it. If you want multiple fields, use `WithFields`.
Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal or Panic on the Entry it returns.
func WithFields ¶
WithFields creates an entry from the standard xlog and adds multiple fields to it. This is simply a helper for `WithField`, invoking it once for each field.
Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal or Panic on the Entry it returns.
Types ¶
type CallerHook ¶
type CallerHook struct {
// contains filtered or unexported fields
}
CallerHook is the logrus.Hook that sets up the logrus.Entry.Caller field. Sets up the entry.Logger
func DefaultCallerHook ¶
func DefaultCallerHook() *CallerHook
DefaultCallerHook gets the default caller hook that sets up the caller for the level fatal, error, panic, warn and trace.
func NewCallerHook ¶
func NewCallerHook(levels []logrus.Level) *CallerHook
NewCallerHook creates a new CallerHook.
func (CallerHook) Fire ¶
func (c CallerHook) Fire(entry *logrus.Entry) error
Fire sets up the Caller field in the logrus.Entry. Implements logrus.Hook.
func (CallerHook) Levels ¶
func (c CallerHook) Levels() []logrus.Level
Levels gets the levels that this hook is available for. Implements logrus.Hook.
type ColorScheme ¶
type ColorScheme struct { InfoLevelStyle string WarnLevelStyle string ErrorLevelStyle string FatalLevelStyle string PanicLevelStyle string DebugLevelStyle string PrefixStyle string TimestampStyle string }
ColorScheme represents colors used with terminal
type CtxKey ¶
type CtxKey string
CtxKey represents custom type for context
const CtxLogger CtxKey = "xlog:entry"
CtxLogger represents key in context
type HTTPRequest ¶
type HTTPRequest struct { // The request method. Examples: `"GET"`, `"HEAD"`, `"PUT"`, `"POST"`. RequestMethod string `json:"requestMethod,omitempty"` // The scheme (http, https), the host name, the path and the query // portion of the URL that was requested. // Example: `"http://example.com/some/info?color=red"`. RequestURL string `json:"requestUrl,omitempty"` // The size of the HTTP request message in bytes, including the request // headers and the request body. RequestSize int64 `json:"requestSize,omitempty"` // The response code indicating the status of response. // Examples: 200, 404. Status int32 `json:"status,omitempty"` // The size of the HTTP response message sent back to the client, in bytes, // including the response headers and the response body. ResponseSize int64 `json:"responseSize,omitempty"` // The user agent sent by the client. Example: // `"Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Q312461; .NET CLR 1.0.3705)"`. UserAgent string `json:"userAgent,omitempty"` // The IP address (IPv4 or IPv6) of the client that issued the HTTP // request. Examples: `"192.168.1.1"`, `"FE80::0202:B3FF:FE1E:8329"`. RemoteIP string `json:"remoteIp,omitempty"` // The IP address (IPv4 or IPv6) of the origin server that the request was // sent to. ServerIP string `json:"serverIp,omitempty"` // The referer URL of the request, as defined in // [HTTP/1.1 Header Field Definitions](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). Referer string `json:"referer,omitempty"` // The request processing latency on the server, from the time the request was // received until the response was sent. Latency string `json:"latency,omitempty"` // Whether or not a cache lookup was attempted. CacheLookup bool `json:"cacheLookup,omitempty"` // Whether or not an entity was served from cache // (with or without validation). CacheHit bool `json:"cacheHit,omitempty"` // Whether or not the response was validated with the origin server before // being served from cache. This field is only meaningful if `cache_hit` is // True. CacheValidatedWithOriginServer bool `json:"cacheValidatedWithOriginServer,omitempty"` // The number of HTTP response bytes inserted into cache. Set only when a // cache fill was attempted. CacheFillBytes int64 `json:"cacheFillBytes,omitempty"` // Protocol used for the request. Examples: "HTTP/1.1", "HTTP/2", "websocket" Protocol string `json:"protocol,omitempty"` }
HTTPRequest for logging HTTP requests. Only contains semantics defined by the HTTP specification. Product-specific logging information MUST be defined in a separate message.
func ExtractHTTPField ¶
func ExtractHTTPField(r logrus.Fields) (HTTPRequest, error)
ExtractHTTPField will extract http option
type Logger ¶
type Logger interface { logrus.FieldLogger }
Logger is interface which satisfies Entry and Log
type RequestIDHook ¶
type RequestIDHook struct{}
RequestIDHook is a logging hook used to log the request id stored in the context metadata.
func (RequestIDHook) Levels ¶
func (m RequestIDHook) Levels() []logrus.Level
type TextFormatter ¶
type TextFormatter struct { // TimestampFormat sets the format used for marshaling timestamps. // The format to use is the same than for time.Format or time.Parse from the standard // library. // The standard Library already provides a set of predefined format. TimestampFormat string // Force disabling colors. For a TTY colors are enabled by default. UseColors bool // DisableTimestamp allows disabling automatic timestamps in output DisableTimestamp bool // DataKey allows users to put all the log entry parameters into a nested dictionary at a given key. DataKey string // CallerPrettyfier can be set by the user to modify the content // of the function and file keys in the json data when ReportCaller is // activated. If any of the returned value is the empty string the // corresponding key will be removed from fields. CallerPrettyfier func(*runtime.Frame) (function string, file string) // contains filtered or unexported fields }
TextFormatter is struct implementing Format interface this is useful for formatting logs in different environments. This formatter will format logs for terminal and testing.
func NewTextFormatter ¶
func NewTextFormatter(colors bool) *TextFormatter
NewTextFormatter creates new logrus based text formatter.
type UserIDHook ¶
type UserIDHook struct{}
UserIDHook is a hook that gets the user id from the context metadata and logs it on each log level.
func (UserIDHook) Levels ¶
func (u UserIDHook) Levels() []logrus.Level