Documentation
¶
Index ¶
Constants ¶
const ( HeadTracker = "HeadTracker" HeadListener = "HeadListener" HeadSaver = "HeadSaver" HeadBroadcaster = "HeadBroadcaster" FluxMonitor = "FluxMonitor" Keeper = "Keeper" TelemetryIngressBatchClient = "TelemetryIngressBatchClient" TelemetryIngressBatchWorker = "TelemetryIngressBatchWorker" )
Constants for service names for package specific logging configuration
const ( // SentryFlushDeadline indicates the maximum amount of time we allow sentry to // flush events on manual flush SentryFlushDeadline = 5 * time.Second )
Variables ¶
This section is empty.
Functions ¶
func GetLogServices ¶ added in v0.10.6
func GetLogServices() []string
func InitColor ¶ added in v1.1.0
func InitColor(c bool)
InitColor explicitly sets the global color.NoColor option. Not safe for concurrent use. Only to be called from init().
func NewOCRWrapper ¶ added in v1.1.0
Types ¶
type Config ¶ added in v1.1.0
type LogConfig ¶ added in v0.10.6
type LogConfig struct { ID int64 ServiceName string LogLevel string CreatedAt time.Time UpdatedAt time.Time }
LogConfig stores key value pairs for configuring package specific logging
type Logger ¶
type Logger interface { // With creates a new Logger with the given arguments With(args ...interface{}) Logger // Named creates a new Logger sub-scoped with name. // Names are inherited and dot-separated. // a := l.Named("a") // logger=a // b := a.Named("b") // logger=a.b Named(name string) Logger // NewRootLogger creates a new root Logger with an independent log level // unaffected by upstream calls to SetLogLevel. NewRootLogger(lvl zapcore.Level) (Logger, error) // SetLogLevel changes the log level for this and all connected Loggers. SetLogLevel(zapcore.Level) Trace(args ...interface{}) Debug(args ...interface{}) Info(args ...interface{}) Warn(args ...interface{}) Error(args ...interface{}) Critical(args ...interface{}) Panic(args ...interface{}) // Fatal logs and then calls os.Exit(1) // Be careful about using this since it does NOT unwind the stack and may // exit uncleanly Fatal(args ...interface{}) Tracef(format string, values ...interface{}) Debugf(format string, values ...interface{}) Infof(format string, values ...interface{}) Warnf(format string, values ...interface{}) Errorf(format string, values ...interface{}) Criticalf(format string, values ...interface{}) Panicf(format string, values ...interface{}) Fatalf(format string, values ...interface{}) Tracew(msg string, keysAndValues ...interface{}) Debugw(msg string, keysAndValues ...interface{}) Infow(msg string, keysAndValues ...interface{}) Warnw(msg string, keysAndValues ...interface{}) Errorw(msg string, keysAndValues ...interface{}) Criticalw(msg string, keysAndValues ...interface{}) Panicw(msg string, keysAndValues ...interface{}) Fatalw(msg string, keysAndValues ...interface{}) // ErrorIf logs the error if present. ErrorIf(err error, msg string) // ErrorIfClosing calls c.Close() and logs any returned error along with name. ErrorIfClosing(c io.Closer, name string) // Sync flushes any buffered log entries. // Some insignificant errors are suppressed. Sync() error // Helper creates a new logger with the number of callers skipped by caller annotation increased by skip. // This allows wrappers and helpers to point higher up the stack (like testing.T.Helper()). Helper(skip int) Logger // Recover reports recovered panics; this is useful because it avoids // double-reporting to sentry Recover(panicErr interface{}) }
Logger is the main interface of this package. It implements uber/zap's SugaredLogger interface and adds conditional logging helpers.
The package-level helper functions are being phased out. Loggers should be injected instead (and usually Named as well): e.g. lggr.Named("<service name>")
Tips
- Tests should use a TestLogger, with NewLogger being reserved for actual runtime and limited direct testing.
- Critical level logs should only be used when user intervention is required.
- Trace level logs are omitted unless compiled with the trace tag. For example: go test -tags trace ...
var NullLogger Logger = &nullLogger{}
func NewLogger ¶ added in v1.1.0
func NewLogger() Logger
NewLogger returns a new Logger configured from environment variables, and logs any parsing errors. Tests should use TestLogger.
func TestLogger ¶ added in v1.1.0
TestLogger creates a logger that directs output to PrettyConsole configured for test output, and to the buffer testMemoryLog. t is optional. Log level is derived from the LOG_LEVEL env var.
type MemorySink ¶ added in v0.8.15
type MemorySink struct {
// contains filtered or unexported fields
}
MemorySink implements zap.Sink by writing all messages to a buffer.
func MemoryLogTestingOnly ¶ added in v0.8.15
func MemoryLogTestingOnly() *MemorySink
func (*MemorySink) Close ¶ added in v0.8.15
func (s *MemorySink) Close() error
Close is a dummy method to satisfy the zap.Sink interface
func (*MemorySink) Reset ¶ added in v1.1.0
func (s *MemorySink) Reset()
func (*MemorySink) String ¶ added in v0.8.15
func (s *MemorySink) String() string
String returns the full log contents, as a string
func (*MemorySink) Sync ¶ added in v0.8.15
func (s *MemorySink) Sync() error
Sync is a dummy method to satisfy the zap.Sink interface
type PrettyConsole ¶
PrettyConsole wraps a Sink (Writer, Syncer, Closer), usually stdout, and formats the incoming json bytes with colors and white space for readability before passing on to the underlying Writer in Sink.
func (PrettyConsole) Close ¶ added in v1.2.0
func (pc PrettyConsole) Close() error
Close is overridden to prevent accidental closure of stderr/stdout