golog

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2025 License: MIT Imports: 3 Imported by: 1

README

pgx-golog

build status report card godocs

Free golog and pgx logging integration.

import "github.com/jackc/pgx/v5/tracelog"
import pgxgolog "github.com/kataras/pgx-golog"

// [...]

logger := pgxgolog.NewLogger(yourGologLoggerInstanceHere)
tracer := &tracelog.TraceLog{
    Logger:   logger,
    LogLevel: tracelog.LogLevelTrace,
}

📖 Learning pgx-golog

Installation

The only requirement is the Go Programming Language.

Create a new project
$ mkdir myapp
$ cd myapp
$ go mod init myapp
$ go get github.com/kataras/pgx-golog
Install on existing project
$ cd myapp
$ go get github.com/kataras/pgx-golog

Run

$ go mod tidy
$ go run .

📝 License

This project is licensed under the MIT License.

Documentation

Overview

Package golog provides a logger that writes to a github.com/kataras/golog log.

Index

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
}

Logger supports golog integration with the new pgx's tracelogs.

func NewLogger

func NewLogger(l *golog.Logger) *Logger

NewLogger returns a new logger which implements the pgx's tracelog's logger interface.

Example Code:

import (
	"context"

	"github.com/jackc/pgx/v5/pgxpool"
	"github.com/jackc/pgx/v5/tracelog"
	"github.com/kataras/golog"
	pgxgolog "github.com/kataras/pgx-golog"
)

func main() {
	golog.SetLevel("debug")

	logger := pgxgolog.NewLogger(golog.Default)
	tracer := &tracelog.TraceLog{
		Logger:   logger,
		LogLevel: tracelog.LogLevelTrace,
	}

	connString := "postgres://postgres:admin!123@localhost:5432/test_db?sslmode=disable&search_path=public"
	connConfig, err := pgxpool.ParseConfig(connString)
	if err != nil {
		panic(err)
	}
	connConfig.ConnConfig.Tracer = tracer

	pool, err := pgxpool.NewWithConfig(context.Background(), connConfig)
	if err != nil {
		panic(err)
	}

	// [...]
}

func (*Logger) Log

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

Log implements the tracelog logger interface.

Jump to

Keyboard shortcuts

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