logger

package module
v0.0.0-...-60e9d12 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2021 License: MIT Imports: 15 Imported by: 194

README

Golang logger functionality with package-level logging separation to improve application debug process

MIT License

Functionality of this package is similar to logrus and other popular Golang logging packages, but still the capabilities of this package are not as flexible and advanced as the mentioned popular packages.

One of the reasons for creating this library was the ability to log with more verbosity levels. For instance, we have here Fatal, Panic, Error, Warning, Notify, Information and Debug levels, while others ordinary do not include Notify verbosity.

I'll add more information about the API here later, but for now, folks, that's all now.

License

Go-logger is licensed under MIT License, like other similar Golang logging libraries.

Documentation

Index

Constants

View Source
const (
	LeftIndent = iota
	CenterIndent
	RightIndent
)

Variables

This section is empty.

Functions

func AddCustomLog

func AddCustomLog(writer io.Writer, colored bool, level LogLevel)

func ChangePackageLogLevel

func ChangePackageLogLevel(packageName string, level LogLevel) error

func EnableSyslog

func EnableSyslog(enable bool)

func FinalizeLogger

func FinalizeLogger() error

func FormatMessage

func FormatMessage(options FormatOptions, level LogLevel, packageName, msg string, colored bool) string

func SetFormatOptions

func SetFormatOptions(format FormatOptions)

func SetLogFileName

func SetLogFileName(logFilePath string) error

func SetRotateParams

func SetRotateParams(rotateMaxSize int64, rotateMaxCount int)

Types

type File

type File struct {
	sync.RWMutex
	Path string
	File *os.File
}

func (*File) Close

func (v *File) Close() error

func (*File) Flush

func (v *File) Flush() error

type FormatOptions

type FormatOptions struct {
	TimeFormat    string
	PackageLength int
	LevelLength   LevelLength
}

func (FormatOptions) GetLevelStr

func (options FormatOptions) GetLevelStr(level LogLevel) string

type IndentKind

type IndentKind int

type LevelLength

type LevelLength int
const (
	LevelShort LevelLength = iota
	LevelLong
)

type Log

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

func NewLog

func NewLog(log *log.Logger, colored bool, level LogLevel) *Log

type LogLevel

type LogLevel int
const (
	FatalLevel LogLevel = iota
	PanicLevel
	ErrorLevel
	WarnLevel
	NotifyLevel
	InfoLevel
	DebugLevel
)

func (LogLevel) LongStr

func (v LogLevel) LongStr() string

func (LogLevel) ShortStr

func (v LogLevel) ShortStr() string

func (LogLevel) String

func (v LogLevel) String() string

type Logger

type Logger struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger() *Logger

func (*Logger) AddCustomLog

func (v *Logger) AddCustomLog(writer io.Writer, colored bool, level LogLevel)

func (*Logger) ChangePackageLogLevel

func (v *Logger) ChangePackageLogLevel(packageName string, level LogLevel) error

func (*Logger) Close

func (v *Logger) Close() error

func (*Logger) EnableSyslog

func (v *Logger) EnableSyslog(enable bool)

func (*Logger) GetFormatOptions

func (v *Logger) GetFormatOptions() FormatOptions

func (*Logger) GetLogFileInfo

func (v *Logger) GetLogFileInfo() *File

func (*Logger) GetRotateMaxCount

func (v *Logger) GetRotateMaxCount() int

func (*Logger) GetRotateMaxSize

func (v *Logger) GetRotateMaxSize() int64

func (*Logger) GetSyslogEnabled

func (v *Logger) GetSyslogEnabled() bool

func (*Logger) NewPackageLogger

func (v *Logger) NewPackageLogger(packageName string, level LogLevel) PackageLog

func (*Logger) SetFormatOptions

func (v *Logger) SetFormatOptions(options FormatOptions)

func (*Logger) SetLogFileName

func (v *Logger) SetLogFileName(logFilePath string) error

func (*Logger) SetRotateParams

func (v *Logger) SetRotateParams(rotateMaxSize int64, rotateMaxCount int)

type Package

type Package struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*Package) Close

func (v *Package) Close() error

func (*Package) Debug

func (v *Package) Debug(args ...interface{})

func (*Package) Debugf

func (v *Package) Debugf(format string, args ...interface{})

func (*Package) Error

func (v *Package) Error(args ...interface{})

func (*Package) Errorf

func (v *Package) Errorf(format string, args ...interface{})

func (*Package) Fatal

func (v *Package) Fatal(args ...interface{})

func (*Package) Fatalf

func (v *Package) Fatalf(format string, args ...interface{})

func (*Package) GetLogLevel

func (v *Package) GetLogLevel() LogLevel

func (*Package) Info

func (v *Package) Info(args ...interface{})

func (*Package) Infof

func (v *Package) Infof(format string, args ...interface{})

func (*Package) Notify

func (v *Package) Notify(args ...interface{})

func (*Package) Notifyf

func (v *Package) Notifyf(format string, args ...interface{})

func (*Package) Panic

func (v *Package) Panic(args ...interface{})

func (*Package) Panicf

func (v *Package) Panicf(format string, args ...interface{})

func (*Package) Print

func (v *Package) Print(level LogLevel, args ...interface{})

func (*Package) Printf

func (v *Package) Printf(level LogLevel, format string, args ...interface{})

func (*Package) SetLogLevel

func (v *Package) SetLogLevel(level LogLevel)

func (*Package) Warn

func (v *Package) Warn(args ...interface{})

func (*Package) Warnf

func (v *Package) Warnf(format string, args ...interface{})

func (*Package) Warning

func (v *Package) Warning(args ...interface{})

func (*Package) Warningf

func (v *Package) Warningf(format string, args ...interface{})

type PackageLog

type PackageLog interface {
	Printf(level LogLevel, format string, args ...interface{})
	Print(level LogLevel, args ...interface{})
	Debugf(format string, args ...interface{})
	Debug(args ...interface{})
	Infof(format string, args ...interface{})
	Info(args ...interface{})
	Notifyf(format string, args ...interface{})
	Notify(args ...interface{})
	Warningf(format string, args ...interface{})
	Warnf(format string, args ...interface{})
	Warning(args ...interface{})
	Warn(args ...interface{})
	Errorf(format string, args ...interface{})
	Error(args ...interface{})
	Panicf(format string, args ...interface{})
	Panic(args ...interface{})
	Fatalf(format string, args ...interface{})
	Fatal(args ...interface{})
}

func NewPackageLogger

func NewPackageLogger(module string, level LogLevel) PackageLog

Jump to

Keyboard shortcuts

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