logging

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2023 License: MPL-2.0 Imports: 16 Imported by: 3

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

func SetLoggerManager added in v1.1.0

func SetLoggerManager(lm LoggerManager)

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 GetLoggerManager added in v1.1.0

func GetLoggerManager() LoggerManager

func NewLoggerManager

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

func NewNoFileLoggerManager

func NewNoFileLoggerManager(lv logrus.Level) LoggerManager

Jump to

Keyboard shortcuts

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