slogrus

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: MIT Imports: 3 Imported by: 0

README

slogrus

slogrus is a this simple wrapper that allows me to use slog but in a more logrus way.

Installation

go get -u github.com/squeakycheese75/slogrus

Usage

package main

import (
	"github.com/squeakycheese75/slogrus"
)

func main() {
	logger := slogrus.New()

	// Log an info message
	logger.Info("This is an info message with slogrus")

	// Log an error message with fields
	logger.WithFields(slogrus.Fields{
		"error": "some error message",
	}).Error("An error occurred")

	// Log a debug with fields
	logger.WithFields(slogrus.Fields{
		"http":          "req",
		"method":        "POST",
		"handler":       "UpdateDataColumn",
		"correlationID": "order123",
		"params": map[string]string{
			"datacolumnID": "abcdef",
			"datasetId":    "123456",
		},
	}).Debug("UpdateDataColumn request received")
}

Contributing

Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".

Don't forget to give the project a star! Thank you again!

Fork the Project Create your Feature Branch (git checkout -b feature/AmazingFeature) Commit your Changes (git commit -m 'Add some AmazingFeature') Push to the Branch (git push origin feature/AmazingFeature) Open a Pull Request License Distributed under the MIT License. See LICENSE for more information.

Acknowledgments

  • logrus for the inspiration.
  • slog for the performance-focused logging.

Documentation

Index

Constants

View Source
const ErrorKey = "error"

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

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

func WithFields added in v0.1.1

func WithFields(fields Fields) *Entry

func (*Entry) Debug

func (entry *Entry) Debug(args ...interface{})

func (*Entry) Error

func (entry *Entry) Error(args ...interface{})

func (*Entry) Info

func (entry *Entry) Info(args ...interface{})

func (*Entry) Print added in v0.1.1

func (entry *Entry) Print(args ...interface{})

func (*Entry) Warn

func (entry *Entry) Warn(args ...interface{})

type Fields

type Fields map[string]interface{}

type LogLevel

type LogLevel int
const (
	Debug LogLevel = -4
	Info  LogLevel = 0
	Warn  LogLevel = 4
	Error LogLevel = 8
)

type Logger

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

func New

func New() *Logger

func NewWithHandler

func NewWithHandler(handler slog.Handler) *Logger

func (*Logger) Debug

func (l *Logger) Debug(args ...interface{})

func (*Logger) Error

func (l *Logger) Error(args ...interface{})

func (*Logger) GetSlogLogger

func (l *Logger) GetSlogLogger() *slog.Logger

func (*Logger) Info

func (l *Logger) Info(args ...interface{})

func (*Logger) Warn

func (l *Logger) Warn(args ...interface{})

func (*Logger) WithError added in v0.1.1

func (l *Logger) WithError(err error) *Entry

func (*Logger) WithField added in v0.1.1

func (l *Logger) WithField(key string, value interface{}) *Entry

func (*Logger) WithFields

func (l *Logger) WithFields(fields ...Fields) *Entry

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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