logger

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 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