logger

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: MIT Imports: 11 Imported by: 27

README

🔍  go-logger

Easy to use, extendable and superfast logging package for Go


Release Go Version License


CI / CD    Build Last Commit      Quality    Go Report Coverage
Security    Scorecard Security      Community    Contributors Bitcoin


Project Navigation
🚀 Installation 🧪 Examples & Tests 📚 Documentation
🤝 Contributing 🛠️ Code Standards ⚡ Benchmarks
🤖 AI Usage ⚖️ License 👥 Maintainers

Installation

go-logger requires a supported release of Go.

go get github.com/mrz1836/go-logger

For use with Log Entries (Rapid7), change the environment variables:

export LOG_ENTRIES_TOKEN=your-token-here

(Optional) Set custom endpoint or port parameters

export LOG_ENTRIES_ENDPOINT=us.data.logs.insight.rapid7.com
export LOG_ENTRIES_PORT=514

Documentation

View the generated documentation

Heads up! go-logger is intentionally light on dependencies. The only external package it uses is the excellent testify suite—and that's just for our tests. You can drop this library into your projects without dragging along extra baggage.


Features
  • Native logging package (extends log package)
  • Native support for Log Entries (Rapid7) with queueing
  • Test coverage on all custom methods
  • Supports different Rapid7 endpoints & ports
  • Interface for GORM compatibility

Additional Documentation & Repository Management
Development Setup (Getting Started)

Install MAGE-X build tool for development:

# Install MAGE-X for development and building
go install github.com/mrz1836/mage-x/cmd/magex@latest
magex update:install
Library Deployment

This project uses goreleaser for streamlined binary and library deployment to GitHub. To get started, install it via:

brew install goreleaser

The release process is defined in the .goreleaser.yml configuration file.

Then create and push a new Git tag using:

magex version:bump bump=patch push=true branch=master

This process ensures consistent, repeatable releases with properly versioned artifacts and citation metadata.

Build Commands

View all build commands

magex help
GitHub Workflows

All workflows are driven by modular configuration in .github/env/ — no YAML editing required.

View all workflows and the control center →

Updating Dependencies

To update all dependencies (Go modules, linters, and related tools), run:

magex deps:update

This command ensures all dependencies are brought up to date in a single step, including Go modules and any managed tools. It is the recommended way to keep your development environment and CI in sync with the latest versions.


Examples & Tests

All unit tests and fuzz tests run via GitHub Actions and use Go version 1.21.x. View the configuration file.

Run all tests (fast):

magex test

Run all tests with race detector (slower):

magex test:race

Benchmarks

Run the Go benchmarks:

magex bench

Code Standards

Read more about this Go project's code standards.


🤖 AI Usage & Assistant Guidelines

Read the AI Usage & Assistant Guidelines for details on how AI is used in this project and how to interact with AI assistants.


Maintainers

MrZ
MrZ

Contributing

View the contributing guidelines and please follow the code of conduct.

How can I help?

All kinds of contributions are welcome 🙌! The most basic way to show your support is to star 🌟 the project, or to raise issues 💬. You can also support this project by becoming a sponsor on GitHub 👏 or by making a bitcoin donation to ensure this journey continues indefinitely! 🚀

Stars


License

License

Documentation

Overview

Package logger is an easy-to-use, super-fast and extendable logging package for Go

Index

Examples

Constants

View Source
const (
	LogEntriesPort         = "10000"               // 80, 514, 443, 10000
	LogEntriesTestEndpoint = "52.214.43.195"       // This is an IP for now, since GitHub Actions fails on resolving the domains
	LogEntriesURL          = "data.logentries.com" // "data.insight.rapid7.com" "eu.data.logs.insight.rapid7.com"
	MaxRetryDelay          = 2 * time.Minute
	RetryDelay             = 100 * time.Millisecond
)

Package constants

View Source
const SlowQueryThreshold = 5 * time.Second

SlowQueryThreshold is the time cut-off for considering a query as "slow"

Variables

This section is empty.

Functions

func Data

func Data(stackLevel int, logLevel LogLevel, message string, args ...KeyValue)

Data will format the log message to a standardized log entries compatible format. stackLevel 2 will tag the log with the location from where Data is called. This will print using the implementation's Println function

func Errorfmt

func Errorfmt(stackLevel int, format string, v ...interface{})

Errorfmt is equivalent to Printf with a custom stack level, see Errorln for details

func Errorln

func Errorln(stackLevel int, v ...interface{})

Errorln is equivalent to Println() except the stack level can be set to generate the correct log tag. A stack level of 2 is will tag the log with the location from where Errorln is called, and is equivalent to Println. Larger numbers step further back in the stack

func Fatal added in v0.2.3

func Fatal(v ...interface{})

Fatal is equivalent to Print() followed by a call to os.Exit(1)

func Fatalf

func Fatalf(format string, v ...interface{})

Fatalf is equivalent to Printf() followed by a call to os.Exit(1)

func Fatalln

func Fatalln(v ...interface{})

Fatalln is equivalent to Println() followed by a call to os.Exit(1)

func FileTag

func FileTag(level int) string

FileTag tag file

Example

ExampleFileTag example using FileTag()

// fileTag := FileTag(1)
fileTag := "go-logger/logger_test.go:go-logger.ExampleFileTag:102"
fmt.Println(fileTag)
Output:
go-logger/logger_test.go:go-logger.ExampleFileTag:102

func FileTagComponents

func FileTagComponents(level int) []string

FileTagComponents file tag components

Example

ExampleFileTagComponents example using FileTagComponents()

fileTag := FileTagComponents(1)
fmt.Println(fileTag[0])
Output:
go-logger/logger_test.go

func NoFileData added in v0.1.3

func NoFileData(logLevel LogLevel, message string, args ...KeyValue)

NoFileData will format the log message to a standardized log entries compatible format. This will print using the implementation's Println function

func NoFilePrintf added in v0.1.3

func NoFilePrintf(format string, v ...interface{})

NoFilePrintf calls Output to print to the connected logger. Arguments are handled in the manner of fmt.Printf.

func NoFilePrintln added in v0.1.3

func NoFilePrintln(v ...interface{})

NoFilePrintln calls Output to print to the connected logger. Arguments are handled in the manner of fmt.Println.

func Panic added in v0.2.3

func Panic(v ...interface{})

Panic is equivalent to Print() followed by a call to os.Exit(1)

func Panicf added in v0.2.3

func Panicf(format string, v ...interface{})

Panicf is equivalent to Printf() followed by a call to os.Exit(1)

func Panicln added in v0.2.3

func Panicln(v ...interface{})

Panicln is equivalent to Println() followed by a call to os.Exit(1)

func Print added in v0.2.3

func Print(v ...interface{})

Print calls Output to print to the connected logger. Arguments are handled in the manner of fmt.Print.

func Printf

func Printf(format string, v ...interface{})

Printf calls Output to print to the connected logger. Arguments are handled in the manner of fmt.Printf.

func Println

func Println(v ...interface{})

Println calls Output to print to the connected logger. Arguments are handled in the manner of fmt.Println.

func SetImplementation

func SetImplementation(impl Logger)

SetImplementation allows the log implementation to be swapped at runtime

Types

type GormLogLevel added in v0.3.0

type GormLogLevel int

GormLogLevel is the GORM log level

const (
	// Silent silent log level
	Silent GormLogLevel = iota + 1

	// Error error log level
	Error

	// Warn warn log level
	Warn

	// Info info log level
	Info
)

type GormLoggerInterface added in v0.3.0

type GormLoggerInterface interface {
	Error(ctx context.Context, s string, v ...interface{})
	GetMode() GormLogLevel
	GetStackLevel() int
	Info(ctx context.Context, s string, v ...interface{})
	SetMode(gl GormLogLevel) GormLoggerInterface
	SetStackLevel(level int)
	Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error)
	Warn(ctx context.Context, s string, v ...interface{})
}

GormLoggerInterface is a logger interface to help work with GORM

func NewGormLogger added in v0.3.0

func NewGormLogger(debugging bool, stackLevel int) GormLoggerInterface

NewGormLogger will return a basic logger interface

type KeyValue

type KeyValue interface {
	Key() string
	Value() interface{}
}

KeyValue key value for errors

type LogClient added in v0.1.4

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

LogClient configuration

func NewLogEntriesClient

func NewLogEntriesClient(token, endpoint, port string) (*LogClient, error)

NewLogEntriesClient new client

func (*LogClient) Connect added in v0.1.4

func (l *LogClient) Connect() error

Connect will connect to Log Entries

func (*LogClient) Fatal added in v0.2.3

func (l *LogClient) Fatal(v ...interface{})

Fatal overloads built-in method

func (*LogClient) Fatalf added in v0.1.4

func (l *LogClient) Fatalf(format string, v ...interface{})

Fatalf overloads built-in method

func (*LogClient) Fatalln added in v0.1.4

func (l *LogClient) Fatalln(v ...interface{})

Fatalln overloads built-in method

func (*LogClient) Panic added in v0.2.3

func (l *LogClient) Panic(v ...interface{})

Panic overloads built-in method

func (*LogClient) Panicf added in v0.2.3

func (l *LogClient) Panicf(format string, v ...interface{})

Panicf overloads built-in method

func (*LogClient) Panicln added in v0.2.3

func (l *LogClient) Panicln(v ...interface{})

Panicln overloads built-in method

func (*LogClient) Print added in v0.2.3

func (l *LogClient) Print(v ...interface{})

Print overloads built-in method

func (*LogClient) Printf added in v0.1.4

func (l *LogClient) Printf(format string, v ...interface{})

Printf overloads built-in method

func (*LogClient) Println added in v0.1.4

func (l *LogClient) Println(v ...interface{})

Println overloads built-in method

func (*LogClient) ProcessQueue added in v0.1.4

func (l *LogClient) ProcessQueue()

ProcessQueue process the queue

type LogLevel

type LogLevel uint8

LogLevel our log level

const (
	DEBUG LogLevel = iota
	INFO
	WARN
	ERROR
)

Global constants

func (LogLevel) String

func (l LogLevel) String() string

String turn log level to string

Example

ExampleLogLevel_String example using level.String()

var level LogLevel
fmt.Println(level.String())
Output:
debug

type Logger

type Logger interface {
	Fatal(v ...interface{})
	Fatalf(format string, v ...interface{})
	Fatalln(v ...interface{})
	Panic(v ...interface{})
	Panicf(s string, v ...interface{})
	Panicln(v ...interface{})
	Print(v ...interface{})
	Printf(format string, v ...interface{})
	Println(v ...interface{})
}

Logger interface describes the functionality that a log service must implement

func GetImplementation added in v0.2.3

func GetImplementation() Logger

GetImplementation gets the current logger implementation

type Parameter added in v0.0.2

type Parameter struct {
	K string      `json:"key"`
	V interface{} `json:"value"`
}

Parameter is a standardized parameter struct for logger.Data()

func MakeParameter added in v0.0.2

func MakeParameter(key string, value interface{}) *Parameter

MakeParameter creates a new Parameter (key/value)

func (*Parameter) Key added in v0.0.2

func (p *Parameter) Key() string

Key implements the Logger KeyValue interface

func (*Parameter) String added in v0.0.2

func (p *Parameter) String() string

Parameter json encodes the parameter into standard key=>value JSON

func (*Parameter) Value added in v0.0.2

func (p *Parameter) Value() interface{}

Value implements the Logger KeyValue interface

Directories

Path Synopsis
Package main is an example package to show the use case of go-logger
Package main is an example package to show the use case of go-logger

Jump to

Keyboard shortcuts

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