sqllogging

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2025 License: MIT Imports: 16 Imported by: 0

README

This library has been deprecated

This library has been deprecated. See go-querysql instead; go-querysql also has logging (and now monitoring) capabilities.

Original documentation for go-sqllogging

Documentation

Overview

Package sqllog provides a logging hook for go-mssqldb that turns mssqldb errors into proper logging using logrus. See README.md.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InstallMssql

func InstallMssql()

func LoggerOrNil

func LoggerOrNil(ctx context.Context) mssql.ContextLogger

func With

func With(ctx context.Context, logger logrus.FieldLogger, dbi DB, fallback ...LogrusMssqlLogger) context.Context

With configures a standard opinionated logger, see LogrusLogger.

func WithLogger

func WithLogger(ctx context.Context, logger mssql.ContextLogger) context.Context

WithLogger attaches an mssql.ContextLogger to ctx. This is the basic hook and you may use this directly to override the SQL logger per call.

Types

type DB

type DB interface {
	QuerierExecer
	Conn(ctx context.Context) (*sql.Conn, error)
}

DB interface is used simply to avoid a potentially common mistake of passing a *Conn or *Tx to With()

type LogrusLogger

type LogrusLogger struct {
	Logger   logrus.FieldLogger // Normal logrus output
	Querier  QuerierExecer      // For ##log-table dumping, this is used to fetch table data
	Fallback LogrusMssqlLogger  // If `<level>:` prefix is not present, forward to this logger
	Stderr   io.Writer          // The special "stderr:" level is written here
}

LogrusLogger is an opinionated logger implementation that parses the SQL log string and turns it into a nice logrus log; see README.md for further description.

func (LogrusLogger) Log

func (l LogrusLogger) Log(ctx context.Context, category msdsn.Log, msg string)

type LogrusMssqlLogger

type LogrusMssqlLogger interface {
	Log(ctx context.Context, logger logrus.FieldLogger, category msdsn.Log, msg string)
}

type QuerierExecer

type QuerierExecer interface {
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
}

type Row

type Row []any

type StandardFallbackLogrusMssqlLogger

type StandardFallbackLogrusMssqlLogger struct {
	Mask  msdsn.Log
	Level logrus.Level
}

StandardFallbackLogrusMssqlLogger defines the behaviour if no log level is specified with the "level:" prefix; i.e. messages that are likely not logged with this framework in mind.

func (StandardFallbackLogrusMssqlLogger) Log

Directories

Path Synopsis
Package sql allows pulling in the SQL files present in this directory as a go library.
Package sql allows pulling in the SQL files present in this directory as a go library.

Jump to

Keyboard shortcuts

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