Documentation ¶
Index ¶
- Variables
- func ElapsedMillisTimeEncoder(setupTime time.Time) zapcore.TimeEncoder
- func EnsureLogFile(ctx context.Context) context.Context
- func EnsureLogger(ctx context.Context, fields ...Fields) context.Context
- func LogFileFrom(ctx context.Context) *os.File
- func WithFatalCaptured(fn func()) []any
- func WithLogFile(ctx context.Context, f *os.File) context.Context
- func WithLogFileCloser(ctx context.Context, closer Closer) context.Context
- func WithLogger(ctx context.Context, l Logger) context.Context
- type Closer
- type Fields
- type Logger
Constants ¶
This section is empty.
Variables ¶
var ErrCallEnsureLoggerFirst = errors.New("call EnsureLogger() before LoggerFrom() method")
ErrCallEnsureLoggerFirst is returned when LoggerFrom() is called before EnsureLogger().
Functions ¶
func ElapsedMillisTimeEncoder ¶
func ElapsedMillisTimeEncoder(setupTime time.Time) zapcore.TimeEncoder
func EnsureLogFile ¶
EnsureLogFile ensures that a log file is present in the context. If not, it creates one and adds it to the context. The file's Closer is also added to the context if not already present.
func EnsureLogger ¶
EnsureLogger ensures that a logger is attached to the context. The returned context will have a logger attached to it. Given fields will be added to the logger, either new or existing.
func WithFatalCaptured ¶
func WithFatalCaptured(fn func()) []any
WithFatalCaptured runs the given function and captures the arguments passed to Fatal function. It is useful in tests to verify that the expected error was reported.
Types ¶
type Logger ¶
type Logger interface { // WithName returns a new Logger with the given name. WithName(name string) Logger // WithFields returns a new Logger with the given fields. WithFields(fields Fields) Logger // Debug logs a message at the debug level. Debug(args ...any) // Info logs a message at the info level. Info(args ...any) // Warn logs a message at the warn level. Warn(args ...any) // Error logs a message at the error level. Error(args ...any) // Fatal logs a message at the fatal level and then exit the program. Fatal(args ...any) // Debugf logs a message at the debug level using given format. Debugf(format string, args ...any) // Infof logs a message at the info level using given format. Infof(format string, args ...any) // Warnf logs a message at the warn level using given format. Warnf(format string, args ...any) // Errorf logs a message at the error level using given format. Errorf(format string, args ...any) // Fatalf logs a message at the fatal level using given format and then // exit the program. Fatalf(format string, args ...any) }
Logger is the interface for logging, similar to the Uber's zap.Logger.
func LoggerFrom ¶
LoggerFrom returns the logger from the context. If EnsureLogger() was not called before, it will panic.