logger

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: May 15, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package logger provides a structured file-based logger implementation using the zerolog library.

This package defines a ZeroLogger type that implements logging to a file with support for structured logs and automatic cleanup. It is used for tracking build processes, errors, and general operational output in the application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ZeroLogger

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

ZeroLogger is a file-based structured logger powered by zerolog.

It writes logs to a specified file and supports informational and error messages with optional formatting. The logger includes automatic cleanup and renaming logic to move the log file to a target directory after use.

func NewFileZeroLogger

func NewFileZeroLogger(filePath, logDir string) *ZeroLogger

NewFileZeroLogger creates a new ZeroLogger instance that logs to a file.

The file is opened in append mode and created if it does not exist. If the file cannot be opened, the function panics. The resulting logger is timestamped and configured for structured output.

Parameters:

  • filePath: Path to the log file to write to.
  • logDir: Directory where the file will be moved after cleanup.

Returns:

  • *ZeroLogger: A configured logger instance ready for use.

func (*ZeroLogger) Cleanup

func (l *ZeroLogger) Cleanup()

Cleanup closes the log file and moves it to the configured log directory.

If a rename operation fails, it is silently ignored. If no file was opened, Cleanup does nothing.

func (*ZeroLogger) Error

func (l *ZeroLogger) Error(message string, err error, args ...interface{})

Error logs an error message along with an associated error.

If formatting arguments are provided, the message is formatted accordingly. Logging is skipped if the log file is not initialized.

Parameters:

  • message: The log message or format string.
  • err: The error object to include in the log.
  • args: Optional format arguments for the message.

func (*ZeroLogger) Info

func (l *ZeroLogger) Info(message string, args ...interface{})

Info logs an informational message using zerolog.

If formatting arguments are provided, the message is formatted using fmt-style verbs. Logging is skipped if the log file is not initialized.

Parameters:

  • message: The log message or format string.
  • args: Optional format arguments for the message.

Jump to

Keyboard shortcuts

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