logging package - github.com/FimGroup/logging - Go Packages

logging

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2023 License: MPL-2.0 Imports: 15 Imported by: 5

README

logging

Simple logging package with direct file and other appenders

Goal of the package
  • simple logging package to persist every log to file
  • flexible and easy file rotation configurations
  • wrap commonly used logging package(currently logrus) for providing general api

Get started

1. Create LoggingManager for file persistent

manager, err := logging.NewLoggerManager("logs/fim", 1, 1*1024*1024, 2, logrus.TraceLevel, true, true)

Parameters:

  • log file path+prefix
  • max days
  • max file size
  • max file per day
  • log level
  • enable caller info
  • enable print log to console
2. Get Logger from LoggingManager

logger := manager.GetLogger("demoLogger001")

Parameter:

  • Logger name
3. Use Logger
type Logger interface {
	Trace(objects ...interface{})
	TraceF(format string, args ...interface{})
	IsTraceEnabled() bool

	Debug(objects ...interface{})
	DebugF(format string, args ...interface{})
	IsDebugEnabled() bool

	Info(objects ...interface{})
	InfoF(format string, args ...interface{})
	IsInfoEnabled() bool

	Warn(objects ...interface{})
	WarnF(format string, args ...interface{})
	IsWarnEnabled() bool

	Error(objects ...interface{})
	ErrorF(format string, args ...interface{})
	IsErrorEnabled() bool
}

Dependency

  • Logging package: github.com/sirupsen/logrus
  • FS manipulation: github.com/spf13/afero

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger interface {
	Trace(objects ...interface{})
	TraceF(format string, args ...interface{})
	IsTraceEnabled() bool

	Debug(objects ...interface{})
	DebugF(format string, args ...interface{})
	IsDebugEnabled() bool

	Info(objects ...interface{})
	InfoF(format string, args ...interface{})
	IsInfoEnabled() bool

	Warn(objects ...interface{})
	WarnF(format string, args ...interface{})
	IsWarnEnabled() bool

	Error(objects ...interface{})
	ErrorF(format string, args ...interface{})
	IsErrorEnabled() bool
}

type LoggerManager

type LoggerManager interface {
	GetLogger(loggerName string) Logger
}

func NewLoggerManager

func NewLoggerManager(filePathPrefix string, maxDays, maxFileSize, maxFilePerDay int, lv logrus.Level, enableCallerInfo, enableConsoleOutput bool) (LoggerManager, error)

func NewNoFileLoggerManager

func NewNoFileLoggerManager() LoggerManager

Jump to

Keyboard shortcuts

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