zlog

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2025 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package zlog provides a simple and flexible logging utility built around the zerolog library.

It offers structured, leveled logging with support for console output, file logging with rotation, and custom output targets. This package simplifies logger setup and management by wrapping zerolog and integrating with the lumberjack package for efficient log file rotation.

Key Features:

  • Structured logging using zerolog
  • Optional console output with human-readable formatting
  • File logging with automatic rotation (size, age, and backup limits)
  • Singleton design for easy initialization and global logger access
  • Runtime log level adjustments and custom writer support

Example:

package main

import (
	"github.com/valentin-kaiser/go-core/zlog"
	"github.com/rs/zerolog"
	"github.com/rs/zerolog/log"
)

func main() {
	zlog.Logger().
		WithConsole().
		WithLogFile().
		Init("example", zerolog.InfoLevel)

	log.Info().Msg("This is an info message")

	zlog.SetLevel(zerolog.DebugLevel)
	log.Debug().Msg("This is a debug message")
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Interactive added in v1.6.0

func Interactive() bool

Interactive checks if the application is running in interactive mode by checking if stdout is available.

func Logger

func Logger() *logger

Logger returns the singleton instance of the logger.

func SetModeDetector added in v1.6.0

func SetModeDetector(d ModeDetector)

SetModeDetector allows the user to provide a custom function to detect interactive mode

Types

type ModeDetector added in v1.6.0

type ModeDetector func() bool

ModeDetector is a function type for detecting interactive mode

type MultiWriter added in v1.6.0

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

MultiWriter is like io.MultiWriter but continues writing to other writers even if one fails

func (*MultiWriter) Write added in v1.6.0

func (mw *MultiWriter) Write(p []byte) (n int, err error)

type StreamWriter added in v1.6.0

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

StreamWriter is an io.Writer that streams log entries to listeners

func NewStreamWriter added in v1.6.0

func NewStreamWriter(bufferMax int) *StreamWriter

NewStreamWriter creates a new StreamWriter with optional buffer size

func (*StreamWriter) AddListener added in v1.6.0

func (sw *StreamWriter) AddListener(ch chan string)

AddListener adds a new listener channel and sends buffered entries

func (*StreamWriter) GetListenerCount added in v1.6.0

func (sw *StreamWriter) GetListenerCount() int

GetListenerCount returns the number of active listeners

func (*StreamWriter) HasListeners added in v1.6.0

func (sw *StreamWriter) HasListeners() bool

HasListeners returns true if there are active listeners

func (*StreamWriter) RemoveListener added in v1.6.0

func (sw *StreamWriter) RemoveListener(ch chan string)

RemoveListener removes a specific listener channel

func (*StreamWriter) Write added in v1.6.0

func (sw *StreamWriter) Write(p []byte) (n int, err error)

Write implements io.Writer interface

Jump to

Keyboard shortcuts

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