Help us shape the future of Go! Take the 2026 Go Developer Survey

file

package
v1.75.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 6 Imported by: 0

README

Package file

Пакет file предоставляет функциональность для настройки файлового вывода логов с ротацией через Lumberjack.
Интегрируется с zap как кастомный Sink.

Types

Output

Структура представляет собой конфигурацию вывода, в которой можно указать путь к файлу логов, максимальный размер файла (MB) до ротации, максимальный срок хранения файлов в днях, максимальное количество старых лог-файлов и функцию сжатия старых файлов.

Functions

ConfigToUrl(r Output) *url.URL

Сконвертировать Output в URL для zap.

NewFileWriter(r Output) io.WriteCloser

Создать логгер lumberjack с ротацией.

Usage

Default usage flow
package main

import (
	"log"

	log2 "github.com/txix-open/isp-kit/log"
	"github.com/txix-open/isp-kit/log/file"
)

func main() {
	output := file.Output{
		File:       "app.log",
		MaxSizeMb:  100,  /* Ротация при 100MB */
		MaxBackups: 3,    /* Хранить 3 старых файла */
		Compress:   true, /* Сжимать .gz */
	}

	logger, err := log2.New(
		log2.WithLevel(log2.InfoLevel),
		log2.WithFileOutput(output),
	)
	if err != nil {
		log.Fatal(err)
	}
}

Documentation

Overview

Package file provides log file output with rotation using lumberjack.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigToUrl

func ConfigToUrl(r Output) *url.URL

ConfigToUrl converts an Output configuration to a URL.

func NewFileWriter

func NewFileWriter(r Output) io.WriteCloser

NewFileWriter creates a new log file writer with rotation.

Types

type Output

type Output struct {
	// File is the path to the log file.
	File string
	// MaxSizeMb is the maximum file size in megabytes before rotation.
	MaxSizeMb int
	// MaxDays is the maximum number of days to retain old log files.
	MaxDays int
	// MaxBackups is the maximum number of old log files to retain.
	MaxBackups int
	// Compress enables compression of rotated log files.
	Compress bool
}

Output configures log file rotation.

Jump to

Keyboard shortcuts

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