Documentation ¶
Index ¶
- Constants
- Variables
- func D(ctx context.Context, fmt string, args ...interface{})
- func E(ctx context.Context, fmt string, args ...interface{})
- func Enter(ctx context.Context, name string) context.Context
- func Err(ctx context.Context, cause error, msg string) error
- func Errf(ctx context.Context, cause error, fmt string, args ...interface{}) error
- func F(ctx context.Context, stopProcess bool, fmt string, args ...interface{})
- func GetProcess(ctx context.Context) string
- func GetTag(ctx context.Context) string
- func GetTrace(ctx context.Context) []string
- func HHMMSSsss(t time.Time) string
- func I(ctx context.Context, fmt string, args ...interface{})
- func PutClock(ctx context.Context, c Clock) context.Context
- func PutFilter(ctx context.Context, w Filter) context.Context
- func PutHandler(ctx context.Context, w Handler) context.Context
- func PutProcess(ctx context.Context, w string) context.Context
- func PutStacktracer(ctx context.Context, s Stacktracer) context.Context
- func PutTag(ctx context.Context, w string) context.Context
- func RegisterStyle(s Style)
- func Testing(t delegate) context.Context
- func W(ctx context.Context, fmt string, args ...interface{})
- type Broadcaster
- type Clock
- type Filter
- type FixedClock
- type Handler
- type Indirect
- type Logger
- func (l *Logger) D(fmt string, args ...interface{})
- func (l *Logger) E(fmt string, args ...interface{})
- func (l *Logger) Err(cause error, msg string) error
- func (l *Logger) Errf(cause error, fmt string, args ...interface{}) error
- func (l *Logger) F(fmt string, stopProcess bool, args ...interface{})
- func (l *Logger) Fatal(args ...interface{})
- func (l *Logger) Fatalf(format string, args ...interface{})
- func (l *Logger) Fatalln(args ...interface{})
- func (l *Logger) I(fmt string, args ...interface{})
- func (l *Logger) Log(s Severity, stopProcess bool, f string)
- func (l *Logger) Logf(s Severity, stopProcess bool, fmt string, args ...interface{})
- func (l *Logger) Message(s Severity, stopProcess bool, text string) *Message
- func (l *Logger) Messagef(s Severity, stopProcess bool, text string, args ...interface{}) *Message
- func (l *Logger) Print(args ...interface{})
- func (l *Logger) Printf(format string, args ...interface{})
- func (l *Logger) Println(args ...interface{})
- func (l *Logger) W(fmt string, args ...interface{})
- func (l *Logger) Writer(s Severity) io.WriteCloser
- type Message
- type Severity
- type SeverityFilter
- type SeverityStacktracer
- type SeverityStyle
- type SourceLocation
- type Stacktracer
- type Style
- type Trace
- type V
- type Value
- type ValueStyle
- type Values
- type Writer
Constants ¶
const ( // NoSeverity is the option to disable the printing of the severity. NoSeverity = SeverityStyle(iota) // SeverityShort is the option to display the severity as a single character. SeverityShort // SeverityLong is the option to display the severity in its full name. SeverityLong )
const ( // NoValues is the option to disable the printing of values. NoValues = ValueStyle(iota) // ValuesSingleLine is the option to display all values on a single line. ValuesSingleLine // ValuesMultiLine is the option to display each value on a separate line. ValuesMultiLine )
Variables ¶
var ( // Raw is a style that only prints the text of the message. Raw = Style{ Name: "raw", Timestamp: false, Tag: false, Trace: false, Process: false, Severity: NoSeverity, Values: NoValues, } // Brief is a style that only prints the text and short severity of the // message. Brief = Style{ Name: "brief", Timestamp: false, Tag: false, Trace: false, Process: false, Severity: SeverityShort, Values: NoValues, } // Normal is a style that prints the timestamp, tag, trace, process, // short severity. Normal = Style{ Name: "normal", Timestamp: true, Tag: true, Trace: true, Process: true, Severity: SeverityShort, Values: NoValues, } // Detailed is a style that prints the timestamp, tag, trace, process, // long severity and multi-line values. Detailed = Style{ Name: "detailed", Timestamp: true, Tag: true, Trace: true, Process: true, Severity: SeverityLong, Values: ValuesMultiLine, } )
var ( // NoClock is a Clock that disables printing of the time. NoClock = FixedClock(time.Time{}) )
Functions ¶
func F ¶
F logs a fatal message to the logging target. If stopProcess is true then the message indicates the process should stop.
func GetProcess ¶
GetProcess returns the process assigned to ctx.
func PutHandler ¶
PutHandler returns a new context with the Handler assigned to w.
func PutProcess ¶
PutProcess returns a new context with the process assigned to w.
func PutStacktracer ¶
func PutStacktracer(ctx context.Context, s Stacktracer) context.Context
PutStacktracer returns a new context with the Stacktracer assigned to w.
func RegisterStyle ¶
func RegisterStyle(s Style)
RegisterStyle registers the style s. The list of registered styles can be displayed in command line flags.
Types ¶
type Broadcaster ¶
type Broadcaster struct {
// contains filtered or unexported fields
}
Broadcaster forwards all messages to all supplied handlers. Broadcaster implements the Handler interface.
func Broadcast ¶
func Broadcast(handlers ...Handler) *Broadcaster
Broadcast forwards all messages sent to Broadcast to all supplied handlers. Additional handlers can be added with Listen.
func (*Broadcaster) Close ¶
func (b *Broadcaster) Close()
Close calls Close on all the listening handlers and removes them from the broadcaster.
func (*Broadcaster) Count ¶
func (b *Broadcaster) Count() int
Count returns the number of registered handlers.
func (*Broadcaster) Handle ¶
func (b *Broadcaster) Handle(m *Message)
Handle broadcasts the page to all the listening handlers.
func (*Broadcaster) Listen ¶
func (b *Broadcaster) Listen(h Handler) (unlisten func())
Listen calls adds h to the list of handlers that are informed of each log message passed to Handle.
type Filter ¶
type Filter interface { // ShowSeverity returns true if the message of severity s should be shown. ShowSeverity(s Severity) bool }
Filter is the filter of log messages.
type FixedClock ¶
FixedClock is a Clock that returns a fixed time.
type Handler ¶
type Handler interface { Handle(*Message) Close() }
Handler is the handler of log messages.
func Channel ¶
Channel is a log handler that passes log messages to another Handler through a chan. This makes this Handler safe to use from multiple threads.
func GetHandler ¶
GetHandler returns the Handler assigned to ctx.
func NewHandler ¶
NewHandler returns a Handler that calls handle for each message and close when the handler is closed. close can be nil.
func OnClosed ¶ added in v0.6.2
OnClosed returns a handler that forwards all messages on to h, but also calls closed after the returned handler is closed.
func TestHandler ¶
TestHandler is a Writer that uses the style to write records to t's using the style s.
type Indirect ¶ added in v0.6.2
type Indirect struct {
// contains filtered or unexported fields
}
Indirect is a Handler that can be dynamically retarget to another logger.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger provides a logging interface.
func (*Logger) Errf ¶
Errf creates a new error that wraps cause with the current logging information.
func (*Logger) F ¶
F logs a fatal message to the logging target. If stopProcess is true then the message indicates the process should stop.
func (*Logger) Fatal ¶
func (l *Logger) Fatal(args ...interface{})
Fatal implements the standard go logger interface.
func (*Logger) Fatalln ¶
func (l *Logger) Fatalln(args ...interface{})
Fatalln implements the standard go logger interface.
func (*Logger) Print ¶
func (l *Logger) Print(args ...interface{})
Print implements the standard go logger interface.
func (*Logger) Println ¶
func (l *Logger) Println(args ...interface{})
Println implements the standard go logger interface.
type Message ¶
type Message struct { // The message text. Text string // The time the message was logged. Time time.Time // The severity of the message. Severity Severity // StopProcess is true if the message indicates the process should stop. StopProcess bool // The tag associated with the log record. Tag string // The name of the process that created the record. Process string // The callstack at the time the message was logged. Callstack []*SourceLocation // The stack of enter() calls at the time the message was logged. Trace Trace // The key-value pairs of extra data. Values Values }
type Severity ¶
type Severity int32
Severity defines the severity of a logging message.
const ( // Verbose indicates extremely verbose level messages. Verbose Severity = 0 // Debug indicates debug-level messages. Debug Severity = 1 // Info indicates minor informational messages that should generally be ignored. Info Severity = 2 // Warning indicates issues that might affect performance or compatibility, but could be ignored. Warning Severity = 3 // Error indicates non terminal failure conditions that may have an effect on results. Error Severity = 4 // Fatal indicates a fatal error. Fatal Severity = 5 )
The values must be identical to values in gapis/service/service.proto
func (*Severity) Choose ¶
func (s *Severity) Choose(c interface{})
Choose allows *Severity to be used as a command line flag.
type SeverityFilter ¶
type SeverityFilter Severity
SeverityFilter implements the Filter interface which filters out any messages below the severity value.
func (SeverityFilter) ShowSeverity ¶
func (f SeverityFilter) ShowSeverity(s Severity) bool
ShowSeverity returns true if the message of severity s should be shown.
type SeverityStacktracer ¶
type SeverityStacktracer Severity
SeverityStacktracer implements the Stacktracer interface which adds a stacktrace to messages equal to or more than the severity level.
func (SeverityStacktracer) ShouldStacktrace ¶
func (s SeverityStacktracer) ShouldStacktrace(m *Message) bool
ShouldStacktrace returns true if the message of severity s should include a stacktrace.
type SeverityStyle ¶
type SeverityStyle int
SeverityStyle is an enumerator of ways that severities can be printed.
type SourceLocation ¶
type Stacktracer ¶
Stacktracer is the interface that controls when a stacktrace is taken.
func GetStacktracer ¶
func GetStacktracer(ctx context.Context) Stacktracer
GetStacktracer returns the Stacktracer assigned to ctx.
type Style ¶
type Style struct { Name string // Name of the style. Timestamp bool // If true, the timestamp will be printed if part of the message. Tag bool // If true, the tag will be printed if part of the message. Trace bool // If true, the trace will be printed if part of the message. Process bool // If true, the process will be printed if part of the message. Severity SeverityStyle // How the severity of the message will be printed. Values ValueStyle // How the values of the message will be printed. }
Style provides customization for printing messages.
func (*Style) Choose ¶
func (s *Style) Choose(v interface{})
Choose sets the style to the supplied choice.
func (Style) Handler ¶
Handler returns a new Handler configured to write to out and err with the given style.
type V ¶
type V map[string]interface{}
V is a map of key-value pairs. It can be associated with a context with Bind().
type ValueStyle ¶
type ValueStyle int
ValueStyle is an enumerator of ways that values can be printed.