slog

package module
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: MIT Imports: 3 Imported by: 2

README

slog

import "github.com/induzo/gocom/database/pgx-slog"

Package slog provides a logger that writes to a go.uber.org/slog.Logger.

Index

type Logger

type Logger struct {
    // contains filtered or unexported fields
}
func NewLogger
func NewLogger(logger *slog.Logger) *Logger
Example

package main

import (
	"context"
	"io"
	"log/slog"

	"github.com/jackc/pgx/v5/pgxpool"
	"github.com/jackc/pgx/v5/tracelog"

	slogadapter "github.com/induzo/gocom/database/pgx-slog"
)

func main() {
	textAdapter := slog.NewTextHandler(io.Discard, nil)
	logger := slog.New(textAdapter)

	pgxPool, _ := pgxpool.New(context.Background(), "postgres://postgres:postgres@localhost:5432/datawarehouse")

	pgxPool.Config().ConnConfig.Tracer = &tracelog.TraceLog{
		Logger:   slogadapter.NewLogger(logger),
		LogLevel: tracelog.LogLevelTrace,
	}
}

func (*Logger) Log
func (pl *Logger) Log(_ context.Context, level tracelog.LogLevel, msg string, data map[string]interface{})

Generated by gomarkdoc

Documentation

Overview

Package slog provides a logger that writes to a go.uber.org/slog.Logger.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger(logger *slog.Logger) *Logger
Example
package main

import (
	"context"
	"io"
	"log/slog"

	"github.com/jackc/pgx/v5/pgxpool"
	"github.com/jackc/pgx/v5/tracelog"

	slogadapter "github.com/induzo/gocom/database/pgx-slog"
)

func main() {
	textAdapter := slog.NewTextHandler(io.Discard, nil)
	logger := slog.New(textAdapter)

	pgxPool, _ := pgxpool.New(context.Background(), "postgres://postgres:postgres@localhost:5432/datawarehouse")

	pgxPool.Config().ConnConfig.Tracer = &tracelog.TraceLog{
		Logger:   slogadapter.NewLogger(logger),
		LogLevel: tracelog.LogLevelTrace,
	}
}
Output:

func (*Logger) Log

func (pl *Logger) Log(_ context.Context, level tracelog.LogLevel, msg string, data map[string]interface{})

Jump to

Keyboard shortcuts

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