fireplaceslog

package
v2.3.3 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2023 License: MIT Imports: 10 Imported by: 0

README ¶

Fireplace slog Hook

With version 1.21, Go introduced a native structured logging solution in the package 'log/slog'. This component provides a custom handler that allows you to use the standard slog package to write logs both to STDOUT and Fireplace.

🚀 Getting Started

Here is an example of setting up Fireplace as your default logger.

import (
	"fmt"
	"log/slog"
	"time"

	fireplaceslog "github.com/app-nerds/fireplace/v2/cmd/fireplace-slog"
	"github.com/app-nerds/inlingo/internal/configuration"
	"gorm.io/gorm/logger"
)

func main() {
    setupLogger("v1.0.1", "http://localhost:8999", "password")

    slog.Info("Welcome to using structured logging in Go using slog!")
}

func setupLogger(version, fireplaceURL, fireplacePassword string) {
	handler := fireplaceslog.NewFireplaceHandler(fireplaceslog.HandlerConfig{
		Application:      "test-application",
		ConsoleLogFormat: fireplaceslog.TextFormat,
		FireplaceURL:     fireplaceURL,
		Level:            slog.LevelInfo,
		Password:         fireplacePassword,
	})

    handler = handler.WithAttrs([]slog.Attr{
        slog.String("version", version),
    })

	logger := slog.New(handler)
	slog.SetDefault(logger)
}

In this example we set up the Fireplace Handler as the handler for a slog logger, and make it the default logger. Because of this direct calls against the global slog methods will use Fireplace, AND it will output to STDOUT in the format provided in ConsoleLogFormat.

Documentation ¶

Index ¶

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

This section is empty.

Types ¶

type ConsoleLogFormat ¶

type ConsoleLogFormat int
const (
	TextFormat ConsoleLogFormat = iota
	JSONFormat
)

type FireplaceHandler ¶

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

func NewFireplaceHandler ¶

func NewFireplaceHandler(config HandlerConfig) *FireplaceHandler

func (*FireplaceHandler) Enabled ¶

func (h *FireplaceHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*FireplaceHandler) Handle ¶

func (h *FireplaceHandler) Handle(ctx context.Context, r slog.Record) error

func (*FireplaceHandler) WithAttrs ¶

func (h *FireplaceHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*FireplaceHandler) WithGroup ¶

func (h *FireplaceHandler) WithGroup(name string) slog.Handler

type HandlerConfig ¶

type HandlerConfig struct {
	Application      string
	ConsoleLogFormat ConsoleLogFormat
	FireplaceURL     string
	Level            slog.Level
	Password         string
}

Jump to

Keyboard shortcuts

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