sflog

package
v2.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package sflog package defines the logging interface for Snowflake's Go driver. If you want to implement a custom logger, you should implement the SFLogger interface defined in this package.

Index

Constants

View Source
const (
	LevelTrace = Level(-8)
	LevelDebug = Level(-4)
	LevelInfo  = Level(0)
	LevelWarn  = Level(4)
	LevelError = Level(8)
	LevelFatal = Level(12)
	LevelOff   = Level(math.MaxInt)
)

Custom level constants that extend slog's standard levels

Variables

This section is empty.

Functions

func LevelToString

func LevelToString(level Level) (string, error)

LevelToString converts Level to string

Types

type ClientLogContextHook

type ClientLogContextHook func(context.Context) string

ClientLogContextHook is a client-defined hook that can be used to insert log fields based on the Context.

type Level

type Level int

Level represents the log level for a log message. It extends slog's standard levels with custom levels.

func ParseLevel

func ParseLevel(level string) (Level, error)

ParseLevel converts a string level to Level

type LogEntry

type LogEntry interface {
	Tracef(format string, args ...interface{})
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Warnf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Fatalf(format string, args ...interface{})

	Trace(msg string)
	Debug(msg string)
	Info(msg string)
	Warn(msg string)
	Error(msg string)
	Fatal(msg string)
}

LogEntry allows for logging using a snapshot of field values. No implementation-specific logging details should be placed into this interface.

type SFLogger

type SFLogger interface {
	LogEntry
	WithField(key string, value interface{}) LogEntry
	WithFields(fields map[string]any) LogEntry

	SetLogLevel(level string) error
	SetLogLevelInt(level Level) error
	GetLogLevel() string
	GetLogLevelInt() Level
	WithContext(ctx context.Context) LogEntry
	SetOutput(output io.Writer)
}

SFLogger Snowflake logger interface which abstracts away the underlying logging mechanism. No implementation-specific logging details should be placed into this interface.

type SFSlogLogger

type SFSlogLogger interface {
	SetHandler(handler slog.Handler) error
}

SFSlogLogger is an optional interface for advanced slog handler configuration. This interface is separate from SFLogger to maintain framework-agnostic design. Users can type-assert the logger to check if slog handler configuration is supported.

Example usage:

logger := gosnowflake.GetLogger()
if slogLogger, ok := logger.(gosnowflake.SFSlogLogger); ok {
    customHandler := slog.NewJSONHandler(os.Stdout, nil)
    slogLogger.SetHandler(customHandler)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL