logging

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package logging manages log file creation, rotation, and filtering for non-critical messages when verbose mode is off.

Index

Constants

View Source
const MaxLogSize = 5 * 1024 * 1024

MaxLogSize is the threshold for log rotation (5MB)

Variables

View Source
var NonCriticalPrefixes = []string{
	"[~] Modo prueba activado",
	"[>] Peso enviado",
	"[!] No se recibió peso significativo",
	"[i] Configuración sin cambios",
	"[i] Iniciando escucha",
	"[i] Terminando escucha",
	"[+] Cliente conectado",
	"[-] Cliente desconectado",
}

NonCriticalPrefixes are log messages filtered when verbose=false

Functions

func Flush

func Flush(path string) error

Flush reduces the log file to the last 50 lines

func GetFileSize

func GetFileSize(path string) int64

GetFileSize returns the size of the log file in bytes

func ReadLastNLines

func ReadLastNLines(path string, n int) []string

ReadLastNLines reads the last n lines from a file efficiently

func RotateIfNeeded

func RotateIfNeeded(path string) error

RotateIfNeeded truncates the log file if it exceeds MaxLogSize Keeps the last 1000 lines for continuity

Types

type FilteredLogger

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

FilteredLogger wraps a file writer with verbose filtering

func NewFilteredLogger

func NewFilteredLogger(file *os.File, verbose *bool, vMu *sync.RWMutex) *FilteredLogger

NewFilteredLogger creates a logger that can filter non-critical messages

func (*FilteredLogger) Write

func (l *FilteredLogger) Write(p []byte) (n int, err error)

type Manager

type Manager struct {
	FilePath string

	Verbose bool
	// contains filtered or unexported fields
}

Manager handles log file lifecycle and configuration

func Setup

func Setup(serviceName string, defaultVerbose bool) (*Manager, error)

Setup initializes logging to file with stdout fallback for console mode

func (*Manager) Close

func (m *Manager) Close() error

Close closes the log file

func (*Manager) Closer

func (m *Manager) Closer() io.Closer

Closer returns an io.Closer for the log file

func (*Manager) Flush

func (m *Manager) Flush() error

Flush reduces the log file keeping last 50 lines

func (*Manager) GetStatus

func (m *Manager) GetStatus() map[string]interface{}

GetStatus returns current log status

func (*Manager) GetTail

func (m *Manager) GetTail(n int) []string

GetTail returns the last n lines of the log

func (*Manager) GetVerbose

func (m *Manager) GetVerbose() bool

GetVerbose returns current verbose setting

func (*Manager) SetVerbose

func (m *Manager) SetVerbose(v bool)

SetVerbose updates the verbose setting

Jump to

Keyboard shortcuts

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